How to enable Android lint check for the @Nullable annotation?

If the inspection in question was lint, there would be a way of configuring lintOptions inside your build.gradle to force builds to fail as in the answers to this question here

However, the inspection you are talking about is provided by the IDE itself in Android Studio. There is currently no way to stop builds for these inspections, as per this canonical answer from a IntelliJ developer Here is a link to the documentation for this static code analysis provided by IntelliJ. Within the analysis explained in the documentation, the specific name is "Constant conditions & exceptions":

This inspection analyzes method control and data flow to report possible conditions that are always true or false, expressions whose value is statically proven to be constant, and situations that can lead to nullability contract violations. Variables, method parameters and return values marked as @Nullable or @NotNull are treated as nullable (or not-null, respectively) and used during the analysis to check nullability contracts, e.g. report possible NullPointerException errors.

I think the best you can do is change its severity so it appears as a warning (red underlined in the IDE). Do it like this, go to Preferences / Inspections / Probable Bugs and change the severity of "Constant conditions & exceptions" to warning:

the probable bugs section of Inspections in Android Studio

Your project will still build if you ignore the warning, but it won't look nice:

red underline on calling get on the result of a method that is @Nullable

You'll have to set it up so that your team shares the same Android Studio code inspection settings. You can do that with a settings repository.

Please note also that you can enable the Commit Changes / Perform code analysis check box as well which will force a code analysis before the team commits.

commit changes dialog in Android Studio

When you click commit, it performs the analysis first and finds the warning you have been talking about:

code analysis dialog box in Android Studio

Please also note that forcing a team to use inspections like this may not be the best option if NPEs are becoming problematic in the project. Instead, you can try options like discussing openly the problems that returning null generates and possible solutions. This excellent article on avoiding null in the Google Guava wiki is a great starting point.


If you want lint to throw an error when certain rules are broken in the source code, you can definitely configure the project in a way that the source compilation halts. I could have written the whole process but this link more or less summarizes the whole thing

Also go through the Android link doc

Note : Analyze option in Android Studio Menu mostly uses both Lint and built in Intellij Idea Code inspection