18

Getting the following error, after adding Lombok lib

An error has occurred. See error log for more details.
Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @1d1c37d5
Thirumal
  • 8,280
  • 11
  • 53
  • 103
  • 2
    You tagged your question with both, `[java-17]` and `[eclipse-2021-09]`. Since Eclipse 2021-09 does not support Java 17, I guess you have installed [_Java 17 Support for Eclipse 2021-09 (4.21)_](https://marketplace.eclipse.org/content/java-17-support-eclipse-2021-09-421) which is the preview/BETA of the upcoming Java 17 support that will be released with Eclipse 2021-12 (4.22) on December 15, 2021. Please make sure [this issue has been reported to Eclipse](https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT) with a minimal reproducible example and the error log. – howlger Sep 17 '21 at 06:57
  • 3
    JDK 17 doesn’t support `--illegal-access=permit` anymore. It’s not is if the previous versions weren’t warning about this kind of access… – Holger Sep 17 '21 at 10:51
  • In my case, I had to change eclipse.ini VM path: -vm C:\bin\jdk-11.0.18\bin as suggested by https://stackoverflow.com/a/68134496/8374909 – Clover May 19 '23 at 12:29

8 Answers8

28

Updating to Lombok 1.18.22 plugin resulted in this issue going away for me. I did try adding the --add-opens flag, but the eclipse launcher balked at that. IMHO this is simply a result of incompatibility between Java 17 and the Lombok Eclipse IDE plugin.

Tod Harter
  • 516
  • 5
  • 8
17

Add the below lines to the end of the eclipse.ini file

--illegal-access=warn
--add-opens java.base/java.lang=ALL-UNNAMED
Thirumal
  • 8,280
  • 11
  • 53
  • 103
  • 5
    Since your question is specifically mentioning Java 17, there is no point in specifying `--illegal-access=warn`, it is not supported and will be ignored. – Holger Sep 17 '21 at 17:53
  • But it’s working on Java 17, I did adding Lombok lib, after that I got the problem. Same problem I faced with 2021-06 in Java 15 – Thirumal Sep 18 '21 at 00:49
  • @Thirumal Your question seems to be about running your code and your answer seems to be about running Java. It's unclear whether you installed the preview Java 17 support and whether you use a Java 17 VM to run Eclipse. Please improve or delete your question. – howlger Sep 18 '21 at 09:47
  • 1
    **Thank you!** This solved my issue when trying to run Eclipse 2021-09 (with lombok) on macOS with JDK 17 installed. Without this fix Eclipse will indeed start and run, but every imported Maven Project is broken and gives the error from the question. I spent literally a whole day with reinstalling different Eclipse versions, reimporting the projects, choosing different JDKs within Eclipse, with and without lombok, etc... Nothing worked. But adding those 2 lines to `eclipse.ini` solved it. – Benjamin M Sep 18 '21 at 10:49
  • @BenjaminM So it's a Lombok thing? I cannot find a [Lombok issue](https://github.com/projectlombok/lombok/issues). How to reproduce this issue (with which Java version running Eclipse and with which Lombok version)? With or without _Java 17 Support for Eclipse 2021-09 (4.21)_ installed? – howlger Sep 19 '21 at 10:52
  • 3
    @Thirumal did you crosscheck? When your computer works after you connected the power plug and painted it green, does it prove that painting it green solved the problem? How about adding the `--add-opens java.base/java.lang=ALL-UNNAMED` option *without* the `--illegal-access=warn` that has no effect? – Holger Sep 20 '21 at 07:59
  • @Holger, I don't know why or how it worked, I just copied these lines from the Github eclipse repository issue. To recreate the issue-> Install eclipse -> import gradle/maven project -> Install Lombok -> restart eclipse. You will get an error. – Thirumal Sep 20 '21 at 08:42
  • 5
    “I just copied these lines”—a very good summarization of why we are flooded with horrible software. Even now, after I told you explicitly that these are **two** independent options and only one of them has an effect in JDK 17, you refuse to even try to understand. Yes, without green color and the cable removed, the computer doesn’t work, but with cable plugged in and a green painting, the computer works. Now, you only have to understand that this does not imply that green painting was necessary. Or just execute `jdk-17\bin\java --illegal-access=warn x` in cmd and note the warning message. – Holger Sep 20 '21 at 09:54
  • @howlger I'm not sure if it's a Lombok issue. I did not get an error when importing a fresh Spring Boot application, but when importing my projects from work (all using Spring Boot 2.5.4 with lot's of different dependencies: Hibernate, Jackson, Elasticsearch, MongoDB, MySQL, Freemarker, etc.). My machine is running Eclipse 2021-09 (4.21.0), Lombok 1.18.20, macOS 11.6, OpenJDK 17 (2021-09-14 LTS). – Benjamin M Sep 20 '21 at 19:24
  • @BenjaminM With which Java version do you run Eclipse? Java 17 that is installed on your system or Java 16 that is included in Eclipse? Please tell, in `eclipse.ini` what is the line after `-vm`. Please check also if there is something in the error log. This would at least be hints on how to produce the issue. – howlger Sep 20 '21 at 20:49
  • Adding those two lines to my ini caused Eclipse to now even being able to start any more. It instantly says `Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.` – Panossa Mar 13 '23 at 09:10
7

The only thing that worked for me was downloading the lombok directly from lombok website instead of using the one available on maven folder.

Gledson
  • 71
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 20 '21 at 19:20
2

In my case, I solved changing java version from 16 top 11.
Adding this line:
--illegal-access=warn
--add-opens java.base/java.lang=ALL-UNNAMED

in my case, eclipse is not enable to start. Version: 2021-03 (4.19.0) Build id: 20210312-0638

jackarian
  • 21
  • 1
  • Answer could be explained to help future readers. Why does adding this line help resolve the issue? – Vishnu Dasu Sep 08 '22 at 14:35
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 08 '22 at 14:35
0

Itseems problem with the lombok plugin. I have removed it from the eclipse.ini file and it resolved the issue.

Removed below line:

-javaagent:C:\<location>\eclipse-jee-2022-03-R-win32-x86_64\lombok.jar
Sreedhar GS
  • 2,694
  • 1
  • 24
  • 26
0

For my case nothing above work for a specific project.

  1. Import existing maven project or create a maven project
  2. Goto project explorer and Right click on your pom.xm then select Run As maven install.
  3. and then what you want.

Hope it will serve your purpose. You can download a sample spring boot project from sample spring boot project

Or you can run a maven project from terminal or cmd. Just goto project root folder and then run a maven task like maven clean install . Happy Coding :)

Basharat Ali
  • 1,099
  • 9
  • 11
0

I was also facing same issue after configured lombok in STS 4.17.2.RELEASE.

I have removed below properties from ini file.

--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.base/java.net=ALL-UNNAMED
--add-opens=java.base/sun.security.ssl=ALL-UNNAMED
-Dsun.java.command=SpringToolSuite4

I have tried many solutions but not worked. So, I have compared with my older sts version.

Honestly, I don't know actual reason.

0

you would need to check which java exe your IDE is pointing to in the .ini file. In other words, Just point your eclipse.ini to the right java.exe folder then the error goes away. This works for me in Spring STS and "may be" this same remedy will work in Eclipse too.