Eclipse 2021-06: ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module

Viewed 22913

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.

4 Answers

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

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

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.

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!

Related