Should annotations in jar305.jar be preferred over similar annotations in annotation.jar for FindBugs?

后端 未结 1 1433
北恋
北恋 2021-02-20 01:50

In the FindBugs distribution, annotations.jar is not a subset of jsr305.jar. However, several annotations seem to be duplicated (either exactl

1条回答
  •  不知归路
    2021-02-20 02:27

    Yes, you should prefer the JSR305 annotation if possible. Why? Because the JSR305 is a standard and it makes total sense to stick to the standards where possible. While porting my own applications I did not notice any problems or changes in behavior. Moreover, you can even define your own @NotNull annotation and findbugs will pick it up (as long as you name it NotNull) see this blog entry for more details.

    As far as I can see by looking at the sources, findbugs is using the same analysis methods internally. The dispatching is done only based on the annotations name. As mentioned in the blog post linked above, have a look at the edu.umd.cs.findbugs.ba.NullnessAnnotation and NullnessAnnotationDatabase classes to get an initial view how this is done internally. Have a look at this package and you'll find similar classes for the other annotations like the jcip ones.

    So from an implementations point of view it really doesn't matter. For everybody still not sure which annotations to use I would consider using the standard annotations or self defined ones to avoid their code being dependent on the findbugs library.

    0 讨论(0)
提交回复
热议问题