Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the risks with Project Lombok?

I'm coming up with performance goals for the new year, and I thought I'd be fun to put a goal to reduce the size of the code base, especially boilerplate. One action I've come up with to address this is to use Project Lombok to make beans as short as they should be. But I have a habit of overlooking downsides to new software and approaches, so I'm relying on the Stack Overflow community: Can anyone tell me why Lombok is a bad idea?

like image 665
jldugger Avatar asked Jan 03 '11 22:01

jldugger


People also ask

Is it safe to use Project Lombok?

Lombok is still being actively maintained and enhanced, which bodes well to the safety level of adoption.

Why you should not use Lombok?

The reasons for not using this annotation are very similar to the case of @Builder : it allows object creation in invalid state. And how else can you add values to this class if not using the also discussed @Setter ? Use it only if it makes sense to your object that it exists with all empty values.

Is Lombok a good idea?

Lombok is a really nice tool that helps us to write less code and helps us to concentrate more on our actual work. It is more about how you use Lombok in your project.

Does Lombok affect performance?

It does not decrease performance at runtime, there is a performance flaw at compiletime.


2 Answers

A limitation of Lombok is the fact that it is closely tied to the java compiler. Since the annotation processor API only allows creation of new files during the compilation (and not the modification of the existing files) lombok uses that API as a entry point to modify the java compiler. Unfortunately these modifications of the compiler make heavy usage of non-public APIs. Using lombok may be a good idea but you must be aware that upgrading your compiler may break your code. The probability is low but I always feel uncomfortable using non-public APIs.

like image 93
Jcs Avatar answered Oct 01 '22 22:10

Jcs


In my opinion source code in "Java+Lombok" is not Java source code anymore. I see it as something similar Borland company made many years ago in their Borland C++ Builder IDE for VCL - they introduced "properties" in C++ code effectively introducing some kind of a new programming language that wasn't C++ anymore (not C++ in sense of standard of C++ language). Sources using "Java+Lombok" are not valid sources in sense of Java language specification. Moreover I think annotations were not designed to influence language semantic.

like image 20
Krzysztof Tomaszewski Avatar answered Oct 01 '22 22:10

Krzysztof Tomaszewski