Some months ago we took over development and maintenance of a Java EE-based web application. The project has ok-code for the most part and uses mostly standard libraries from the Java ecosystem. One of them is lombok which strives to reduce the boilerplate code needed and make the code more readable and concise.
Fortunately there is a plugin for IntelliJ, our favourite Java IDE that understands lombok and allows for easy navigation and code hints. For example you can jump from getMyField()
to the lombok-annotated backing field of the getter and so on.
This sounds very good but some day we were debugging a weird behaviour. An abstract class contained a special implementation of a Map as its field and was annotated with @Getter
and @Setter
. But somehow the type and contents of the Map changed without calling the setter.
What was happening here? After a quite some time digging spent in the debugger we noticed, that the getter was overridden in a subclass. Normally, IntelliJ shows an Icon with navigation options beside overridden/overriding methods. Unfortunately for us not for lombok annotations!
Consider the following code:
public class SuperClass { @Getter private List strings = new ArrayList(); public List getInts() { return new ArrayList(); } } public class NotSoSuperClass extends SuperClass { @Override public List getStrings() { return Arrays.asList("Many", "Strings"); } @Override public List getInts() { return Arrays.asList(1,2,3); } }
The corresponding code in IntelliJ looks like this:
Notice that IntelliJ puts a nice little icon next to the line number where the class or a methods is subclassed/overridden. But not so for the lombok getter. This tiny detail lead to quite a surprise and cost us some hours.
Of course you can argue, that the code design is broken, but hey, that was the state and the tools are there to help you discover such weird quirks.
We opened an issue for the lombok IntelliJ plugin, so maybe it will be enhanced to provide such additional tooling information to be on par with plain old java code.