java.lang.IllegalAccessError class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Before exploring the technical underpinnings of the java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment, it's crucial to understand the primary components involved and the typical scenarios where this error might arise. This article aims to provide a comprehensive understanding of this error and guide you on how to resolve it when encountered.
Understanding the Components
Lombok
Lombok is a popular Java library that offers annotations to reduce the boilerplate code frequently used in Java applications. It uses annotation processing at compile time to generate code, such as getters, setters, equals, hashcode, and other utility methods.
Javac Processing Environment
com.sun.tools.javac.processing.JavacProcessingEnvironment is a part of the Java Compiler (Javac) API, which provides tools for annotation processors to interact with and modify the data during the compilation process.
Error Explanation
The java.lang.IllegalAccessError occurs when there's an attempt to access or modify a class that is not accessible from the location trying to access it. In this specific error, the LombokProcessor lacks the necessary permissions to interact with JavacProcessingEnvironment.
Technical Explanation
This error typically arises due to:
- Module System Restrictions: With the introduction of Java's module system (Project Jigsaw) in Java 9, accessibility and encapsulation at the module level have been strictly enforced. If the module containing
JavacProcessingEnvironmentdoesn't export it, classes outside the module cannot access it. - Version Compatibility Issues: There may be an incompatibility between the versions of Java, Lombok, or other libraries used in the project, leading to accessibility issues during compilation.
- Class-loader Issues: Sometimes, different class-loaders might load the same class, causing conflicts that lead to
IllegalAccessError.
Resolution Steps
To resolve this error, follow the steps below:
Step 1: Validate Java and Lombok Version Compatibility
Ensure that the versions of Java and Lombok are compatible. Update both Java and Lombok to the latest versions if needed. Check the Lombok release notes and Java compatibility to confirm compatibility.
Step 2: Module Exports
If you're using Java 9 or above, you can modify the command-line options to allow access to internal APIs. Use --add-exports to make JavacProcessingEnvironment accessible:
Step 3: Check for Duplicate Libraries
Ensure there are no duplicate or conflicting versions of libraries in your project. Use a build tool like Maven or Gradle to manage dependencies effectively.
Step 4: Update Project Configuration
Ideally, update your IDE settings or build configuration to ensure that Lombok is correctly configured. Ensure annotation processing is enabled, and the correct Lombok plugin and dependencies are added.
Example Scenario
Consider a scenario where a project is running on JDK 11 and Lombok 1.18.2. Here's a potential setup in a Maven pom.xml:
To check if there are compatibility issues, update the Pom to the latest Lombok version, e.g.,:
Summary Table
| Issue | Possible Cause | Resolution |
IllegalAccessError | Module system restrictions | Use --add-exports option |
IllegalAccessError | Version compatibility | Update Java and Lombok versions |
IllegalAccessError | Duplicate libraries | Use Maven/Gradle to manage dependencies |
IllegalAccessError | Annotation processor misconfiguration | Correct Lombok setup in the project |
Additional Considerations
While combating the java.lang.IllegalAccessError, consider the larger context of your application:
- Maintain a consistent build environment: Use Docker or tools like SDKMAN! to ensure consistent Java environments across the team.
- Monitor Lombok changes and announcements: Address potential deprecations or changes in how lombok interacts with Java's native modules.
By addressing the factors outlined above, you can effectively deal with the java.lang.IllegalAccessError and ensure a smooth build process with Lombok and Java.

