@Nullable/@NotNull with IntelliJ IDEA, Maven & JSR

2019-02-03 07:41发布

I really like the code inspection functionalities which are now able with either JSR 305 or Jetbrains' proprietary annotations for IntelliJ. Unfortunately both implementations (JSR 305 and Jetbrains') do not mix well:

  • IntelliJ obviously only understands its own proprietary set of annotations and integrates them quite well.
  • Using Findbugs in my Maven Build, it only supports JSR-305 annotations.

The only possible workaround might be to go for JSR-305 and use the Findbugs plugin in IntelliJ. Has anybody a better idea? (please don't say change your IDE ;) ).

Thanks Thomas

4条回答
手持菜刀,她持情操
3楼-- · 2019-02-03 07:55

As this question is IntelliJ specific it is perhaps best asked on an IntelliJ forum. You might find this thread interesting http://devnet.jetbrains.net/message/5262800. The downside of using Findbugs is that it doesn't provide code injection for runtime checks and JSR-305 doesn't appear likely to be approved anytime soon.

查看更多
女痞
4楼-- · 2019-02-03 08:12

According to IntelliJ issue IDEA-64677:

  • support for arbitrary @Nullable/@NotNull annotations should be available in IDEA 10.0.3
  • there will probably some a manual configuration step(s) to enable support for the non-proprietary annotations (see Anna's comments on that page)
查看更多
孤傲高冷的网名
5楼-- · 2019-02-03 08:14

I'm late to the party, but for future readers this might be interesting.

As of IntelliJ 15.0.2, you may natively use other annotations than the JetBrains ones:

  • go to the settings
  • go to the Editor > Inspections tab
  • go to Java > Probable Bugs > "@NotNull/@Nullable problems"
  • at the end of the options panel (you might need to scroll), there is a Configure annotations button, leading to this dialog where you can select from a list of well-known annotations:

enter image description here

查看更多
登录 后发表回答