False Positive: Rule java:S2589 triggers on conditional @NotNull annotation

The following code will trigger rule S2589 because SonarLint thinks that the value cannot be null:

import javax.validation.constraints.NotNull;

@NotNull(groups = { SpecialValidation.class })
public Long getSomeLong() {
  return theLong;

public void failS2589() {
  if(getSomeLong() == null) {
    throw new RuntimeException("SonarLint flags the condition above as being always false (S2859)")

However, the validation is conditional so null is a possibility

Hello @Alex2,

Thanks for the report and sorry for the late reply. I’ve created a ticket to fix this FP:



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.