Assume you call some external API (e.g. JDK API) that doesn’t use the nullability annotations:
// API declaring everything non-nullable via annotation on the package
void someMethod(String param) { … }
// Using code
Method method = … // known to be non-null
someMethod(method.getName());In this case I get a warning for method.getName() as Eclipse assumes the method to potentially return null, which is as right as it is wrong, as without an annotation it can’t (shouldn’t) actually assume anything.
Question: Is there a way to configure Eclipse to abstain from generating warnings for this?
Answer: Looks like you need to configure "Unchecked conversion from non-annotated type to @NonNull type" to ignore.
Looks like for a class like this:
class SomeClass {
private final DependencyA dependencyA;
private DependencyB dependencyB;
SomeClass(DependencyA dependencyA) {
this.dependencyA = dependencyA;
}
…
}I get a warning on the constructor that the non-nullable field dependencyB has not been initialized.
We currently embrace the pattern of trying to stick to immutability as much as possible and usually hold non-final fields for optional dependencies. I.e. everything non-final is usually optional and thus implicitly nullable.
Question: Is there a way for Eclipse to understand this as is or do we need to annotate all non-final fields with @Nullable. If the latter is the case, Spring’s @Nullable needs to be changed to be usable on fields, too.