Quick revision
The short answer
I would neither ban nor freely encourage them; I would restrict them to an approved list with clear rules. Processors that only generate new source files, such as MapStruct and Immutables, are transparent and safe to encourage. Lombok is different: it changes the compiler's syntax tree through internal javac APIs, so it can break on new JDK versions, and records now cover most of its use for data carriers. Approved processors must be pinned, upgraded before each JDK upgrade, configured the same in IDE and build, and the policy should be revisited with evidence from our own JDK upgrades.
What to remember
In this answer, we saw that annotation processors come in two kinds: source generators such as MapStruct and Immutables, which use the official API and are transparent, and Lombok, which modifies javac's internal syntax tree and so carries more JDK upgrade risk. Records and pattern matching have removed much of Lombok's value for data carriers. A platform should restrict processors to an approved list, pin and upgrade them before JDK upgrades, keep IDE and build consistent, and revisit the policy with evidence from its own upgrades.
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.
I would neither ban nor freely encourage them; I would restrict them to an approved list with clear rules. Processors that only generate new source files, such as MapStruct and Immutables, are transparent and safe to encourage. Lombok is different: it changes the compiler's syntax tree through internal javac APIs, so it can break on new JDK versions, and records now cover most of its use for data carriers. Approved processors must be pinned, upgraded before each JDK upgrade, configured the same in IDE and build, and the policy should be revisited with evidence from our own JDK upgrades.
Why this question is asked
Annotation processors are among the most effective productivity tools in Java: a few annotations replace hundreds of lines of boilerplate. They are also hidden parts of the compiler, and when a JDK upgrade stalls, they are often the reason. A platform team has to decide what its standard says about them, and interviewers ask this to see whether a senior engineer can make a nuanced rule rather than a blanket one. In this answer, we will look at how annotation processing works, why MapStruct and Lombok carry very different risks, what records changed, and what a sensible policy and its enforcement look like.
1A Quick Recap of Annotation Processing
An annotation processor is a plugin for the Java compiler. While javac compiles our code, it finds annotations, hands the annotated elements to registered processors, and lets them act. The official API, javax.annotation.processing, allows a processor to read the code's structure and to write new files: new source files, which javac then compiles in another round, or resources. It does not allow a processor to change the classes it is reading.
That rule is what makes standard processors predictable. The code we wrote is compiled exactly as written, and the generated code is ordinary Java in a separate file that we can open, read and step through in a debugger.
2Source Generators Versus AST Modification
MapStruct and Immutables follow the official rules. MapStruct reads a mapper interface and writes OrderMapperImpl.java; Immutables reads an abstract value type and writes ImmutableOrder.java. If we delete the processor, the generated files disappear and the code that uses them stops compiling, which is a clear, honest failure.
Lombok works differently. To add getters, constructors and builders into the class we are compiling, it reaches into javac's internal abstract syntax tree, the tree of nodes the compiler builds from our source, and modifies it using non-public compiler classes. That is why it can do things the official API forbids, and also why it depends on implementation details of each JDK release. New JDK versions have repeatedly needed a new Lombok release before projects could compile, and the generated methods do not exist in any source file, so debuggers and some tools see code that is not there.
| Aspect | MapStruct, Immutables | Lombok |
|---|---|---|
| How it works | writes new .java files via the official API | edits javac's internal syntax tree |
| JDK upgrade risk | low, standard API | higher, needs a release per JDK |
| Generated code visible | yes, in generated-sources | no, only after delombok |
| Debuggable | yes, breakpoints in generated file | partly, lines map to annotations |
| Removal | replace generated class | delombok, then edit |
3What Records and Pattern Matching Changed
A large part of Lombok's popularity came from data carriers: classes that hold a few fields with getters, equals, hashCode and toString. Since Java 16, records give us exactly that from the language itself.
Records do not cover everything Lombok does. JPA entities cannot be records, builders for types with many optional fields are still convenient, and @Slf4j saves a line in every class. But pattern matching over records and sealed types (Java 21) further reduces the need for hand-made value classes. So the remaining value of Lombok is real but smaller than it was in 2015, while its upgrade risk is unchanged.
4The Policy: An Approved List With Rules
Given that, a ban would throw away real productivity, and free use would let every team add processors that may block the next JDK upgrade for the whole company. The sensible middle is an approved list. MapStruct and Immutables are approved and encouraged where they fit. Lombok is approved for a limited set of features, for example @Getter, @Builder and @Slf4j, with records preferred for new data carriers and experimental features not allowed.
Each approved processor has rules. Its version is pinned in the platform BOM and upgraded by the platform team. Before any JDK upgrade, the platform verifies that every approved processor has a compatible release, and upgrades them first; this is part of the JDK upgrade checklist, not a surprise during it. Processors are declared explicitly in annotationProcessorPaths or the Gradle annotationProcessor configuration, not picked up from the classpath, which matters because recent JDKs no longer run classpath-discovered processors by default (check your JDK's javac notes).
- Team proposes a processorwhat boilerplate it removes
- Uses only the official API?YesLower risk, review normallyNoNeeds strong evidence of value
- Works the same in IDE and build?IntelliJ, Eclipse, Maven, Gradle
- Pin version in platform BOMowner named
- Add to JDK upgrade checklistverified before each JDK release
5 steps in order. Play them, or step through them one at a time.
A processor is part of the compiler, so it gets the same care as a JDK upgrade.
5Consistency, Debugging and Evidence
Two practical rules prevent most day-to-day pain. First, the IDE and the build must behave the same: the IDE must run the same processors with the same options, or developers see errors the build does not, or worse, the reverse. The platform's project template should configure this so no developer has to. Second, generated code must be debuggable and inspectable. For source generators this is automatic; for Lombok, teams should know that delombok exists to show and, if needed, permanently replace the generated code.
Finally, the policy should rest on our own evidence. For each JDK upgrade we record what blocked or delayed it. If, over two upgrades, Lombok caused a week of delay across 200 services while saving a measurable amount of code, that is a trade-off leadership can judge. If it caused nothing, the restriction can relax. A standard that is revisited with data is far easier for teams to accept than one based on opinion.
6Follow-up questions
Would you remove Lombok from existing services?
Not as a big project. I would stop using it for new data carriers in favour of records, and replace it opportunistically when classes change. If it ever blocked a JDK upgrade that we needed, delombok gives a mechanical way out, and an automated refactoring can convert simple @Value classes to records.
Do annotation processors slow down builds?
A little, and mostly on full builds. MapStruct and Immutables add a processing round, and incremental compilation in Gradle supports well-behaved processors. Compared with test time, the cost is usually small, but a processor that is not incremental can make every build a full rebuild, which is worth checking before approval.
How is MapStruct affected by a JDK upgrade?
Very little, because it uses the official processing API and generates normal source. It may need an update to understand new language features, such as when records first appeared, but existing code usually compiles unchanged on a new JDK.
7Conclusion
In this answer, we saw that annotation processors come in two kinds: source generators such as MapStruct and Immutables, which use the official API and are transparent, and Lombok, which modifies javac's internal syntax tree and so carries more JDK upgrade risk. Records and pattern matching have removed much of Lombok's value for data carriers. A platform should restrict processors to an approved list, pin and upgrade them before JDK upgrades, keep IDE and build consistent, and revisit the policy with evidence from its own upgrades.
Open with
I would restrict them to an approved list rather than ban or freely encourage them, because they are not all the same. Processors like MapStruct and Immutables use the official annotation processing API: they only generate new source files, which I can read and debug, and they rarely cause trouble on JDK upgrades.
Then, if they want more
Lombok works by modifying javac's internal syntax tree through non-public APIs, so it can break on a new JDK until a new Lombok release arrives, and its generated methods do not exist in any source file.
At the same time, records since Java 16, and pattern matching with sealed types, cover most of what Lombok was used for with data carriers. So my standard would encourage MapStruct where mapping is mechanical, prefer records for new value types, and allow a limited set of Lombok features, like Getter, Builder and Slf4j, especially for JPA entities.
Every approved processor gets pinned in the platform BOM, has an owner, and is upgraded before each JDK upgrade as part of the checklist. Processors are declared explicitly in the build, and the project template makes the IDE behave the same as the build.
And I would review the policy with real data: what processors cost us in the last two JDK upgrades against the code they save.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 16, Java 21
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
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 "Teams increasingly generate code with annotation processors (Lombok, MapStruct...": https://scrivio-interview-library.netlify.app/java/utility-libraries/c390c578ca/