Search code examples
javabytecodedecompiler

If all the bytecode which compiled from java sources can be decompiled to java sources?


I see some java decompilers can decompile bytecode to readable java sources, I wonder if all the bytecode which comes from java (not other JVM language) can be decompiled to java sources again?


Update

Sorry, let me make the question more clear.

Just talk about the normal Java code on JVM (no Android, no bytecode enhance, no AOP, no obfuscation), and I actually hope the bytecode can be decompiled. But I don't know if there are forms of java code which compiled into bytecode, will never be able to be decompiled to readable java sources.


Solution

  • I wonder if all the bytecode which comes from java (not other JVM language) can be decompiled to java sources again?

    The answer is No.

    Decompilers aren't guaranteed to work for all Java bytecodes:

    • A good obfuscator will deliberately rearrange the bytecodes in such a way that the common decompilers won't produce readable source code ... and probably won't produce valid source code.

    • Many decompilers out there have problems dealing with newer Java constructs.

    • Many decompilers have problems with bytecodes compiled from "complicated" source code.

    • Even if they generate compilable code, there is no guarantee that the code will be correct.

    The bottom line is that a decompiler is only as good as the intelligence and diligence of its author can make it. I've never heard of a perfect one.