sonarqube + lombok = false positives

This case should be perfectly handled by SonarJava. Lombok annotations are taken into account at least since version 3.14 (SONARJAVA-1642). The issues you are getting are resulting from a misconfiguration of your Java project. No need to write any custom rules to handle this, this is natively supported by the analyzer. SonarJava reads bytecode to … Read more

Lombok @Builder and JPA Default constructor

Updated Based on the feedback and John’s answer I have updated the answer to no longer use @Tolerate or @Data and instead we create accessors and mutators via @Getter and @Setter, create the default constructor via @NoArgsConstructor, and finally we create the all args constructor that the builder requires via @AllArgsConstructor. Since you want to … Read more

Lombok annotation @Getter for boolean field

Read the ‘small print’ section on the lombok page https://projectlombok.org/features/GetterSetter.html For boolean fields that start with is immediately followed by a title-case letter, nothing is prefixed to generate the getter name. So the behavior you experience is as specified. Note that the behavior is different for boolean and Boolean: @Getter private boolean isGood; // => … Read more

Build an object from an existing one using lombok

You can use the toBuilder parameter to give your instances a toBuilder() method. @Builder(toBuilder=true) class Foo { int x; … } Foo f0 = Foo.builder().build(); Foo f1 = f0.toBuilder().x(42).build(); From the documentation: If using @Builder to generate builders to produce instances of your own class (this is always the case unless adding @Builder to a … Read more

Building with Lombok’s @Slf4j and Intellij: Cannot find symbol log

In addition to having Lombok plugin installed, also make sure that the “Enable annotation processing” checkbox is ticked under: Preferences > Compiler > Annotation Processors Note: starting with IntelliJ 2017, the “Enable Annotation Processing” checkbox has moved to: Settings > Build, Execution, Deployment > Compiler > Annotation Processors

Is it safe to use Project Lombok? [closed]

TL; DR: Yes, it’s pretty safe to use and I’d recommend using it. (May 2022) Original Answer Just started using Lombok today. So far I like it, but one drawback I didn’t see mentioned was refactoring support. If you have a class annotated with @Data, it will generate the getters and setters for you based … Read more

Lombok problems with Eclipse Oxygen

My env: java version “1.8.0_144” Eclipse: Eclipse Java EE IDE for Web Developers. Version: Oxygen Release (4.7.0) Build id: 20170620-1800 Exit Eclipse(if it is open) and downloaded jar from https://projectlombok.org/download execute command: java -jar lombok.jar This command will open window as shown here https://projectlombok.org/setup/eclipse, install and quit the installer. Add jar to build path/add it … Read more

Java SneakyThrow of exceptions, type erasure

If you compile it with -Xlint you’ll get a warning: c:\Users\Jon\Test>javac -Xlint SneakyThrow.java SneakyThrow.java:9: warning: [unchecked] unchecked cast throw (T) ex; ^ required: T found: Throwable where T is a type-variable: T extends Throwable declared in method <T>sneakyThrowInner(Throwable) 1 warning That’s basically saying “This cast isn’t really checked at execution time” (due to type erasure) … Read more