Version used: * Community Edition Version 9.0.1 (build 46107)
We are getting hits on S2637 “@NonNull” values should not be set to null in code like this:
package simple;
import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
class Example {
boolean falseByDefault;
Boolean nullByDefault;
int zeroByDefault;
Integer nullByDefault2;
public Example() {
nullByDefault = false;
nullByDefault2 = 200;
}
}
SonarQube reports that falseByDefault is not initialized in the constructor. But the Java specification says that falseByDefault is indeed… false by default. So how should it be able to be null? I don’t get it.
Now, some might say that this is “bad code”, but if that is the case this should be a code smell. It is as far as I understand it not a @NonNull violation.
Not sure what the data point is worth, but Eclipse Java NonNull detection does not complain.
/Andreas