Using Error-Prone with NullAway Plugin

Error Prone is static anaylsis tool for Java. It hooks into the compilation process. To use in your maven build you need do some configuration for the maven compiler plugin

An example of error prone being setup for maven compiler plugin with also Null Plugin enabled

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
<fork>true</fork>
<compilerArgs>
<arg>-Werror</arg>
<arg>-Xlint:all</arg>
<arg>-Xlint:-processing</arg>
<arg>-XDcompilePolicy=simple</arg>
<!-- Note the -XepOpt:NullAway:AnnotatedPackages= is mandatory -->
<arg>-Xplugin:ErrorProne -Xep:MissingOverride:ERROR -Xep:NullAway:ERROR -XepOpt:NullAway:AnnotatedPackages=com.choudhury</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
</compilerArgs>
<annotationProcessorPaths>

<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.9.0</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>0.9.2</version>
</path>

</annotationProcessorPaths>
</configuration>
</plugin>

In the above we increased the severity error-prone’s MissingOverride bugpattern to Error (error-prone default was WARNING)

This how the output looks like if now in maven’s compilation goal a class that has a missing @Override annotation

Another feature of error-prone is that it has Intellij Integration
You need to install the https://plugins.jetbrains.com/plugin/7349-error-prone-compiler-integration once that’s done you can change the compiler that Intellij uses

Now within Intellij you will get the same compilation errors as you get from maven

For more details about the installation, see the error-prone documentation http://errorprone.info/docs/installation

Example Maven Project Here

Leave a Reply

Your email address will not be published. Required fields are marked *