Quick revision
The short answer
Lombok is not a normal annotation processor: it edits the class being compiled through internal javac APIs, so every JDK release can break it until a new Lombok version ships. We manage the risk by measuring which Lombok features our 300 services really use, pinning and testing Lombok centrally, banning the risky features, replacing value classes with records, and only then deciding which modules to delombok. We would change course gradually, not with a big-bang removal.
What to remember
In this answer, we saw that Lombok breaks on new JDKs because it edits javac's internal syntax tree, while standard processors such as MapStruct and Immutables only add new files, and records now cover many value classes. We measured the exposure with import counts, then went through the options: waiting before upgrading with a canary build, limiting features with lombok.config, moving value types to records, and delomboking the shared libraries first. The course change is real but gradual, driven by the numbers.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Lombok is not a normal annotation processor: it edits the class being compiled through internal javac APIs, so every JDK release can break it until a new Lombok version ships. We manage the risk by measuring which Lombok features our 300 services really use, pinning and testing Lombok centrally, banning the risky features, replacing value classes with records, and only then deciding which modules to delombok. We would change course gradually, not with a big-bang removal.
Why this question is asked
Lombok saves a lot of typing, which is why it spreads quickly through a large codebase. The trouble starts on the day a new JDK is released and the build fails for every service at once, because the compiler that Lombok hooks into has changed. Interviewers ask this scenario at senior level because it tests whether we can turn a vague worry into numbers and a plan, and whether we understand why one library is fragile while others are not. In this answer, we will recap how Lombok differs from standard annotation processors, measure how exposed the platform is, go through the options from cheapest to most thorough, and then decide whether to change course.
1A Quick Recap: Why Lombok Breaks on New JDKs
An annotation processor is a plugin that the Java compiler, javac, runs during compilation. The standard API for it (JSR 269, the javax.annotation.processing package) lets a processor read the program's structure and create new files: new source files, class files or resources. It does not let a processor change a class that already exists.
Lombok goes further than that contract allows. When it sees @Getter on a class, it does not write a new file. It reaches into javac's internal syntax tree, the in-memory representation of our source code, and adds getter methods to the class directly. To do that it uses classes from com.sun.tools.javac, which are internal to the JDK and can change in any release. Since strong encapsulation arrived in JDK 16 and 17, Lombok also has to work around module boundaries to reach those internals.
So each new JDK can rename or reshape something Lombok depends on. Usually the Lombok team ships a fix within days or weeks, but until then any service that compiles with the new JDK and Lombok fails. Notice that the risk is in compilation, not at run time: Lombok leaves nothing behind in the running application except the code it generated.
2Comparing Lombok With Standard Processors
MapStruct reads a mapper interface and writes a new class that implements it. Immutables reads an abstract value type and writes a new ImmutableX class. Neither touches our source, and both use only the public processing API, so a new JDK rarely breaks them. Records, added in Java 16, remove the need for many value classes in the first place, because the language now generates the constructor, accessors, equals, hashCode and toString.
| Approach | How it generates code | JDK upgrade risk |
|---|---|---|
| Lombok | Edits javac's internal syntax tree | High: may break until a new release |
| MapStruct | Writes new implementation classes | Low: public processing API only |
| Immutables | Writes new ImmutableX classes | Low: public processing API only |
| Records | Part of the language itself | None: the compiler owns it |
The table makes the point of the whole answer: the problem is not code generation, it is code generation through internal APIs.
3Measuring the Exposure Before Deciding Anything
Before we choose a plan we need to know what we are dealing with. Three hundred services may use Lombok in very different ways. If ninety percent of the usage is @Getter, @RequiredArgsConstructor and @Slf4j, the problem is small and mechanical. If many services use experimental features such as @ExtensionMethod or val, it is much bigger. A short script run across all repositories gives us the real picture.
We also record which services are shared libraries, because a broken build there blocks every team that depends on them.
4Option 1: Wait Before Upgrading the JDK
The cheapest option is to accept the delay. We pin one Lombok version in the platform's dependency bill of materials (BOM), the shared file that fixes library versions for every service, and we upgrade the JDK for the fleet only after Lombok officially supports it. This usually costs little, because production services move between LTS releases, such as Java 21 to Java 25, and Lombok support normally arrives long before we are ready to move.
We make the wait visible rather than accidental. A canary pipeline builds a few representative services against early-access JDK builds every week, so we learn about a break months before the release instead of on the day. But there is a catch: waiting only works while the breakage stays short. If Lombok ever lagged for months, or a security fix forced a fast JDK upgrade, we would want an exit already prepared.
5Option 2: Limit the Features We Allow
Lombok has a configuration file, lombok.config, that can turn any feature into a compile error. Placed at the root of each repository (or generated by our build plugin), it freezes the feature set so that the exposure stops growing while we work on it.
The features we forbid first are the ones that change Java's meaning or are hardest to remove later. Experimental features may change between Lombok versions. val and var invent language syntax. @SneakyThrows throws checked exceptions without declaring them, which surprises callers. The everyday features, @Getter, @RequiredArgsConstructor and @Slf4j, stay allowed because delombok turns them into plain code with no change in behaviour.
6Option 3: Records, Standard Processors and Delombok
For value classes, records are the natural replacement for @Value and many uses of @Data. The generated accessor is currency() instead of getCurrency(), so callers change, but Jackson and Spring both support records, and the compiler now guarantees what Lombok used to generate.
Builders can move to a small hand-written builder or to a standard processor that generates one. For our most critical modules, the shared libraries, we can run delombok, a tool shipped with Lombok that writes out the plain Java code Lombok would have generated. The command java -jar lombok.jar delombok src/main/java -d build/delombok produces sources we can review and commit. After that the module no longer needs Lombok at all, and a JDK release cannot break it.
7Would We Change Course?
Yes, but slowly and in the cheapest order. A full removal across 300 services in one quarter would cost weeks of engineering time for little benefit, since most usage is the harmless getter kind. The senior choice is to stop the exposure growing, remove it where a break hurts the most, and let normal work shrink the rest.
In practice we freeze the feature set this month, delombok the shared libraries first, write new value types as records, and review the import counts every quarter. If the numbers fall the way we expect, a later JDK upgrade becomes a non-event, and if Lombok ever falls far behind, the remaining services only use features that delombok handles mechanically.
- Is it a shared library?YesDelombok it nowNoKeep Lombok for now
- Does it use forbidden features?YesReplace them firstNoLeave it as is
- Write new value types as recordsno new
@Valueor@Data - Re-measure every quarterimport counts per feature
4 steps in order. Play them, or step through them one at a time.
8Follow-up questions
Which Lombok features would you forbid first and why?
The experimental package first, because those features can change or disappear between Lombok versions and they reach deepest into the compiler. Then val and var, which add syntax Java does not have, and @SneakyThrows, which hides checked exceptions from callers. I would also discourage @Data on JPA entities, because its generated equals and hashCode use every field, which breaks with lazy loading and generated ids. I keep @Getter, @RequiredArgsConstructor and @Slf4j, because they are easy to delombok and do not change Java semantics.
Why not simply delombok everything at once?
Delombok produces correct but verbose code, and committing it in 300 services means huge diffs, merge conflicts with ongoing work, and review time for code nobody wrote by hand. The benefit only appears on the rare day a JDK release breaks Lombok. Doing it first for shared libraries gets most of the benefit for a fraction of the cost.
9Conclusion
In this answer, we saw that Lombok breaks on new JDKs because it edits javac's internal syntax tree, while standard processors such as MapStruct and Immutables only add new files, and records now cover many value classes. We measured the exposure with import counts, then went through the options: waiting before upgrading with a canary build, limiting features with lombok.config, moving value types to records, and delomboking the shared libraries first. The course change is real but gradual, driven by the numbers.
Open with
Lombok is fragile on JDK upgrades for a specific reason: it does not follow the standard annotation processing contract. Instead of generating new files, it modifies javac's internal syntax tree using internal com.sun.tools.javac APIs, so any JDK release can break it until Lombok ships a fix.
Then, if they want more
Processors like MapStruct or Immutables only generate new files through the public API, so they are rarely affected. First I would measure: count every Lombok import across the 300 services, per feature, and mark which ones are shared libraries. Usually most usage is getters, constructors and loggers, which are low risk. Then I would act in order of cost.
We pin Lombok in the platform BOM, upgrade the fleet JDK only after Lombok supports it, and run a weekly canary build on early-access JDKs so we hear about breaks early. We freeze the feature set with lombok.config, forbidding experimental features, val and SneakyThrows. New value types become records, which replace most uses of Value and Data.
Shared libraries get delomboked first, because a broken library blocks everyone. So yes, I would change course, but gradually and measured every quarter, not with a big-bang removal.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 16, Java 21, Java 25
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your platform relies on Lombok across 300 services. A new JDK release breaks Lombok for...": https://scrivio-interview-library.netlify.app/java/annotations/aa47593ce1/