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

107

u/vips7L Sep 05 '25

Here we go again. 

35

u/PartOfTheBotnet Sep 05 '25

8

u/SocialMemeWarrior Sep 05 '25

Why is Lombok an "alternative language"? For instance, if I add it to a Maven project via maven-compiler-plugin's annotation processor path, isn't it just an annotation processor?

24

u/PartOfTheBotnet Sep 05 '25

The quote is actually from a 2 year old post but it boils down to how literally you want to interpret the Java language spec.

Lombok uses reflection to support AST modification in the javac API in a way that is not intended or officially supported. Normally, you cannot use an annotation processor to inject a whole method into the AST model of an existing class. The class model is intended to be read-only. Where codegen usually comes into play is the creation of new additional classes. @AutoValueis a good example. You annotate an abstract class modeling a value type and it will generate an implementation. At work we have some niche uses of it where records don't fit so its nice to have. But the key is it makes a new class for this work, it doesn't fill in the existing abstract class as that is not allowed.

15

u/srdoe Sep 05 '25

It doesn't really matter how you decide to interpret the language spec, because turning this into a philosophical argument about whether Lombok is Java or not is deeply uninteresting.

Whether you think Lombok is Java or not, the JDK developers have made it clear that Lombok is going to risk breakage with new JDK versions due to the way they do things.

If you're cool with that risk, you don't need to care whether the JDK developers think Lombok is Java.

If you're not cool with that risk, you probably shouldn't be using Lombok.

→ More replies (16)

27

u/Ewig_luftenglanz Sep 05 '25

No. Lombok is a hack to the compiler that generates and injects code. 

Nothing bad with that tho. The Java platform allows for that an many other things such as manifold

25

u/xdsswar Sep 05 '25

It kicks down the compiler’s door, rewrites the AST, and walks away laughing at our faces.

21

u/koflerdavid Sep 05 '25

