Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

After upgrading to a new JDK, the build fails with errors like 'java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment'. What is going on and how do you handle it?

Lombok works by calling internal javac classes in the jdk.compiler module, which are not exported, and newer JDKs both enforce that encapsulation strictly and change those internals. An older Lombok version therefore fails on a new JDK with IllegalAccessError or similar errors. The fix is to upgrade Lombok to a release that supports the new JDK and keep the version in annotationProcessorPaths aligned with the dependency; longer term, we make Lombok part of the JDK upgrade checklist, test early-access JDKs in CI, keep delombok as an exit route, and avoid --add-opens workarounds as a permanent solution.

Why this question is asked

JDK upgrades are supposed to be routine, and for most libraries they are. Lombok is different because it reaches into the compiler itself. This error message, with its long class names, is one many teams saw when they moved past JDK 16, and similar errors have appeared with later versions. Interviewers ask it to check whether we understand why the error happens, not just which version to bump. In this answer, we will recap the module system's strong encapsulation, read the error closely, see why Lombok depends on those internals, fix it properly, and look at how to keep future upgrades smooth.

1A Quick Recap of Strong Encapsulation

Since Java 9, the JDK is split into modules, and each module declares which packages it exports. Exported packages are public API; everything else is internal. For several releases, the JDK allowed code to reach internals anyway, with a warning. JDK 16 turned that off by default, and JDK 17 removed the switch that relaxed it, so access to non-exported packages now fails unless the JVM is started with an explicit --add-opens or --add-exports option.

The compiler, javac, lives in the module jdk.compiler. Its public API is in javax.tools and com.sun.source; the classes that actually implement compilation, in com.sun.tools.javac, are internal.

2Reading the Error

Let us read the full message the build prints.

Java
java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x3c5a99da)
cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler)
because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x3c5a99da

Each part tells us something. LombokProcessor is Lombok's annotation processor, running inside javac. It is in the unnamed module, which is where classpath code lives. It tried to use JavacProcessingEnvironment, an internal javac class, and the module system refused because jdk.compiler does not export that package. So the error is not a bug in our code and not a Maven problem; it is an old Lombok version that does not know how to get access on this JDK.

Later JDKs produced different-looking failures for the same reason. For example, moving to JDK 21 with a Lombok older than 1.18.30 failed with a NoSuchFieldError about a field of JCTree$JCImport, because an internal compiler class had changed shape. The pattern is the same: a new JDK, an old Lombok, internal classes that moved.

3Why Lombok Needs Compiler Internals

The standard annotation processing API lets a processor read code and generate new source files, but not change existing classes. Lombok's whole purpose is to add methods to the class we wrote, so it uses javac's internal classes to get at the syntax tree and modify it. Newer Lombok releases contain code to open the packages they need on each supported JDK and to handle internal classes whose structure changed. An older release simply does not have that code for a JDK released after it.

Step throughCompiling with an old Lombok on a new JDK
MavenjavacLombokProcessorjdk.compiler internals
compile with processor path
init(processingEnv)
use JavacProcessingEnvironment
IllegalAccessError: package not exported
processor fails
BUILD FAILURE

6 messages in order. Play them, or step through them one at a time.

The failure happens before any of our code is compiled.

4The Fix: Upgrade Lombok, and Keep the Versions Aligned

We upgrade Lombok to a release whose changelog lists support for our JDK. The changelog is the source of truth; for example, support for JDK 16 came in 1.18.20 and for JDK 21 in 1.18.30. Check it for your exact JDK.

The common trap is upgrading in one place only. If the pom's dependency says the new version but annotationProcessorPaths still names the old one, javac runs the old processor and the error stays. Using one property for both places avoids that.

XML
<properties>
<lombok.version>1.18.x</lombok.version> <!-- one property, a version that supports the new JDK -->
</properties>
<!-- dependency: <version>${lombok.version}</version> -->
<!-- annotationProcessorPaths: <version>${lombok.version}</version> -->
mvn -q dependency:tree -Dincludes=org.projectlombok # confirm which version is used
mvn help:effective-pom | grep -A3 annotationProcessorPaths # confirm the processor version

