What is the correct way to use @Nullable in a project?

IDEA keeps importing com.sun.istack.internal.Nullable when I auto-generate nullable methods.  This causes build failures when I try to build my code on some JDKs that don't support this package.

I would like to use @Nullable annotations, but I am confused by the options and unsure of best practices.  Of the various options, which @Nullable annotation should I use such that my project will build reliably using Maven, and how do I configure IDEA to use these annotations?

1 comment
Comment actions Permalink

Firstly you can add 'com.sun' package to 'Exclude from Import and Completion' list in Settings | Editor | 'Auto Import'.
Secondly you need to include a correct annotations jar as a dependency into your project. You can either use annotations from
org.jetbrains.annotations package (they are available at Maven repository:
http://search.maven.org/#artifactdetails%7Ccom.intellij%7Cannotations%7C12.0%7Cjar) or use custom annotations and configure '@NotNull/@Nullable
problems' inspection accordingly (Settings | Inspections).


--
Nikolay Chashnikov
Software Developer
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.