Search code examples
javaintellij-ideadecompiler

Java decompiling get duplicated local variables


In a decompiled code by Intellij IDEA, I see following code:

public void someMethod(Map params)  {
    HashMap params;
    if (null == params) {
        params = new HashMap();
    } else {
        // ...
    }
}

This code can't compile due to 2 reasons:

  • params is re-declared in body, thus it's duplicated local variable.
  • Even fixed the above issue, the second params is still not initialized.

Questions

  • Why it decompile in that way?

Solution

  • IntelliJ uses own decompiler named as "Fernflower". Here is a GitHub.
    It's not a best decompiler but it's an alive, so there is possibility sometimes it will become the best.
    Meanwhile you can use Eclipse ;). There is really powerful decompiler plugin which supports several different decompilers.
    Also you can use Jar Explorer. This is separate tool which has three decompilers including Fernflower.