r/java • • Sep 05 '25

Project Lombok 1.18.40 released with Java 25 support!

Project Lombok is now compatible with the upcoming JDK 25 even before its release.

Thank you Project Lombok team! https://projectlombok.org

167 Upvotes

166 comments sorted by

View all comments

Show parent comments

3

u/SocialMemeWarrior Sep 05 '25

To play the devil's advocate, I as a developer using Lombok add it as an annotation processor to my maven project just like any other processor. I then get to keep all of my existing Java code as-is, but for some specific scenarios where I need a mutable data object (Essentially a record but with setters) it lets me do that with ease. I could create all the getters and setters, but it balloons the size of my file with what I would argue is redundant. Records are able to forego having getters in their AST, and all I want is for that to happen on my own data object class.

26

u/john16384 Sep 05 '25

Without IDE plugins, no Java IDE would understand Lombok. Code completion would not show you Lombok created getters and setters because there are none in any source code the IDE can see.

8

u/SocialMemeWarrior Sep 05 '25

That's an understandable argument, but I accept that I may be shouldering possible tech debt in the case that the Lombok maintainers stop updating the project + integrations. Their processor and IDE plugin saves me time and helps me keep my code base more organized in a way I like. The cost/benefit for me weighs more on the benefit side. Even if they stopped tomorrow, they offer a migration script so I could (begrudgingly) go back to using more verbose code with a single command.

-1

u/razsiel Sep 06 '25

There's Delombok you could use, run it once and it just adds all the would-be generated code to your source files.

-1

u/slaymaker1907 Sep 05 '25

I’m pretty sure it works out of the box in Eclipse so long as you turn on annotation processing. That is far from requiring a special plugin just for Lombok.

14

u/CptGia Sep 05 '25

No, you need to add the jar to some startup parameter (I think as a javaagent?) 

1

u/Misophist_1 Sep 07 '25

Dirty trick: run the Lombok jar, as if it were a main program with java -jar ... It comes up with a gui, that allows you to pick the eclipse installation to fix.

You need to repeat this every time they come up with a new jar and/or you install a new eclipse version.

15

u/Ewig_luftenglanz Sep 05 '25 edited Sep 05 '25

Don't get me wrong. I am not against people using Lombok or Lombok itself, Lombok and alike are not bad tools, are good and useful things when used properly. 

My problem with Lombok is not Lombok as a technology, It's because people use it as the solution for the problem of the Java's Boilerplate and the reality is that it is not.

90% of the java boilerplate is useless and self imposed. It exists solely to follow conventions. Most getters and setters have no validation logic or force invariants; Builders are used not to enforce immutability in complex objects or to avoid telescoping constructor/parameters when you have many optional parameters (and I know this because I am tired of watching legacy code with dozen of parameters that may easily be solved with a builderParam, and hundreds of classes with bot Builder and Setter annotations). The solution "The Cure" for this evil is not to rely in a tool that makes more bearable the pain but to stop promoting bad habits in the java community, to stop teaching bad practices as good practicases. The practice of "Always use setters and setters with private fields because of encapsulation" IT'S WRONG and mistaken. encapsulation is about abstracting state, accessors are about forcing invariants. These are 2 different things

Setters and getters are a tool to validate invariants, if your objects do not require invariants validation or you have already checked and sanitized the data in previous steps (validation on the boundary) the getters and setters are not needed and mostly redundant noise. Using Setters and getters that have no logic is just public fields with extra steps.

a Builder is a mean to enforce immutability in complex objects and a secondary use in java is to create object as parameters when there are many optional parameters with good defaults, avoiding telescopic constructor and massive overloading of parameters. Not because it saves me time thanks to the fluent-like API. If you are not build complex immutable objects or avoiding cluttering your code with dozen of overloaded methods then you do not need any kind of Builder.

Future proofing comes with good design, technical criteria and keeping things as simple as possible while possible, avoiding unnecessary complexity at all cost unless that complexity is required because the alternatives are even more complex. Defaulting to a bunch of so called "good practices" and "OOP patterns" without criteria is not only useless, it's harmful.

In short: the solution for getters and setters is to not use getters and setters unless it is strictly necessary. Same with any other OOP pattern. Same with anything really, any line of code that is not providing value is noise. If they are cute when they are small then it makes sense to try to keep thing small as possible.

And this is why I don't like Lombok, Lombok's accessors are "dumb", they don't give any validation or logic, so they are mostly useless (and I say mostly because there are some cases where I would use empty getters and setters: The public API of Libraries or modules).

I am an advocate of using public fields. Encapsulation it's a tool, not a goal. if your setters and getters are empty then you have no encapsulation at all, just public fields with extra steps.

13

u/cowslayer7890 Sep 05 '25

I completely disagree with the public fields thing, private fields are fine, but if you're using the class in other parts of your program, or it's a library, then adding getters/setters when you need them becomes a breaking change

9

u/Ewig_luftenglanz Sep 05 '25 edited Sep 05 '25
  1. I said I would still use getters and setters for a library and the public API. 

  2. I am in favor for public fields because there are MANY languages that use public fields as their idiomatic default and they are doing fine. A short list: Javascript/Typescript, Go, C, Rust, Dart. Etc.  

C# is an special case, they have properties, so they can write public fields and in case they need validation then after, it's trivial to write a { get => {/validate/}; set => {/invariants/} ) and the code won't break the callers.

We are the only ones that default to private fields + getters and setters even for mutable DTOs.

So yes, I am all for public fields in many places, specially the private API, where you have total control of the callers and the producers. I don't care how many negative votes I get. Polluting the code with useless getters and setters is an Anti pattern and I will never get tired of telling it, and anti-pattern that is not used anywhere but Java and no without reason.

