17

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?

AnthonyW
  • 1,910
  • 5
  • 25
  • 46
Andre Perkins
  • 7,640
  • 6
  • 25
  • 39
  • 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 Answers1

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