java-decompiler / jd-gui

A standalone Java Decompiler GUI
GNU General Public License v3.0
13.78k stars 2.36k forks source link

static fields names are replaced by the string they are referring to #231

Open florentbr opened 5 years ago

florentbr commented 5 years ago

JD-GUI : 1.4.1 JD-Core: 0.7.1 Compiler: Java 6

When I decompile com.owon.uppersoft.zip, I'm getting this code for WorkBenchTiny.class :

public class WorkBenchTiny implements WorkBench
{
  ...
  public static final String SCOPEINFOR = "/com/owon/uppersoft/dso/pref/scopeInfo.ini";

  public InputStream getDefaultInIStream()
  {
    return WorkBenchTiny.class.getResourceAsStream("/com/owon/uppersoft/dso/pref/scopeInfo.ini");
  }
  ...
}

The name SCOPEINFOR was replaced in getStaticPrefStream by the string it's pointing to. The decompiler should decompile as:

public class WorkBenchTiny implements WorkBench
{
  ...
  public static final String SCOPEINFOR = "/com/owon/uppersoft/dso/pref/scopeInfo.ini";

  public InputStream getDefaultInIStream()
  {
    return WorkBenchTiny.class.getResourceAsStream(SCOPEINFOR);
  }
  ...
}
emmanue1 commented 5 years ago

Hi @florentbr, Javac replace all static final field references with their values. It's impossible to display the constant java.util.Calendar.APRIL, for example. Nevertheless, if the constant declaration and its value are used in the same class (as in your example), I will be able to improve the decompiled source code.