I just upgraded my Spring Boot 1.5.13 application (with Lombok) to Spring Boot 1.5.14 but it now fails to compile with the following types of errors:
constructor SomeClass() is already defined in class SomeClass
for each of my POJOs, e.g.,
@Data
@NoArgsConstructor
public class SomeClass {
private String someProperty;
}
Constructor Calling form another Constructor The calling of the constructor can be done in two ways: By using this() keyword: It is used when we want to call the current class constructor within the same class. By using super() keyword: It is used when we want to call the superclass constructor from the base class.
Constructor chaining can be done in two ways: Within same class: It can be done using this() keyword for constructors in the same class. From base class: by using super() keyword to call the constructor from the base class.
No, you cannot call a constructor from a method. The only place from which you can invoke constructors using “this()” or, “super()” is the first line of another constructor.
This is a bug in Lombok 1.6.22; upgrade Lombok to 1.18.0:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
or, as a work-around, change the order of the annotations:
@NoArgsConstructor
@Data
public class SomeClass {
private String someProperty;
}
Details:
The root cause of this bug is a bug in Lombok 1.16.22. Spring Boot 1.5.13 uses Lombok 1.16.20 which does not have this bug, but Spring Boot 1.5.14 updated the Lombok dependency to 1.16.22 -- unfortunately, the Lombok project does not comply with SEMVER which then triggered this bug.
I was facing this issue even on the most recent version i.e.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
After marking my member variables as final everything worked.
@RequiredArgsConstructor
generates a constructor with the required arguments, where a required arguments are final fields and fields annotated with @NonNull
(more on that later)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With