Lombok + Eclipse compiler problem: "java.lang.ClassFormatError: Extra bytes at the end of class file"

Answered

Hello,

in my current project, we use Lombok and the Eclipse compiler.

To get these two things compile together, we already had to modify a compiler setting "build process VM option": -javaagent:<somepath>\org\projectlombok\lombok\1.18.16\lombok-1.18.16.jar. See also: https://github.com/mplushnikov/lombok-intellij-plugin/issues/89

Thus we were able to compile our stuff.

But now, when trying to start tests or an application, we get the following error (see below).

I did some googling but wasn't able to find a solution, yet. I then had a look into the bytecode and it struck me, that the first, typical bytes "CA FE BA BE" were repeated at some point in the file. It seems that the class file contains the bytecode twice (see screenshot).

Any help is appreciated.

Thanks in advance,

Marc

 

>>>

java.lang.ClassFormatError: Extra bytes at the end of class file lomboktest/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"

<<<

 

 

5 comments
Comment actions Permalink

Hi. Annotation processors are normally loaded by javac from the classpath, not via agent API.
Please try asking Lombok authors to comment on the resulting bytecode.

0
Comment actions Permalink

Hello,

yes, with javac it's no problem. But the project has the restriction to use the Eclipse compiler and obviously, it uses lombok via the agent API (although I don't know why). See https://projectlombok.org/setup/ecj

I'm fearing it might be an integration issue between lombok (plugin) and the Eclipse compiler...

But I will try to get some help from the Lombok authors. Thanks for the hint.

Kind regards,

Marc

0
Comment actions Permalink

Hello Petr (again ;),

I did some further investigations and as it seems, lombok is not the cause for the problem.

I directly compiled my sample code via command line using the current lombok version 1.18.16 and a previous version 1.18.12. Both work fine.

Using the previous version of lombok (1.18.12), I also got the code to work in IDEA. But not with 1.18.16.

Thus, I think the problem is either in the IDEA lombok plugin or somehow in the integration of the plugin with IDEA. But I don't know enough there...

I did open an issue in the IDEA lombok plugin repo: https://github.com/mplushnikov/lombok-intellij-plugin/issues/969

Please feel free to have a look if you think it might be an integration issue with IDEA itself. The issue also contains my example IDEA project and the scripts for command line compilation.

Kind regards,

Marc

0
Comment actions Permalink

We will add a fix on our side to avoid such problems in a future. https://youtrack.jetbrains.com/issue/IDEA-254725

0

Please sign in to leave a comment.