Java annotation recommendation

We’d like to have our team start using annotations such as @Nonull in our code base to aid with potential bug detection. Unfortunately there’s no standard for this or similar annotations with JSR 305 being dead. Does Sonar define it’s own set of Java annotations we could use? If not can anyone suggestion an alternative set of annotations (e.g. SpotBug’s annotation set)?

Thanks in advance.


that’s very good question. SonarJava doesn’t provide own annotations for this purpose and you are right that situation in Java ecosystem is not ideal with different libraries providing similar annotations with slight differences in semantics. We try to support many commonly used libraries and in our code we use While it’s not actively developed we find it sufficient for the purpose.

We’d like to avoid using JSR305 annotations due to the split package problem it causes when using Java 9+ (see That’s why we’d like to find a non-JSR305 option.

SpotBugs claims to be the successor to FindBugs and defines a set of annotations, which is why we thought it might be an option. Any word on Sonar recognizing and using SpotBug’s annotations?

1 Like

Do you happen to know the fully qualified class names of the SpotBugs annotations? Looking at their docs (Guide for migration from FindBugs 3.0 to SpotBugs 3.1), it seems they are in fact the same as with FindBugs. In that case, they would be supported by SonarJava. See the test class for NullableAnnotationUtils for a list.

Archiving this topic due a lack of activity. If you have a similar problem please start a new topic. Thank you.