1

I recently upgraded to Eclipse 2021-03 version (due to some plugin issues with an older version), but am now having issues using lombok in existing projects.

The lombok jar is imported into the project:

lombo referenced library

And the class imports for AllArgsConstructor, Getter and Setter do not throw any errors in the classes they are required for:

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class Greeting {
    
    private @Getter @Setter final long id;
    private @Getter @Setter final String content;
    
}

However, these annotations are not being respected anywhere else in the project.

Firstly, both the "id" and "content" fields above show as uninitialised final fields due to there being no apparent constructor:

Final fields not initialized

Similarly attempting to construct in a RestController class elsewhere shows a "constructor undefined" error:

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @GetMapping("/greeting")
    public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
        Greeting greeting = new Greeting(counter.incrementAndGet(), String.format(template, name)); 
        System.out.println(greeting.getContent());
        return greeting;
    }
}

Constructor undefined

The getter method "getContent()" in the above code always shows an "undefined" error (similarly if trying to add implicit setters):

Getter undefined

If I add explicit constructors, getters and setters back into the Greeting class, everything works as expected:

Explicit constructor and getter Working Controller class

nick_j_white
  • 534
  • 6
  • 27
  • Does this answer your question? [Lombok is not generating getter and setter](https://stackoverflow.com/questions/11803948/lombok-is-not-generating-getter-and-setter) – Jan Rieke Jun 16 '21 at 13:07
  • 1
    It looks like it should - certainly all the symptoms I'm describing above fit the issue. However, I've tried installing by running the jar, followed by explicit exit/start multiple times to no avail. I can see there's an entry in eclipse.ini: -`javaagent:D:\.m2\repository\org\projectlombok\lombok\1.18.20\lombok-1.18.20.jar`, and the same jar exists in the Maven depenencies for the build paths of affected projects. – nick_j_white Jun 16 '21 at 14:27
  • Does Lombok show up in the bottom of the About dialog text? – Jan Rieke Jun 16 '21 at 20:01
  • Just checked, and it doesn't show. I checked my old version (2019-12) and it does display there: `Lombok v1.18.20 "Envious Ferret" is installed. https://projectlombok.org/` – nick_j_white Jun 16 '21 at 21:56
  • Ok, found the issue - my eclipse.ini got messed up and was missing `-vmargs` . After fixing and restarting the IDE, everything worked fine. Thanks! – nick_j_white Jun 16 '21 at 22:01
  • @nick_j_white Is that due to lombok installation? If it is, then it would be good if you add that as an answer. – Gautham M Jun 17 '21 at 04:45

0 Answers0