Java annotation recommendation

java

(David Schneider) #1

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.


(Tibor Blenessy) #2

Hello,

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 com.google.code.findbugs:jsr305. While it’s not actively developed we find it sufficient for the purpose.


(David Schneider) #3

We’d like to avoid using JSR305 annotations due to the split package problem it causes when using Java 9+ (see https://blog.codefx.org/java/jsr-305-java-9/#What8217s-the-problem). 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?