Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

Delombok removes super(); in default constructors

Context:

  • You have a class that has one or more constructors other than default constructor, so you have to define the default constructor explicitly.
  • You use Lombok to generate some methods/fields.
  • You use static code analyzers that warn empty method definitions or empty blocks, so you write super(); in the default constructor to suppress warnings.

Problem:

When you delombok the class, super(); in the default constructor disappears and the static code analyzer warns that an empty method definition is found.

Reason:

It seems by design of com.sun.tools.javac.tree.JCTree.* classes. Lombok uses them to delombok method definition, and just call print(tree.body); to print method body. https://github.com/rzwitserloot/lombok/blob/master/src/delombok/lombok/delombok/PrettyPrinter.java#L744

Solution:

If your static code analyzer respects @SuppressWarnings annotations (like PMD), add it in front of the default constructor.