Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any Java Decompiler that can correctly decompile calls to overloaded methods?
    text
    copied!<p>Consider this (IMHO simple) example:</p> <pre><code>public class DecompilerTest { public static void main(String[] args) { Object s1 = "The", s2 = "answer"; doPrint((Object) "You should know:"); for (int i = 0; i &lt; 2; i++) { doPrint(s1); doPrint(s2); s1 = "is"; s2 = new Integer(42); } System.out.println(); } private static void doPrint(String s1) { System.out.print("Wrong!"); } private static void doPrint(Object s1) { System.out.print(s1 + " "); } } </code></pre> <p>Compile it with source/target level 1.1 without debug information (i.e. no local variable information should be present) and try to decompile it. I tried Jad, JD-GUI and Fernflower, and all of them got at least one of the call wrong (i. e. the program printed "Wrong!" at least once)</p> <p>Is there really no java decompiler that can infer the right casts so that it will not call the wrong overload?</p> <p><strong>Edit:</strong> Target level 1.1 so that there is none of that Java6-specific fast-validation information present. That might give the decompiler a clue that s1 has been declared as <code>Object</code> and not as <code>String</code>. Decompilers should be able to decompile the code even without this information (not necessarily get the original variable type, but show the same behaviour), especially since lots of obfuscators strip it as well.</p> <p>What decompilers got wrong:</p> <ul> <li>They missed the cast to <code>(Object)</code> in the first call.</li> <li>They inferred the type of <code>s1</code> to be <code>String</code>, but forgot to add a cast to the call to <code>doPrint</code> (so that the String version is called instead of the Object version).</li> <li>One crappy one (I have not even listed) even infers the type of <code>s2</code> to be String, causing uncompilable code.</li> </ul> <p>In any case, this code never calls the <code>String</code> overload, but the decompiled code did.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload