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 don't really understand the thought behind the question. In the sense of legality? Obviously. In the sense of someone saying something? Obviously. In the sense that people have free will? No. The people that work at water facilities are typically technically government employees. If all of them suddenly went rogue would you count that as "the government doing it"? Because they wouldn't be acting in line with the government, but they're still "the government."
So, no, but actually yes, but actually no.
It's like saying "what's actually preventing a secret service member from shooting the president?" Nothing? Everything? How do you answer?