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
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
Just a few samples from the session:
- implement consistency in coding style (not to confuse with code style)
- reduce visible clutter like
finalbefore variables by using
@varto denote mutable variables and consider immutable the default
- ease the transition to higher JVM versions, e.g replace
- verify logging uses
- fail builds that violate rules and conventions
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