Contents

Fix Generating Equals/hashcode Implementation but Without a Call to Superclass

The warning from building a Spring Boot project

When I built my Spring boot project, I got 20 warnings about a same thing. The warning shows: Generating equals/hashCode implementation but without a call to superclass

https://raw.githubusercontent.com/williamyuaus/blog-img/master/img/20220810145523.png

Description of the warning

This warning is from lombook, it happens when we inherit a child class from parent class by using @Data @ToString @EqualsAndHashCode, IDE will trigger the warning: Generating equals/hashCode implementation but without a call to superclass .

Solution

There are two solutions:

  1. add annotation @EqualsAndHashCode(callSuper = true) on the class
  2. create lombook config file in the project root path: src/main/java. Note: this solution requires the version of lombook > 1.14.

I recommend the solution 2, since you will not need to add the annotation to all the required classes.

To impletement the solution, you need to create lombook.config in the path of src/main/java. If you have more than one packages, you may need to create multiple config files.

The content of the config file includes:

config.stopBubbling=true
lombok.equalsAndHashCode.callSuper=call

When we rebuild our project, you will not get these warnings anymore.

Cheers!