Classformaterror: Incompatible Magic value 0 in class file

Asked

Viewed 660 times

2

My project was working normally. After restarting my machine, running it through the IDE returns the following:

Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value 0 in class file Principal$9
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at Principal.main(Principal.java:707)

Does anyone know why this error occurs?

2 answers

2


I updated the JDK version where you solved the problem.

  • 1

    What a bizarre mistake.

2

Incompatible Magic value happens when a class has been corrupted in some way (e.g., downloading some .class failed or the compiler / bytecode generator did something it shouldn’t). I’ve seen this happen a few times in Eclipse projects (which use an incremental compiler) and / or in projects with Javassist, ASM, etc.

The class starts with byte 0 (instead of CAFEBABE) usually implies that a download failed or the compiler did not do what it was supposed to and created a file .class emptiness.

Solving this type of problem usually involves clearing the class cache, checking the integrity of any class you’ve downloaded (e.g., comparing the checksum), clean and build the project again and review any part of the stack who is manipulating bytecode (compiler, tools that generate dynamic bytecode, etc).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.