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

JavaFX Draggable Tabs

The TabPane in JavaFX unfortunately does not provide mouse dragging / re-ording out of the box which is quite fustrating as users are now accustomed to doing that in their Browsers whey have Tabbed Browsing switched on.

There is a Jira Raised for this feature :

https://bugs.openjdk.java.net/browse/JDK-8092098

There Jira was targeted for Java 9, however Java 9 is now feature complete, so it’s likely Java 10 is the earliest we will see this being available.

Available Solutions

  1. https://github.com/sibvisions/javafx.DndTabPane

    This implementation draws a nice marker line as you drag the tabs around.

  2. http://berry120.blogspot.co.uk/2014/01/draggable-and-detachable-tabs-in-javafx.html
    This seems to be the simplest solution, its relatively easy to understand how it’s working (it works both Java 8 and Java 9-ea b158), in addition to the draggable tabs feature, it’s also detaching (tabs can be dragged out of the window into their own window).

    There is a few things you have to observe if you want to use it, as detailed in his blog.

  3. https://github.com/xylo/DraggableTabs

    There is this project which seems to based on similar solution to above, it’s more polished, has some sample code under tests, it’s also published onto maven central

Enforcing Coding Standards using Checkstyle

Checkstyle is a great tool for enforcing agreed code style across a team.

To make sure everyone in your team is observing the agreed code style. You can get the checkstyle maven plugin to fail the build if a rule is violated

Here is a simple example demonstration a simple project with checkstyle rules applied. Here is an example of checkstyle failing our build, we have setup checkstyle config in this example project to enforce left curly is a line by itself, but as you can see in the example project, the Hello class has violated the rule.

Checkstyle has an an extensive list of checks you can configure and you even write your checks aswell.

checkstyle-build-check-goal