I am using SonarLint for IntelliJ IDEA, version 4.12.1.22375.
Given the following class,
import javax.validation.constraints.NotNull;
public class Test {
interface TestCheck {}
@NotNull(groups = TestCheck.class)
public String testString;
public void setTestString() {
testString = null;
}
}
SonarLint flags the line testString = null;
with S2637, because the field has a @NotNull
annotation.
I think this is a rather more clear-cut case than, e. g., this issue: False Positive on S2583 when a @NotNull field is allowed to be null
Given that the validation in question only applies to certain validation groups, it should be clear that the @NotNull
annotation is not intended to mean that the field can never be null - only that it cannot be null in certain contexts. Therefore, SonarLint should not flag @NotNull
annotations with the groups
parameter set.