28

Upgrading to the last Eclipse version, now I am getting the following error:

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 @5d01b0d8

I tried changing JDK under preferences with no luck.

devwebcl
  • 2,866
  • 3
  • 27
  • 46
  • 4
    If you are using Lombok, it's probably this issue: https://twitter.com/howlger/status/1407316561803763716 (changing the JDK under preferences, does not change the Java used to run Eclipse). Or a similar issue of a plugin you have installed. – howlger Jun 24 '21 at 17:47

6 Answers6

41

Thanks, @howlger it was Lombok plug-in when using JDK 16. That tweet gave me the reasons: https://github.com/projectlombok/lombok/issues/2810

A workaround :

  • Use Java 15 to start Eclipse or
  • add --illegal-access=warn and --add-opens=java.base/java.lang=ALL-UNNAMED to your eclipse.ini
  • or install a pre-built version (1.18.21)

In my situation I had to change eclipse.ini VM path:

-vm
C:\bin\jdk-15.0.2\bin
Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84
devwebcl
  • 2,866
  • 3
  • 27
  • 46
3

An easy way is to change the Java Version used to run Eclipse. There for you have to change the eclipse.ini.

  1. Set the vm location at the start of the file to a prior Java 16 JDK e.g. JDK 14
  2. Under MacOSX eclipse.ini is typically located in /Applications/Eclipse.app/Contents/Eclipse/
  3. The reason is an incompatibility of the lombock plugin

This a working example of the eclipse.ini file:

-vm
/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home/bin/java
-startup
../Eclipse/plugins/org.eclipse.equinox.launcher_1.6.200.v20210416-2027.jar
--launcher.library
../Eclipse/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.2.200.v20210527-0259
-product
org.eclipse.epp.package.java.product
-showsplash
org.eclipse.epp.package.common
--launcher.defaultAction
openFile
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-javaagent:/Applications/Eclipse.app/Contents/Eclipse/lombok.jar
-Dosgi.requiredJavaVersion=11
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-Dsun.java.command=Eclipse
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dorg.eclipse.swt.internal.carbon.smallFonts
-Dosgi.dataAreaRequiresExplicitInit=true
-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true
-Xms256m
-Xmx2048m
-Xdock:icon=../Resources/Eclipse.icns
-XstartOnFirstThread
Mirko Ebert
  • 1,349
  • 1
  • 18
  • 36
  • There are some duplicate lines: `--add-modules=ALL-SYSTEM` `-XstartOnFirstThread` `-Dorg.eclipse.swt.internal.carbon.smallFonts` `-Dosgi.requiredJavaVersion=11` I suppose this is not on purpose? – WarpEnterprises Oct 14 '21 at 15:09
2

Latest version of lombok 1.18.22 has fixed this issue. Install this version of lombok into your eclipse. Then this issue will get resolved.

Jobin John
  • 21
  • 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 07:08
  • thanks, this fixed it for me on eclipse 2021-12/4.22 with java 17 – dan carter Jan 09 '22 at 22:24
  • 3
    no luck here using lombok 1.18.24 – Digao Jun 10 '22 at 19:39
  • I'm using 1.18.24 as well. As noted above, `--add-opens=java.base/java.lang=ALL-UNNAMED` did the trick. – Harry Developer Nov 04 '22 at 09:38
2

I had the same issue. I was using org.mockito.mockito-all as a test dependency in my project's pom. Moving to org.mockito.mockito-core as dependency resolved the issue. Reflection is no longer supported in JDK 17, so mockito-all (using reflection) is deprecated.

1

Changing the SpringToolSuite4.ini as below:

-vm
C:\Users\my-id-here\softwares\openjdk-11.0.2\jdk-11.0.2\bin

and replacing the lombok.jar with the latest download. It worked!

raikumardipak
  • 1,461
  • 2
  • 29
  • 49
0

If you are starting your application from cmd (command prompt) and via below command.

java -jar myapplication.jar 

and getting this error. Then add below in your command.

-Dsun.misc.URLClassPath.disableJarChecking=true --add-opens jdk.naming.rmi/com.sun.jndi.rmi.registry=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.security.action=ALL-UNNAMED --add-opens java.base/sun.net=ALL UNNAMED

Your command will looks like this.

java -Dsun.misc.URLClassPath.disableJarChecking=true --add-opens jdk.naming.rmi/com.sun.jndi.rmi.registry=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.security.action=ALL-UNNAMED --add-opens java.base/sun.net=ALL UNNAMED -jar myapplication.jar

Now you will not get this error.

Pirate
  • 2,886
  • 4
  • 24
  • 42