While looking at the various options in Android Studio's Analyze tab, I came across an option called "infer nullity". I am just curious how this tool is supposed to be used and what can it do for my Android Studio project?
Asked
Active
Viewed 5,798 times
17
-
Beware of bug https://code.google.com/p/android/issues/detail?id=66640 which is that if it adds annotations.jar to your project, it won't update build.gradle. – Scott Barta Mar 25 '14 at 17:35
-
See also http://stackoverflow.com/questions/4963300/which-notnull-java-annotation-should-i-use – AnthonyW Apr 24 '14 at 13:49
1 Answers
18
This option analyses your code and adds @Nullable
and @NotNull
annotations to your variables and parameters. This assists IntelliJ in detecting contract violations in your code and suggesting null-checks where necessary. To get the full benefit of this feature, you must annotate as much of your code as possible.
The downside of "Infer Nullity" is that, by default, it uses annotations from a JetBrains IntelliJ specific Jar (com.intellij.annotations.NotNull
). As of version 10.5 of IntelliJ, there does seem to be some support for using other annotations.
For more information check out the detailed How-To on this feature.

AnthonyW
- 1,910
- 5
- 25
- 46
-
3
-
1new how-to link: https://www.jetbrains.com/help/idea/inferring-nullity.html – logi0517 Nov 28 '17 at 09:20
-
In android studio 3.1, the annotations come from android.support.annotation. – dfrankow Dec 03 '18 at 16:47