I like null annotations in general but have to say in this implementation the checking is a bit wonky.
I too have run up against the opposing opinions of the compiler and sat-plugin for @NotNullByDefault
on nested classes/interfaces.
Interestingly I have also managed to get:
[WARNING] ... Redundant null check: The variable xyz cannot be null at this location
where xyz
can definitely be null:
final @Nullable Object xyz = map.get(key);
if (xyz != null) {
// Do suff with xyz
}
So it doesn’t even always err on the side of caution.
You can use @SuppressWarnings("null")
at the method level but then you lose all checking in that method.
To get the Unsafe interpretation...
warning to go away you can just assign the result of that method to a @Nullable
annotated variable. Weirdly this also seems to break the null checker for that variable as it lets me immediately dereference the variable without even an assert x != null
.
For the The import xyz is never used.
is it an import that is only used because of JavaDoc?
If so try making all the references in JavaDoc comments fully qualified and then delete the import.
I’ve just resigned myself to living with some of the weird warnings and only giving warnings a skim occasionally to see if there is something new.