If a parent pom or Spring Boot's dependency management sets the version, we override the managed property rather than hard-coding a second version. After the upgrade, a clean build (mvn clean verify) makes sure no stale classes hide the result.

5Why --add-opens Is Not the Answer

It is possible to make an old Lombok work by passing options to the compiler's JVM, for example -J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED for each internal package it touches. This can be a short bridge for a day while a release is pending. As a permanent fix it is fragile: the list of packages grows with every JDK, it does nothing for internal classes that changed shape, it must be repeated in every build and IDE configuration, and it hides the real problem, an unsupported Lombok version, until the next upgrade breaks harder.

6Making Future JDK Upgrades Smooth

Because this will happen again, we turn it into process. The JDK upgrade checklist has a line for Lombok and for any other tool that uses compiler or JVM internals, such as bytecode libraries and agents. A CI job builds the main projects against the next JDK, including early-access builds, a few months before release, so we see the break before we need the upgrade. And we keep an exit route: delombok can turn the code into plain Java if Lombok ever stops keeping up, and we check once a year that it still produces code that compiles.

Step throughJDK upgrade routine with Lombok
  1. Read Lombok changelogis the target JDK supported?
  2. Upgrade the shared lombok.versiondependency and processor path together
  3. Build on the new JDK in CIearly-access builds ahead of release
  4. Build failed in Lombok?
    YesWait for a release or raise an issueNoRoll out the JDK upgrade
  5. Keep delombok workingthe exit route, checked yearly

5 steps in order. Play them, or step through them one at a time.

7Follow-up questions

Why does the IDE still work when the build fails?

IntelliJ IDEA uses its bundled Lombok plugin for the editor and may compile with a different JDK or Lombok version from the command line. The two environments only agree when both use the same JDK and the build's Lombok version.

Is Lombok likely to stop supporting new JDKs?

Its record has been to support new JDKs quickly, often around release day, but it depends on volunteer maintainers and on internals the JDK team does not promise to keep. That is a known risk, which is why the exit route via delombok is worth keeping.

Could we pin an older JDK instead?

For a short time, yes, using the toolchain feature in Maven or Gradle to compile with the older JDK. But it delays security and performance improvements, so it should be a stopgap while the Lombok upgrade is tested.

8Conclusion

In this answer, we saw that the IllegalAccessError comes from an old Lombok processor trying to use javac's internal classes, which newer JDKs strongly encapsulate and keep changing. The fix is upgrading Lombok to a release that supports the JDK and aligning the version in the dependency and in annotationProcessorPaths, not adding --add-opens flags. We also made Lombok part of the JDK upgrade checklist, tested early-access JDKs in CI, and kept delombok as a way out.

What to say in the interviewAbout 80 seconds aloud

Open with

The message says that LombokProcessor, running from the unnamed module, cannot access JavacProcessingEnvironment because jdk.compiler does not export that package. Lombok works by modifying javac's syntax tree through internal classes in com.sun.tools.javac, which are not public API.

Then, if they want more

Since JDK 16, and strictly since 17, the module system blocks access to non-exported packages, and the internals themselves also change between releases. Newer Lombok versions contain code to get that access and handle the changed classes for each JDK they support, so an older Lombok fails on a newer JDK, and this message is the classic symptom.

I would check the Lombok changelog for the version that supports our JDK, for example 1.18.20 for JDK 16 or 1.18.30 for JDK 21, and upgrade. The trap is upgrading only the dependency while annotationProcessorPaths still pins the old version, so I use one lombok.version property for both and verify with the effective pom.

I would not make --add-opens compiler flags permanent; they grow with each JDK, do not help when classes change shape, and hide the real problem. Longer term, Lombok goes on the JDK upgrade checklist, CI builds against the next and early-access JDKs, and we keep delombok working as an exit route in case Lombok ever stops keeping up.

About this answer

Last updated
12 November 2026
Versions it names
Java 16, Java 21, Java 17, Java 9
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 "After upgrading to a new JDK, the build fails with errors like...": https://scrivio-interview-library.netlify.app/java/lombok/609b9f4fb0/