Choose and test java decompiler

user471011 picture user471011 · Oct 10, 2010 · Viewed 42.1k times · Source

Now I'm trying to find the best java decompiler, I found these:

With these decompilers I handle byte code of this class:

public class ss
{
public static void main(String args[])
{
  try{
   System.out.println("try");

  }
  catch(Exception e)
  {
   System.out.println("catch");
  }
  finally
  {System.out.println("finally");}
}
}

and I got the following results:

fernflower:

public class ss {

   public static void main(String[] var0) {
      try {
         System.out.println("try");
      } catch (Exception var5) {
         System.out.println("catch");
      } finally {
         System.out.println("finally");
      }

   }
}

DJ Java Decompiler:

import java.io.PrintStream;

public class ss
{

    public ss()
    {
    }

    public static void main(String args[])
    {
        System.out.println("try");
        System.out.println("finally");
        break MISSING_BLOCK_LABEL_50;
        Exception exception;
        exception;
        System.out.println("catch");
        System.out.println("finally");
        break MISSING_BLOCK_LABEL_50;
        Exception exception1;
        exception1;
        System.out.println("finally");
        throw exception1;
    }
}

cavaj:

import java.io.PrintStream;

public class ss
{

    public ss()
    {
    }

    public static void main(String args[])
    {
        System.out.println("try");
        System.out.println("finally");
        break MISSING_BLOCK_LABEL_50;
        Exception exception;
        exception;
        System.out.println("catch");
        System.out.println("finally");
        break MISSING_BLOCK_LABEL_50;
        Exception exception1;
        exception1;
        System.out.println("finally");
        throw exception1;
    }
}

http://java.decompiler.free.fr/:

import java.io.PrintStream;
public class ss
{
  public static void main(String[] paramArrayOfString)
  {
    try
    {
      System.out.println("try");
    }
    catch (Exception localException)
    {
      System.out.println("catch");
    }
    finally {
      System.out.println("finally");
    }
  }
}

I see that the best result in decompiler: http://java.decompiler.free.fr/

To test, I wrote very simple code. What do you think, what code to write to test decompilers? Maybe the idea is to better than a try{} catch(){} finally{}?

Answer

Justin Garrick picture Justin Garrick · Oct 12, 2010

The code that you use to test should test the features available the in JDK used to compile the target class. For example, if you know that your target is written in Java 1.5, it is reasonable to assume that the code might include generics, so you will want to make sure that your chosen decompiler handles them properly. In my experience, the freely available decompilers tend to lag behind the JDK releases in terms of the features they support by 1-2 releases.

Based on personal trial and error, JD tends to do the best job in general. However, if you're decompiling code that was written in 1.3 or lower, I'd also suggest you give JODE a try.

EDIT, 5 years later:

CFR, Procyon, and Fernflower lead the way in this space.