Search code examples
javajvmreverse-engineeringdecompilingjvm-languages

Decompiling JVM languages


Is it possible to decompile JVM languages like Groovy, Scala to their initial form?

If I try and decompile a 4 line Groovy class I get about 20 lines of decompiled Java code.

It's more of a theoretical question than a practical one, cause there are no such decompilers on the market (not that I know of).

Thanks.


Solution

  • Yes, it's possible to a similar fidelity that a Java decompiler can manage (meaning: the code will look similar, but not necessarily identical).

    You'd need a dedicated decompiler for each language, however.

    Edit: I think I need to clarify what level of fidelity I'd expect:

    • The names of local variables may or may not be reproducable
    • Loop types might be mis-interpreted (for replaced by while, ...)
    • More general: Things that can be done in two similar ways might be mis-interpreted
    • ...

    All of those are errors that also occur on decompiling Java code, simply because the association from byte code to Java source code is not 1:1.

    However, if you have a dedicated Groovy decompiler, then I strongly suspect it to produce much more readable code from decompiling compiled Groovy code than a Java decompiler ever could.