Storyyeller / Krakatau

Java decompiler, assembler, and disassembler
GNU General Public License v3.0
1.95k stars 220 forks source link

test + 1 has different bytecode than test++? #97

Closed Manouchehri closed 8 years ago

Manouchehri commented 8 years ago

Running across an odd issue where it appears that Java doesn't compile test + 1 as the same as test++.

Original functions

public class VotingMachine {
    private int demoVotes, repubVotes;

    public void voteDemo() {
        this.demoVotes++;
    }
    public void voteRepub() {
        this.repubVotes++;
    }
    // Other functions removed to save space.
}

Krakatau output

public class VotingMachine {
    private int demoVotes;
    private int repubVotes;

    public void voteDemo() {
        this.demoVotes = this.demoVotes + 1;
    }
    public void voteRepub() {
        this.repubVotes = this.repubVotes + 1;
    }
    // Other functions removed to save space.
}

combined_votedemo vs votedemo

combined_voterepub vs voterepub

CFR, Fernflower and Procyon all decompile to ++this.demoVotes; and ++this.repubVotes;.

Storyyeller commented 8 years ago

How is this a bug? You obviously can't expect to get the exact same bytecode back after decompiling and recompiling. You're lucky when it compiles at all.

Manouchehri commented 7 years ago

@Storyyeller I think you misread what I wrote. Let me write it out in a table to be a bit more clear.

  1. aload_0; dup == test++
  2. aload_0; aload_0 == test = test + 1
  3. aload_0; dup != test = test + 1
  4. aload_0; aload_0 != test++

Krakatau is incorrectly decompiling aload_0; dup as test = test + 1 instead of test++.

Manouchehri commented 7 years ago

Because CFR, Fernflower and Procyon all correctly decompile aload_0; dup as test++, that implies to me that it's a Krakatau bug.

Storyyeller commented 7 years ago

It's not a bug because the expressions are equivalent.