Link to a (frustratingly) deleted question on Stack Overflow. Text and image copied below incase you don't have the ability to see it. (Not sure why the image shows multiple times.)
Is there any way to more granularly control IntelliJ IDEA's inspections' "Nullability and data flow problems" option "Treat non-annotated members and parameters as @Nullable
"? Preferably for unboxing specifically?
I am aware I can use a variety of @Nullable
annotations in a variety of places in the code to make the warnings appear. That's not always an option as the place the boxed primitives are coming from may be other libraries you don't have control over. (Imagine if the Holder
record below was from a different project.) I included other examples below to illustrate my point.
public class Sample {
private final Boolean value;
public Sample(Boolean value) {
this.value = value;
}
private boolean isValue() {
return value; // I would like a warning here
}
private static Boolean boxedTrue() {
return true;
}
private static boolean unboxedTrue() {
return boxedTrue(); // No warning here, but that's understandable since never null
}
private static Boolean boxedNull() {
return null;
}
private static boolean unboxedNull() {
return boxedNull(); // Only warning in the file (by default)
// "Unboxing of 'boxedNull()' may produce 'NullPointerException'
}
public record Holder(Boolean value) {}
public boolean openHolder(Holder holder) {
return holder.value(); // I would like a warning here
}
}
When "Treat non-annotated members and parameters as @Nullable
" is enabled, the following gives warnings. While that makes sense given the name of the option, there is code like this literally everywhere. It adds hundreds of warnings to my project. I'm trying to find more granular choices.
public static ZonedDateTime timeStuff(LocalDateTime localDateTime, ZoneId zoneId) {
return localDateTime.atZone(zoneId); // I do not want warnings for this
}
I see that the Java Class Library has JetBrains annotations despite not actually being annotated. Is there perhaps some way to add these automatically to libraries if there is no better way to control the inspection?
I agree that "spells do what they say" but a pile of dust is definitely an object, not a creature. That said, I'm willing to concede that it doesn't turn you into a object because it says one of the only ways to be restored to life is through True Resurrection which targets creatures. (And I don't feel like being so obtuse as to argue that the specific rule of Disintegrate saying True Resurrection allows the dust to return to life means it overrides the general rule of True Resurrection targeting creatures lol.)