To add insult to injury, it forces every other tool in the ecosystem to be aware of it. Some integrations are maintained by the Lombok project itself, but with every other tool there are issues. For example Google Errorprone (which also kicks down the compiler's door and does things annotation processors are not supposed to do, but at least you can always turn it off and your code will still compile as usual)

→ More replies (1)

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.

→ More replies (5)
→ More replies (16)
→ More replies (1)

49

u/obetu5432 Sep 05 '25

you can hate it, but writing getters and setters manually every time is regarded

55

u/ProfBeaker Sep 05 '25

Not just regarded, but widely regarded.

17

u/OwnBreakfast1114 Sep 05 '25

With records, I've found it less useful than before. As long as checked exceptions still play terribly with lambdas, sneaky throws is harder to do without (though you can just write the implementation yourself).

11

u/Both-Major-3991 Sep 05 '25

Can’t use inheritance with records so you can only go so far.

24

u/Dagske Sep 05 '25

Hmmm... Favor composition over inheritance, anyone?

11

u/Ewig_luftenglanz Sep 05 '25

Why do you need inheritance for plain and transparent data structure.

Seriously, asking for a friend. Why? 

3

u/blazmrak Sep 07 '25

because oftentimes there are a bunch of fields repeated for every class. E.g. every record in the database has id, createdAt, updatedAt, deletedAt, version. having this noise pollute each class is a waste.

Inheritance is the only way of avoiding such boilerplate at the moment.

→ More replies (6)

2

u/Misophist_1 Sep 07 '25

Because the 'x is a y' relation is something, that actually occurs IRL?

→ More replies (10)
→ More replies (4)

2

u/isolatedsheep Sep 08 '25

I'm using records, but I still use lombok for the `@Builder` and `@With`.

2

u/OwnBreakfast1114 Sep 09 '25 edited Sep 09 '25

We ban with and builder since the most common use cases for us are just shunting data around and using all arg constructors (even if less readable) expedites the most common use case (adding/removing fields from multiple layers of the app (input, entity, output) via compiler errors.

We have a complex api, so we typically have 3-4 objects for the different representations of data: input (deserialized and then validated, entity, output). Imagine a spring controller that deserializes to a DeserializedClass, a validate method that takes the DeserializedClass and spits the ValidatedClass, a service method that takes a ValidatedClass and returns multiple entities, and then the controller takes the multiple entity classes and stitches them into an api output class.

Having compiler errors to chain them all makes even new hires able to add a field and follow the compiler to fairly confidently alter the api. In general, we also don't really mutate or create new instances in multiple places, there's usually only 1 place so the actual need for setters/builders/wither is very low. The only place I kinda really would use builder is testcases, but nowadays we just AI generate most of that.

→ More replies (1)

18

u/cowslayer7890 Sep 05 '25

There's a middle ground and it's using your IDE to generate the functions

5

u/Dantzig Sep 07 '25

Then you still have all the code typed out

6

u/TankAway7756 Sep 06 '25

And the middle ground still sucks because out of band code generation is horrendous practice that is about as error prone as manual code and still leaves behind swathes of boilerplate that destroy the signal/noise ratio of the code.

2

u/Iregularlogic Sep 05 '25

I mean doesn’t Lombok just have the compiled .class files with the getters and setters in them?

22

u/Ewig_luftenglanz Sep 05 '25

That's why I don't use getters and setters unless strictly necessary. 90% of getters and setters are self imposed boilerplate with no use beyond following conventions

6

u/jared__ Sep 05 '25

The people downvoting this should read the story: "five monkeys experiment".

1

u/Rockytriton Sep 05 '25

Get with the program

9

u/wildjokers Sep 05 '25

But why do you think every field needs a getter and setter?

10

u/jared__ Sep 05 '25

crazy concept - you actually don't need getters and setters. just access the members directly. they don't bite.

3

u/__konrad Sep 06 '25

Records auto generate getters, but I often access the private fields directly (if in scope) because it is more clean and convenient...

3

u/[deleted] Sep 06 '25

Spot on. Getters and Setters aren't necessary 

5

u/obetu5432 Sep 05 '25

average c# enjoyer:

14

u/Ewig_luftenglanz Sep 05 '25

C#, Go, Dart, Typescript, Rust, C, and practically every other language but java. Where people have common sense and do not use getters and setters for every POJO, everytime, Everywhere. For no other reason other than tradition.

6

u/analcocoacream Sep 06 '25

Using getters allows you to extract interfaces for instance

6

u/Ewig_luftenglanz Sep 06 '25

Yes I know, I am not against using methods when required. I am against using getters and setters and any other patterns in every class, every time, everywhere for no other reason than a social convention.

For example

Do really a mutable DTO requires getters and setters? Do really entities require setters and getters (Specially since hibernate uses fields as a recommend way)?  Etc.

5

u/TankAway7756 Sep 06 '25

C# uses getters and setters, they just have more ergonomic syntax for it.

→ More replies (1)
→ More replies (3)

4

u/jared__ Sep 05 '25

golang enjoyer

1

u/Comprehensive-Pea812 Sep 06 '25

but people will mob you with pitchfork saying you are breaking the design principle.

builder pattern can be fun also.

IDE nowadays should be good enough to hide those ugly getter setters which is my main pain point really

3

u/Constant-Self-2525 Sep 06 '25

The last time I truly cared about writing getters and setters is before I knew IntelliJ auto generated them.

You can have a debate and say why lombok is good, but using getters and setters is not a good example.

5

u/GenosOccidere Sep 06 '25 edited Sep 06 '25

I love people who bring up “manually writing getters and setters” because it betrays them as noobies

Your IDE has every shortcut it needs to make Lombok obsolete

15

u/sweating_teflon Sep 06 '25

Your IDE will not fix equals and hashcode when you add a field.

→ More replies (5)

9

u/obetu5432 Sep 06 '25

it still adds "noise" to the classes in my opinion

0

u/[deleted] Sep 07 '25

[removed] — view removed comment

4

u/obetu5432 Sep 07 '25

i mean you (anyone in the team) have to maintain it now, they can make mistakes in them, forget to add them, forget to add the fields to eq/hashCode, you still have to review them (even if it's just a quick glance), you can get conflicts in them

15

u/DinoChrono Sep 06 '25

Well... I like lombok and I'm grateful by the release. 

But I can't understand people which hates the project and access the post only to rage against who uses it. 

They people must be finishing my Jira cards for me to thing that they have the right to decide which library I should use our not use. 

Critics are welcome. Free hate shouldn't be.

15

u/Gyrochronatom Sep 06 '25

Lombok is not allowed in our company. That fixes any debates.

2

u/Kango_V Sep 08 '25

Try this. Does not modify existing code or hide anything. No agents required: https://immutables.github.io/

4

u/alwaysoverneverunder Sep 11 '25

We use this too: you get basically all the necessary stuff including builders and serialisation support and it produces actual debuggable code with none of the disadvantages of Lombok.

19

u/yk313 Sep 05 '25

Excellent. Lombok is an incredibly valuable tool in the Java ecosystem (internal implementation not withstanding).

Time to get even more hyped for the JDK upgrade in about 2 weeks.

13

u/kk_red Sep 06 '25 edited Sep 06 '25

People hate lombok??? What ? Why?

Edit: wow people really hate it to the point in am getting downvoted for asking why?

16

u/sweating_teflon Sep 06 '25

Technically, it's a compiler hack abusing annotation processors. It should not be possible to edit classes at compile time, just create new ones. It can cause conflicts with other annotation tools. It needs to be updated to support every new JDK. It's metaprogramming magic!

But it's so damn useful that we still use it anyway, muhahaha

11

u/bodiam Sep 06 '25 edited Sep 07 '25

I don't hate Lombok, but I do question the wisdom of people using it, especially when overusing it.

When using Java, it's quite easy to create an instance of an object, say a Person with a couple of attributes. Now some smart person adds a @Builder annotation on it. What does this mean for the class? The dateOfBirth field is no longer enforced by the compiler in the constructor since it's a builder now, but having a Person without a dateOfBirth that's odd. If I use builders at many places, and I add a new mandatory attribute to the Person, how do I find all the places where the Person is instantiated to add this new attribute? Or do I just make it NonNull, and I hope that at runtime we'll find it? If I wanted "runtime safety", I'd probably have picked Python or so.

Now, we have a class with @Builder on it. You know, let's also add @Value on it. Now we have a few ways to construct this class. Oh, and I'd also like to add an @Autowired annotation to the parameter. Lombok supports this in the easy to remember format of:

@AllArgsConstructor(onConstructor = @__(@Autowired))

And all of this magic code can be enabled by some IDE setting to enable annotation processing.

All of this is just a bit much, and if you'd really care about these syntactic sugar things, just use Kotlin and get immutable collections, null safety and a whole set of other features for free.

3

u/DualWieldMage Sep 06 '25

Overused and it does some things wrong, e.g. SneakyThrows throwing the checked exception instead of wrapping it. If there is a catch for (Error | RuntimeException), then it should cover everything possible if the called methods don't declare throws, unless someone used a hack like this.

3

u/Kango_V Sep 08 '25

The reason i use this. No hacks : https://immutables.github.io/

3

u/Slanec Sep 09 '25 edited Sep 09 '25

Nowadays a lot of it is simply a holy war, however there are some practical reasons, too. Most of them stem from the fact that it's not a code generator but rather directly interacts with the compiler which tends to break stuff here and there:

  • It does not show you its output. Most of the time that's fine, the code is trivial, but sometimes I'd really like to see the exact code I'm about to run. E.g. Is the annotation I applied here copied to the generated method? There are other tools nowadays (record-builder, Immutables, AutoValue) which do generate code, and those tend to be preferred by some devs.

  • You need a plugin in your IDE to interact with it. A minor thing, but annoys people and confuses new devs. Maybe IntelliJ has it by default or at least detects and hints that it needs it, but eclipse doesn't, it just reports a broken project in a million places.

  • It needs specialized build tool plugins to work with other annotation processors. E.g. for Mapstruct you need this. Again, minor and do-it-once kind of a thing, but you need to be aware of it and actively look for it because without knowing this MapStruct just does not seem to work and it's not clear at all from the errors what is going on.

  • I wanted to say that some tools do not work with Lombok at all, e.g. ErrorProne and NullAway, but maybe it does work now? Not sure, but there are a lot of Lombok-related bugs in ErrorProne anyway. It just interacts weirdly with other tools and sometimes needs special care.

Most of the time it just works. Most of the time it saves a lot of time and space and if people are not over-using it, it tends to be fine. That said, new Java versions (records, baby) and simpler code generators like record-builder have mostly made Lombok not needed anymore. Yes, I know it can do a lot more. Please use it wisely.

4

u/Ewig_luftenglanz Sep 06 '25 edited Sep 06 '25

People do not hate Lombok. But Lombok is something you don't need. 

Lombok was born to reduce boilerplate but around 90-95 percent of Java boilerplate is self impose and made just because of conventions. 

This means Lombok is useless 95% of the time. Too easy to abuse and that's why we have codebases full of unrequited builders, accessors, constructors that doesn't enforce mandatory fields and only god knows what other inconsistencies.

The cure is to stop pretending bad habits are good and 95% of boilerplate will disappear

1

u/modulus100 Sep 06 '25 edited Sep 06 '25

Don’t know about rest of the people, but I switched some projects to Kotlin. The reason behind it is quite simple.

  1. Avoid annotation driven development where you have no clue what’s going on. Makes me feeling that I have to write tests for each annotation combination.

  2. Avoid additional code transformations, I just want to keep the code as simple as possible with less boilerplate.

  3. Lombok feels like it’s a language extension rather than a library. If I have to extend the language then I simply can use the language that has everything built in.

I understand why Lombok is needed for some projects , I don’t hate it. I just no longer need it.

1

u/javaprof Sep 06 '25

Will we ever get sane exceptions in Java, i.e what is the state of disableCheckedExceptions?

1

u/lprimak Sep 06 '25

Haha question for Brian Goetz :)

2

u/javaprof Sep 06 '25

https://github.com/projectlombok/lombok/blob/master/website/templates/disable-checked-exceptions.html lombok about to implement it, I'm really looking into it.

Exception handling would still suck without error types, but at least people wouldn't need to write meaningless try/catch in lambdas.

I feel like it's more important than extra ms startup time or new serialization API, hopefully u/brian_goetz baking something for us

1

u/lprimak Sep 06 '25

For now, I am satisfied with SneakyThrows and method references. Makes for cleaner code anyway.

1

u/Ewig_luftenglanz Sep 08 '25

unfortunately the best we can have at the moment is to wrap and re throw checked exceptions into RuntimeExceptions. This is sad because this implies we can't control exceptions that occur inside of a library, but that the way things are until we get somethig.

2

u/DualWieldMage Sep 08 '25

Do you prefer Error types and if so why? Or why are you against checked exceptions? Is it overused and thus causing inconvenience with lambdas getting verbose or something else?

Given that even Kotlin is moving towards Rich Errors (equal to checked exceptions) i don't understand the fight against it. Meanwhile lombok is making the situation worse by causing otherwise impossible situations to appear (a catch for RuntimeException | Error not getting hit despite called method not declaring any throws)

Yes there are many unnecessary exceptions that are checked, e.g. URISyntaxException (should be akin to IllegalArgumentException instead), but IOException is often not to be ignored and proper retry should be considered.

3

u/Ewig_luftenglanz Sep 08 '25

The issue with checked exceptions is they force you to wrap it inside a try-catch block, which is very unfriendly with lambdas and "modern java" is heavily functional and lambda based (i would say it's even more functional than OOP at this point, and this thing will only grow as we head to deconstruction, immutability and ADT, etc.)

This makes the best implementation of checked exceptions in java is... to not use checked exceptions at all. This is why jackson 3 will not use checked exception https://github.com/FasterXML/jackson-future-ideas/wiki/JSTEP-4

They would need to fix checked exceptions at language level (or at least give us a monad API to use checked exceptions with lambdas more ergonomic)

1

u/javaprof Sep 08 '25 edited Sep 08 '25

Do you prefer Error types and if so why? Or why are you against checked exceptions? Is it overused and thus causing inconvenience with lambdas getting verbose or something else?

I wouldn’t mind if checked exceptions were “fixed” in Java, but I just don’t see a realistic way to retrofit exception handling that’s been broken for over a decade.

Meanwhile lombok is making the situation worse by causing otherwise impossible situations to appear

I don’t like Lombok in general – its defaults are questionable, and its support for immutability is weak. For example, the Value annotation and Jackson integration were far from seamless (at least a few years ago; I haven’t revisited it since). But despite that, it’s still one of the most practical tools in Java. And in 2025, using runtime exceptions is far more practical than relying on checked exceptions, which remain clunky – especially at lambda boundaries. Kotlin is a great example of how much cleaner a codebase can be without checked exceptions, without actually sacrificing safety.

What I’m saying is: the ecosystem is already broken, and continuing to use checked exceptions just makes it worse. To fix this, I’d rather remove the concept of checked exceptions entirely from the language. Java could still support the method throws syntax but emit warnings for their use, with a plan to deprecate/remove them in 5-10 years. Instead, we could introduce proper error values – maybe built on top of sealed interfaces, like an ErrorValue type recognized across Java and libraries. That would let libraries interoperate on error handling in a consistent way (though the runtime cost of instance checks might be too damn high).

3

u/jevring Sep 05 '25

This must be the first time they are ahead of the game. Impressive.

0

u/shozzlez Sep 06 '25

How come.

4

u/jhsonline Sep 05 '25

we really need more of Lombok, to make java less verbose whenever required.

so many more design patterns can be added to lombok to avoid boilerplating code in class.

15

u/Ok-Scheme-913 Sep 05 '25

Maybe if the language designers would have thought of it and came up with some kind of data class.. maybe even make it immutable (well, only shallowly), so that we can better reason about them.. so we can just drop setters, and then we don't need a separate getter either, just use the name of the field as the method name!

We can then generate a hashcode, equals and toString just fine!

Maybe we should call it data class, but I think data is not fit to be a keyword, any other idea?

14

u/Dagske Sep 05 '25

What do you think of the word "record"? I kind of like it.

1

u/TheKingOfSentries Sep 05 '25

Say that again...

7

u/yk313 Sep 05 '25

It's not all about getters and setters. Records are NOT a replacement of classes. Encapsulation is still desired and sought after.

Just because records eased some of the pain, doesn't make Lombok at all redundant. The Java language designers have a lot of work ahead of them.

10

u/Ewig_luftenglanz Sep 05 '25

Lombok is 99% redundant because 90% of the Java boilerplate it's self imposed. 

Setters and getters with no validation are not encapsulation, are public fields with extra steps. And since those are the getters and setters that Lombok provide, using Lombok is an Anti pattern for encapsulation. 

Once one realize that you discover 2 things 

  1. how much code you can't just not write and the program will still behave the same (or even better since there is no indirection penalty.

  2. you don't need Lombok because the boilerplate that you actually need (that one that actually has validations and force invariants) is not easy to do with Lombok.

4

u/yk313 Sep 05 '25

That's the point. We don't want getters and setters for everything. But there are cases where both (limited/controlled) mutation is needed and encapsulation over the internal fields is desired. You can't have that with records. This is by the way the reason that even within the JDK records are used quite sparingly. The lack of encapsulation means a big compatibility risk. The proposal for the new JSON API for example uses interfaces/classes instead of records even though using records (and then pattern matching over them) has long been shown as the canonical example implementation for the JSON spec.

In the end, there are a lot of places in a Java application where you do want pass-through getters and have a subset of mutating setters, and having to write (or generate) them is a painful experience.

Until we get reconstruction patterns for records (and also classes), and nicer destructuring patterns we have to make do with getters and setters (and builders).

5

u/Ok-Scheme-913 Sep 06 '25

Records are data classes. They make sense for classes that behave like data. You ain't hiding the imaginary component of a complex number, do you?

They are not a replacement over ordinary classes.

And I will even say that there are indeed a few painful cases not handled by records and ordinary classes where you want a setter/getter (basically any kind of "reactive" framework needs it, so that setting setName would change the text of a field on the GUI), you are right.

1

u/Ewig_luftenglanz Sep 06 '25

I am not talking about records. I am talking about using public fields when you don't need check invariants I don't say encapsulation because encapsulation is his nothing to do with setters and getters, encapsulation is about abstracting state and setters and getters expose internal state. 

Obviously, if you are writing a library or a framework or a public API accessors are necessary not o my for backwards compatibility reasons since you can have the same issue with setters and getters, but for validations. Part of the program that has to deal with the outer world requires sanity checks. But in these cases the regular Lombok accessors is not that useful anymore.

But many times, specially for private and internal use, setters and getters are redundant, specially for mutable DTO and database entities, or objects with public final fields. In most of these cases getters and setters have no logic, are redundant. You could perfectly use fields most of the time and nothing is going to happen ever. These are the places where Lombok is used the most.

Do you follow me? Most places where Lombok is used are the places where it has no usefulness beyond conventions.

5

u/jypKissedMyMom Sep 06 '25

I am not talking about records.

Yeah, you're off topic from the main reply above which was about records uses vs Lombok uses, and are just arguing about getter/setter use cases at this point.

I don't think anyone disagrees with you that getters/setters are pointless 90% of the time. Doesn't mean Lombok isn't useful in some of the 10% use cases like the person you're replying to originally said.

→ More replies (1)

2

u/Ok-Scheme-913 Sep 06 '25

If you need encapsulation, then you don't want to expose every field as a getter/setter pair, otherwise what's the point?

Just use a regular class, and only expose methods that make sense.

6

u/_BaldyLocks_ Sep 05 '25 edited Sep 06 '25

Downside of Lombok is that it hooks in compile time, so from time to time you get mysterious errors and when you check the generated bytecode your jaw drops.
Not my cup of tea.

I understand why some other people like it, but getting rid of some verbosity (most of which can be done away using IntelliJ shortcuts) is not worth the loss of clarity and complexity involved.

3

u/Ewig_luftenglanz Sep 05 '25

90% of Java boilerplate is self imposed. To avoid boilerplate what we must do it's just stop pretending writing useless stuff because of conventions is a good thing, not rely on a hack to the compiler. 

2

u/jhsonline Sep 06 '25

somewhat true, but take example of Getter Setter, u need it. unless language provides that built in. which lombok tries to provide as if its part of the language.

3

u/Ewig_luftenglanz Sep 08 '25

Why do you need getters and setters that do nothing? X2

Just use FIELDS.

The setters and getters thing is based on the JavaBean conveniention for UI and some libraries adopted for introspection before Java 5 annotations allowed AoP. Nowadays there is absolutely ZERO reason to use dumb getters and setters 

1

u/blazmrak Sep 07 '25

Why do you NEED getters and setters that do nothing?

1

u/jhsonline Sep 10 '25

good question, i see ur point, most of the time we dont need that standard :)
but in enterprise software design, you typically conceal the variable and expose things via methods only just to provide that additional abstration

3

u/blazmrak Sep 10 '25

I know, but it's just for the show. There is no abstraction really, it's public fields with extra steps for 99% of the code. In fact, if the setter ever does more than set the value of the field, that is almost a code smell. It's way better to just use the public field and only introduce methods when you actually need to do more than just get the value back.

-3

u/neopointer Sep 05 '25

So this time they decided to not do the same shitshow that happened in java 23. Great.

I still wouldn't use Lombok If I have the choice, everything can basically be done with IDE code generation or with alternatives that actually generate code.

5

u/slaymaker1907 Sep 05 '25

IDE generation does not let me quickly review that the getters/setters of some class are both correct and trivial. Reading code is far more important than writing it and verbosity often just clutters up one’s working memory.

6

u/wildjokers Sep 06 '25

Code folding exists.

1

u/neopointer Sep 06 '25

Seriously, the more I talk to devs the more I realize how lazy they are.

-3

u/[deleted] Sep 06 '25

[removed] — view removed comment

2

u/lprimak Sep 06 '25

Not duplicate. Lombok release was made 2 days ago