Note: We are running “SonarQube Enterprise Edition v2025.1 (102418) Standard Experience“.
I am annotating Method parameters with [NotNull] attribute from JetBrains.Annotations namespace, but SonarQube just ignores it and complains about violation. In the explanation to the violation, the annotation is one of recommended ways.
The IDE shows the violation at the method call, when a null is provided.
I would like to avoid boiler plate code checking for null, when it will never happen when annotated. What could be the reason it is not sufficient for SonarQube?
Can you show a snippet of your code where the rule is raised, including the invocation of the validation method that you’re using inside that - where the validation method should have the [NotNull] attribute on its parameter?
The JetBrains attributes should work there, as they are widely used.
That’s not how the [NotNull] should be used here to comply with the rule, see RSPEC-3900
The [NotNull] is recognized if you’d use a validation method that you pass your parameter to for actual validation.
By adding [NotNull] attribute on your own parameter, you’re adding just annotation that effectively means “I wish nobody sends me null values”, but that does not prevent such values from actually arriving and causing runtime issues. So as long as you want the rule to be active, it still raises a true positive here.