Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lombok's @SuperBuilder - Error java: cannot find symbol

I've been using Lombok with IntelliJ for a while now. I have installed newest (v. 0.28) Lombok plugin, enabled annotation processing and added a Lombok dependency (v. 1.18.10) in pom.xml. It all worked well until today, when I wanted to implement the experimental @SuperBuilder.

I have a simple hierarchy:

@SuperBuilder
public class User {
   private String a;
}

@SuperBuilder
public class Employee extends User {
   private int b;
}

@SuperBuilder
public class Employer extends User {
   private double c;
}

I wanted to set the fields from parent's class in child's builder, e.g.:

Employee.builder().a("Positive").b(1).build();

Employer.builder().a("Negative").c(-2.1).build();

At the first glance it all seems to work - there are no errors displayed when the file is open and the builder is fine. However after mvn clean compile I get the following result on every @SuperBuilder line (i.e. in each of those 3 classes): Error:(20) java: cannot find symbol

What am I missing here? I tried updating Lombok plugin version and reinstalling it, but without any success.

like image 479
Fajeczny Avatar asked Jan 07 '20 10:01

Fajeczny


2 Answers

I've faced same issue and adding @SuperBuilder to the all "base" classes solved the issue.

Before:

abstract class Parent {
   ...
}

@SuperBuilder
class Child extends Parent {
   ...
}

After:

@SuperBuilder              // <- addded
abstract class Parent {
   ...
}

@SuperBuilder
class Child extends Parent {
   ...
}
like image 147
Leonid Dashko Avatar answered Sep 16 '22 11:09

Leonid Dashko


Ok, I found it. I missed that the User class was extending a basic class every entity in our application extends. It seemed so obvious and yet I didn't notice...

Anyway, I found out only by running the mvn clean install in terminal - the output was much more verbose that the one in IntelliJ and it pointed out this class. After adding @SuperBuilder annotation on top of it compilation was successful.

But @SuperBuilder(toBuilder=true) is the right way of using it.

like image 45
Fajeczny Avatar answered Sep 18 '22 11:09

Fajeczny