Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Fatal error compiling: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor #3219

Open
bhawana99 opened this issue Jun 26, 2022 · 16 comments
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug javac

Comments

@bhawana99
Copy link

Issue during Java build using JDK 17 and Lombok 1.18.22:

Fatal error compiling: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x363d3958) 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 @0x363d395**

I am compiling my java source code in java 1.8, while running the project on JRE17. As per the other bug thread, I have upgraded the lombok version to 22 as it suports lombok reflection issue. But still we are getting this issue. What could be the possible issue.

  • 1.18.22 (lombok version of external library that is actually causing the issue)
  • java -version
    openjdk version "17-ea" 2021-09-14
    OpenJDK Runtime Environment (build 17-ea+23-2064)
    OpenJDK 64-Bit Server VM (build 17-ea+23-2064, mixed mode, sharing)

NOTE:
The problem causing library is an external library, in main project we are using lombok version 1.18.12.

@Rawi01
Copy link
Collaborator

Rawi01 commented Jun 26, 2022

The error message happenstance because java 17 enforces strong encapsulation. Lombok can handle that if you upgrade to 1.18.22+. Please double check that you really use that version for your build.

@bhawana99
Copy link
Author

@Rawi01 But doesn't the above issue is fixed in the 1.18.22 version?

@Rawi01
Copy link
Collaborator

Rawi01 commented Jun 27, 2022

Yes, it is fixed. That's why I'm pretty sure that you use an older version for your build.

@JulienElkaim
Copy link

Hello @bhawana99,

You are right they solved the issue, but I think it was only for "direct" dependency.
I just had a similar problem, using 1.18.24 and JDK 16, in a multi-module project.
Maybe yours is multi-module too? If yes, I solved the solution by making lombok non transitive ->

<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <optional>true</optional>
</dependency>

If you want to play with a project that has a solution:

  • git clone my project from the commit in this link, and try to mvn install from the root module bulo-project 1/ with the optional true, 2/ without it. in 2/ you will see runs-orchestrator module fail at compilation, and it has dependency to swagger-starter module which has dependency to lombok

Anyway, I am not sure to understand why the issue still exists when Lombok is an indirect dependency, I will investigate maybe it is an unsolved bug, or maybe it is expected?

@Rawi01
Copy link
Collaborator

Rawi01 commented Jul 2, 2022

@JulienElkaim Thanks for sharing the reproducer. The recommended scope for Lombok is provided because it is only required at runtime. I changed the scope and it works too. That actually explains why their is only a small subset of people who faces this problem because it requires a wrong configuration.

If you are unable to change the included dependency it is also possible to exclude the dependency using <exclusions>.

To be honest I have no idea why this happens and it is clearly not intended.

@Rawi01 Rawi01 added javac accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug labels Jul 2, 2022
@suorinz
Copy link

suorinz commented Apr 4, 2023

Hello @bhawana99,

You are right they solved the issue, but I think it was only for "direct" dependency. I just had a similar problem, using 1.18.24 and JDK 16, in a multi-module project. Maybe yours is multi-module too? If yes, I solved the solution by making lombok non transitive ->

<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <optional>true</optional>
</dependency>

If you want to play with a project that has a solution:

  • git clone my project from the commit in this link, and try to mvn install from the root module bulo-project 1/ with the optional true, 2/ without it. in 2/ you will see runs-orchestrator module fail at compilation, and it has dependency to swagger-starter module which has dependency to lombok

Anyway, I am not sure to understand why the issue still exists when Lombok is an indirect dependency, I will investigate maybe it is an unsolved bug, or maybe it is expected?

You, my friend, are brilliant

@duibu
Copy link

duibu commented Jul 19, 2023

@bhawana99 I also experienced this situation,Replacing jdk1.8 can solve the problem

@shahnawaz4automation
Copy link

Thank you @JulienElkaim. Adding the above dependency in my projects pom.xml solved the exception.

@vkrnt18
Copy link

vkrnt18 commented Aug 24, 2023

Hello @bhawana99,
You are right they solved the issue, but I think it was only for "direct" dependency. I just had a similar problem, using 1.18.24 and JDK 16, in a multi-module project. Maybe yours is multi-module too? If yes, I solved the solution by making lombok non transitive ->

<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <optional>true</optional>
</dependency>

If you want to play with a project that has a solution:

  • git clone my project from the commit in this link, and try to mvn install from the root module bulo-project 1/ with the optional true, 2/ without it. in 2/ you will see runs-orchestrator module fail at compilation, and it has dependency to swagger-starter module which has dependency to lombok

Anyway, I am not sure to understand why the issue still exists when Lombok is an indirect dependency, I will investigate maybe it is an unsolved bug, or maybe it is expected?

You, my friend, are brilliant

It worked for me. Gr8

cristinamghita added a commit to metasfresh/metasfresh that referenced this issue Nov 28, 2023
@marcosflobo
Copy link

I'm still having this issue

Execution failed for task ':compileJava'.
> java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x34ce9fe1) 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 @0x34ce9fe1
  • Java 17.0.2-tem
  • lombok 1.18.24

With Gradle

* What went wrong:
Execution failed for task ':compileJava'.
> java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x76c7b88e) 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 @0x76c7b88e

@rspilker
Copy link
Collaborator

Please update you Lombok first, we did do some changes regarding the packaging of the embedded ASM.

@marcosflobo
Copy link

I've tried with the latest too 1.18.30

@rspilker
Copy link
Collaborator

rspilker commented Dec 2, 2023

In Java 17 we try to automatically take care of all the necessary add-opens problems. In Java 22, this no loners works. Could it be that you're accidentally using Java 22.

In any case, in the repo you can find all the necessary add-open statements in the docker directory.

@rspilker
Copy link
Collaborator

rspilker commented Dec 2, 2023

FYI: for Java 22 and up we will use a different solution.

@zeimao77
Copy link

May I ask if the new version of lombok (>=JDK17) no longer relies on the jdk.compiler module for implementation? If you don't use JDK. compiler, what AST editing technique did you use?

@anirban-debnath-sophos
Copy link

anirban-debnath-sophos commented Apr 5, 2024

Resolved by adding the following in sourceset.gradle

 lombokVersion = '1.18.30' 
annotationProcessor "org.projectlombok:lombok:${lombokVersion}" 
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug javac
Projects
None yet
Development

No branches or pull requests