Usability - Productivity - Business - The web - Singapore & Twins

Streamlining Lage-scale Java Development using Error Prone

It has been a while since I attended an in-person conference. Finally this October I managed to attend JavaOne in Las Vegas. I shall report on interesting sessions.

The first one is by Sander Mak on a topic near and dear to me: Code Quality

Another tool in the box

Error Prone, courtesy of Google, supplements tools like Sonar, Spotbugs or Checkstyle. Other than these tools it is a compiler plugin with > 500 checks.

It can be configured to fix a set of identified errors automatically in code, inline or as patch file. Sander used a few simple demos to drive home what is possible using the tooling. Besides the ckecks that are available out-of-the-box one can implement extensions. One interesting contribution comes from the popular mocking framework Mockito, extending the checks to your use of mocking.

Extending error-prone is possible using two complementary approaches:

  • writing your own extensions (extending BugChecker), dealing with Java's AST and all its power
  • using the included ReFaster templates that allow for powerfull pattern based code upgrades

Use cases

Just a few samples from the session:

  • implement consistency in coding style (not to confuse with code style)
  • reduce visible clutter like final before variables by using @var to denote mutable variables and consider immutable the default
  • ease the transition to higher JVM versions, e.g replace !Optional.isPresent() with Optional.isEmpty() (JDK11)
  • verify logging uses {} instead of %s
  • fail builds that violate rules and conventions

My impression

Error-prone seems to be an important tool in toolbox to produce a well groomed Java code base. I loved Sander's progression from a simple introduction example to the more complex use cases that help his company deliver (pun intended). Error-prone isn't for the faint of heart, but a component that belongs into any code base of size. The session inspired me to improve our Java tooling, well done!

The Steve pun, one last thing, was the icing on the cake

More content by Sander

Posted by on 18 October 2022 | Comments (0) | categories: Java


  1. No comments yet, be the first to comment