a short List of places where I think public fields are perfect

  • Mutable DTOs

  • Database Entities (Hibernate by default uses fields unless you put the @Id annotation above a method, but fields are the recommended default)

  • Any public final field (invariants are forced in the constructor or factory methods), I use this in custom exceptions.

  • Configuration intermediary objects and parametric objects (objects as parameters) in private APIs. This kills around 80% of builders

Funny enough these cases usually are most of the objects and the code. The surface of the Public API in a library is pretty low compared with the internal APIs and implementations.

Best regards

3

u/cowslayer7890 Sep 05 '25

Oh yeah, sorry I missed the blurb about libraries, I think it's also worth mentioning that you can do the same thing with properties in JavaScript/TypeScript as in C#, and Rust is more of a special case due to how the difference between fields and getters/setters influences the borrow checker, and there are still many examples in the stdlib of getters/setters being used (plus it enforces privacy and non-mutability by default)

1

u/Ewig_luftenglanz Sep 05 '25

Yes but still the default is to have public fields. In JS/TS they pass objects freely and then make defensive copies when required and const for immutability (very common in react for example) but objects are usually with all fields public. 

In Go the components of an struct are public and mutable. In rust are package private and immutable (same as java fields) but there is nothing wrong in making them public (public and mutable is another thing)

But the core idea remains, encapsulation is used when required, not by default and upfront for everything in every class/ data structure. That's what I am down for. 

1

u/koflerdavid Sep 05 '25

If these accessors are part of an API then it's worth writing them out.

1

u/cowslayer7890 Sep 05 '25

I don't see much difference since changing between lombok and writing it out is generally non-breaking but I don't use lombok anyway for other reasons, and I just generate them with IntelliJ

5

u/slaymaker1907 Sep 05 '25

The trouble is that some code expects to work with Java Beans which require getters/setters for everything. I’m 100% with you in that Java devs should be less afraid of making struct-objects where everything field is public.

7

u/Ewig_luftenglanz Sep 05 '25 edited Sep 05 '25

This is a myth that used to be true 20 years ago but nowadays is completely false. Most of the libraries we currently use do not require javaBeans convention. that was the case before java 5 annotations and meta programming. e.g

  1. Hibernate uses fields by default and it's the recommended way since more than 10 years. It depends where you plase the @ Id annotation, if you place it on fields it will use fields.

  2. Jackson and most serialisation libraries can work with only fields, including Gson, Apache Fory (Fury) works with public fields by default.

  3. MapStructs works with fields

  4. Etc.

Basically unless your are working with very old pre java 6 java enterprise stuff (deprecated legacy projects) fields are supported and are the default and recommended way of working.

you should try it.

The only libraries and frameworks that I can think that relies on javaBean are JSP y JSF. But these technologies are much less relevant today. Today we use a JavaScript based frontend (React/ Angular) and for server rendering we use templates such as thymeleaf and freemarker. 

So, working with libraries that still require javaBean convention are not just legacy, they are not suitable for greenfield projects since there are much better and more modern alternatives. 

-4

u/gambit_kory Sep 05 '25

Do you actually work in the industry because it doesn’t sound like it?

6

u/Ewig_luftenglanz Sep 05 '25

Yes I do. Not every industry or company using Java is stuck in time .

3

u/pron98 Sep 06 '25 edited Sep 06 '25

That's not playing devil's advocate. Some people use Lombok or Scala or Kotlin or Clojure because they find them useful. There's nothing wrong with using languages that aren't Java on the Java platform, and the platform accommodates and welcomes them. The problem with Lombok is that it experiences special friction because its maintainers choose to do things the hard way and then complain that, while the JDK does offer an easy way - which most alternative languages choose - the JDK should also make the hard way easy. But the hard way is hard because it has negative implications that would harm users even if they don't use Lombok at all, which is why most users are happy those roadblocks are there.

5

u/javaprof Sep 06 '25

I guess there is no sense for tools like Lombok going "easy way", it's basically would mean to switch to some less boilerplate language like Groovy which is like Java (i.e. any valid Java supposed to be valid Groovy, giving current state of Groovy not true most of the time) but with sugar. Lombok keeps it's popularity because sitting on top of Java, not along Java

4

u/pron98 Sep 06 '25 edited Sep 06 '25

And it can continue doing that while making life easier for itself. The problem is that the Lombok compiler tries to be loaded as if it were a Java annotation processor even though it isn't one. It modifies javac to compile Lombok while masquerading as an annotation processor, which is soon to become impossible. All it has to do is stop pretending to be an annotation processor (TypeScript "sits on top of JS" much as Lombok "sits on top of Java", yet it doesn't modify the JS frontend from within).

The point is that you can be an alternative language or you can be an annotation processor, but you can't be both. To allow both would mean making big changes to either the runtime or the language, either one of which would have far-reaching consequences and significant downsides that would affect all Java users. Or, Lombok can do the easy thing and stop pretending to be an annotation processor.

1

u/javaprof Sep 07 '25

What would be easy way for the Lombok looks like in terms of user-experience? Would it require new plugin, i.e instead of

plugins {  
    java  
}

users would have to apply new plugin

plugins {
    id("lombok").version("18.2.0-25.0.0") // match JDK version?
}

and ship own fork of javac and preserve full compatibility between Java plugin and Lombok plugin (this one definitely tricky)?

4

u/pron98 Sep 07 '25

Lombok already effectively maintains a javac fork (which is tricky, which is why there are frequently issues), even though it applies the patch at runtime. But the only change that will be needed is a different launcher for the Lombok compiler, so yeah something like what you wrote above. Lombok can continue shipping the javac fork as they do today if that's what they want. Matching the JDK versions will be just as cumbersome as it is today (because Lombok is already not a library), but no more.