More flexible and configurable @Nullable/@NotNull annotations

For quite a while IntelliJ IDEA can detect probable NPE’s in your code. But you have to annotate it with JetBrains’ @Nullable/@NotNull. In order to leave your code free from JetBrains’ annotations you could use external annotations, but they were not so convenient to use as they were not visible in the code. With libraries and SDK code, however, there is no other way except using the external annotations.

So, to make things better, 10.5 IntelliJ IDEA will be able to recognize the most common annotations, such as javax @Nullable/@Nonnull, FindBugs @Nullable/@NonNull, as well as your own annotations with the same semantics.

You just need to configure which annotations are allowed in you code and which should be used by quick fixes to annotate the code.

I like this feature, but the dialog for setting the default is confusing. It took me several tries of setting it to use the javax.annotation before I realized that I had to click on the little D/ (set as default) option. This is quite different from how defaults are set elsewhere in IDEA, so is very confusing.

When I annotate fields with javax @Nullable/@Nonnull and generate setters/getters for them (Ctrl+Enter on Mac OS X), IntelliJ IDEA 10.5 still uses JetBrains annotations on the generated accessors, even tought I configured javax.annotation.* in the Nullable/NotNull configuration. It’s a bug?

Carlos, I’ve just rechecked and it works as expected for me. Could you please check that you have configured default annotations:
1. open File|Settings|Inspections
2. choose constant conditions & exceptions inspection
3. press configure annotations
4. select javax.annotation.Nullable
5. press set as default from toolbar
I suspect that it is the same problem as Tim already mentioned above. We would try to rework the UI to make it more clear. Thank you

I just discovered this feature it looks awesome, I am just wondering why not JDK has this to include so that its available to all and by default. Though most programmer knows what causes NPE, Its best to avoid NPE and rely on tools rather than littering code with !=null checks every now and then.