{"id":738,"date":"2017-08-01T23:55:48","date_gmt":"2017-08-01T23:55:48","guid":{"rendered":"http:\/\/choudhury.com\/blog\/?p=738"},"modified":"2021-09-05T02:08:21","modified_gmt":"2021-09-05T02:08:21","slug":"using-error-prone","status":"publish","type":"post","link":"https:\/\/choudhury.com\/blog\/2017\/08\/01\/using-error-prone\/","title":{"rendered":"Using Error-Prone with NullAway Plugin"},"content":{"rendered":"\n<p><a href=\"https:\/\/github.com\/google\/error-prone\">Error Prone<\/a> 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<\/p>\n\n\n\n<p>An example of error prone being setup for maven compiler plugin with also Null Plugin enabled <br><br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;plugin&gt;<br>    &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;<br>    &lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;<br>    &lt;version&gt;3.8.1&lt;\/version&gt;<br>    &lt;configuration&gt;<br>        &lt;source&gt;8&lt;\/source&gt;<br>        &lt;target&gt;8&lt;\/target&gt;<br>        &lt;encoding&gt;UTF-8&lt;\/encoding&gt;<br>        &lt;fork&gt;true&lt;\/fork&gt;<br>        &lt;compilerArgs&gt;<br>            &lt;arg&gt;-Werror&lt;\/arg&gt;<br>            &lt;arg&gt;-Xlint:all&lt;\/arg&gt;<br>            &lt;arg&gt;-Xlint:-processing&lt;\/arg&gt;<br>            &lt;arg&gt;-XDcompilePolicy=simple&lt;\/arg&gt;<br>            &lt;!-- Note the -XepOpt:NullAway:AnnotatedPackages= is mandatory --&gt;<br>            &lt;arg&gt;-Xplugin:ErrorProne -Xep:MissingOverride:ERROR -Xep:NullAway:ERROR -XepOpt:NullAway:AnnotatedPackages=com.choudhury&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-exports=jdk.compiler\/com.sun.tools.javac.api=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-exports=jdk.compiler\/com.sun.tools.javac.file=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-exports=jdk.compiler\/com.sun.tools.javac.main=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-exports=jdk.compiler\/com.sun.tools.javac.model=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-exports=jdk.compiler\/com.sun.tools.javac.parser=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-exports=jdk.compiler\/com.sun.tools.javac.processing=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-exports=jdk.compiler\/com.sun.tools.javac.tree=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-exports=jdk.compiler\/com.sun.tools.javac.util=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-opens=jdk.compiler\/com.sun.tools.javac.code=ALL-UNNAMED&lt;\/arg&gt;<br>            &lt;arg&gt;-J--add-opens=jdk.compiler\/com.sun.tools.javac.comp=ALL-UNNAMED&lt;\/arg&gt;<br>        &lt;\/compilerArgs&gt;<br>        &lt;annotationProcessorPaths&gt;<br><br>            &lt;path&gt;<br>                &lt;groupId&gt;com.google.errorprone&lt;\/groupId&gt;<br>                &lt;artifactId&gt;error_prone_core&lt;\/artifactId&gt;<br>                &lt;version&gt;2.9.0&lt;\/version&gt;<br>            &lt;\/path&gt;<br>            &lt;path&gt;<br>                &lt;groupId&gt;com.uber.nullaway&lt;\/groupId&gt;<br>                &lt;artifactId&gt;nullaway&lt;\/artifactId&gt;<br>                &lt;version&gt;0.9.2&lt;\/version&gt;<br>            &lt;\/path&gt;<br><br>        &lt;\/annotationProcessorPaths&gt;<br>    &lt;\/configuration&gt;<br>&lt;\/plugin&gt;<\/pre>\n\n\n\n<p>In the above we increased the severity error-prone&#8217;s <a href=\"http:\/\/errorprone.info\/bugpattern\/MissingOverride\">MissingOverride <\/a>bugpattern to Error (error-prone default was WARNING)<\/p>\n\n\n\n<p>This how the output looks like if now in maven&#8217;s compilation goal a class that has a missing @Override annotation<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-compilation-failure-output.png\"><img loading=\"lazy\" decoding=\"async\" width=\"979\" height=\"436\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-compilation-failure-output.png\" alt=\"\" class=\"wp-image-748\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-compilation-failure-output.png 979w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-compilation-failure-output-300x134.png 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-compilation-failure-output-768x342.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/figure>\n\n\n\n<p>Another feature of error-prone is that it has Intellij Integration<br>You need to install the https:\/\/plugins.jetbrains.com\/plugin\/7349-error-prone-compiler-integration once that&#8217;s done you can change the compiler that Intellij uses<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-intellij-integration.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1032\" height=\"533\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-intellij-integration.png\" alt=\"\" class=\"wp-image-753\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-intellij-integration.png 1032w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-intellij-integration-300x155.png 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-intellij-integration-768x397.png 768w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/error-prone-intellij-integration-1024x529.png 1024w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/figure>\n\n\n\n<p>Now within Intellij you will get the same compilation errors as you get from maven<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/intellij-error-output.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1079\" height=\"293\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/intellij-error-output.png\" alt=\"\" class=\"wp-image-755\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/intellij-error-output.png 1079w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/intellij-error-output-300x81.png 300w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/intellij-error-output-768x209.png 768w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/08\/intellij-error-output-1024x278.png 1024w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/figure>\n\n\n\n<p>For more details about the installation, see the error-prone documentation <a href=\"http:\/\/errorprone.info\/docs\/installation\">http:\/\/errorprone.info\/docs\/installation<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Example <a href=\"https:\/\/github.com\/muminc\/maven-errorprone-example\" data-type=\"URL\" data-id=\"https:\/\/github.com\/muminc\/maven-errorprone-example\">Maven Project Here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt; &lt;version&gt;3.8.1&lt;\/version&gt; &lt;configuration&gt; &lt;source&gt;8&lt;\/source&gt; &lt;target&gt;8&lt;\/target&gt; &lt;encoding&gt;UTF-8&lt;\/encoding&gt; &lt;fork&gt;true&lt;\/fork&gt; &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/choudhury.com\/blog\/2017\/08\/01\/using-error-prone\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using Error-Prone with NullAway Plugin&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-738","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/comments?post=738"}],"version-history":[{"count":21,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions"}],"predecessor-version":[{"id":815,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions\/815"}],"wp:attachment":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/media?parent=738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/categories?post=738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/tags?post=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}