Search code examples
javaeclipsedecompiler

.Jar File Has Compile Errors When Decompiled But Works Properly


I downloaded an executable .jar file and used the Java Decompiler to extract the sources. I imported them into Eclipse it shows me a few compile errors such as wrong types or calls to invisible methods. I therefore can't run the project without fixing everything.

How is it possible for the .jar file to function properly even though the decompiler clearly shows that there are logical errors? Does it have to do with the compiler level being older (I use 1.8 while it originally has been compiled using 1.6 or 1.7)? Isn't compatibility kept though? Did the decompiler make mistakes?


Solution

  • How is it possible for the .jar file to function properly even though the decompiler clearly shows that there are logical errors?

    The compiled classes in the .jar file are composed of bytecode, not Java source. There is no single transform from bytecode back into Java code. The bytecode may be well-formed, but different decompilers may produce different results, and the results will not always be valid.

    Did the decompiler make mistakes?

    Probably. It happens. Having written a Java decompiler, I can tell you it is anything but straightforward.