Why is @jakarta.validation.constraints.NotNull use as non null annotation?

Hello,

We are using Jakarta Bean Validation in our project code base and code annotated with @jakarta.validation.constraints.NotNull triggers java:S2589 Expression always evaluate to true in Eclipse.

Versions used:

  • Server : Community Build v25.11.0.114957 Standard Experience
  • Eclipse Plugin : SonarLint for Eclipse 12.6.0.84813 org.sonarlint.eclipse.feature.feature.group SonarSource

As far as I understand from those two links from 2019:

It has already been reported as false positive or fixed.

Yet, I have still the issue : is there something I need to do on my part ? (I do think I am connected with Sonar Server).

Our code:

class Foobar {
  private String x;
  @jakarta.validation.constraints.NotNull 
  public String getX() {return x;}
}

private void myMethod(Foobar source) {
  var x = source.getX(); // annotated with @NotNull
  if (x != null) { // report java:S2589 "Expression always evaluate to true"
    // do something with x
  }
}

Pretty much like the link above, x can be null if (1) validation was not run (2) validation failed (in this case I am performing additional validation that I don’t want to perform using jakarta.validation.ConstraintValidator).