Recently, with the remote help of guys from Uber in California, I integrated NullAway and ErrorProne with the one of my open-source Android projects.

## What is NullAway?

Basically, it’s a tool to help eliminate NullPointerExceptions (NPEs) in your Java code. It detects situations where NPE could occur at the compile time. Let’s have a look at the following code:

NullAway will find out that we’re passing null and we’ll get appropriate error message:

It’s good to have checks like that because they eliminate possible bugs in advance and follows Clean Code principles.

## A few words about ErrorProne

NullAway is built as a plugin to ErrorProne and can run on every single build of our code. Moreover, ErrorProne can perform other checks on our code, which can find out commonly people mistakes. E.g. it can detect a situation, where programmer forgot to add @Test annotation in the unit test method in a test suite and other things. It has built-in bug patterns, which are used during code analysis.

## Integration with the Android project

I’ve integrated ErrorProne and NullAway with ReactiveNetwork Android library. First, in the main build.gradle file, I’ve added the following lines:

Next, in the library/build.gradle file, I’ve added appropriate plugins in the top:

Afterwards, I could add dependencies:

The last thing to do, is the task responsible for running analysis during project compilation:

That’s it! Now, I could run analysis by typing:

and fix the issues. I think, a quite similar approach and configuration could be applied to a regular, pure Java project built with Gradle. If you’re interested in the complete configurations, check it out in my project at: https://github.com/pwittchen/ReactiveNetwork. You can also view Pull Request #226 made by @msridhar (kudos for him!).