leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
2.01k stars 258 forks source link

While loop decompiled as for loop that continues early #247

Open natedogith1 opened 3 years ago

natedogith1 commented 3 years ago

CFR version

CFR 0.151

Compiler

javac 1.8.0_144

Description

The example gets decompiled into a for loop that potentially does a continue when it shouldn't.

Example

public class Test2 {
    public void loop_end(){}
    public void bar(){}
    boolean bool;
    public void testmethod() {
        int rem = 10;
        while(rem >= 0) {
            if(rem >= 1) {
                bar();
            }
            rem -= 2;
            if(bool) loop_end();
        }
    }
}

This gets incorrectly decompiled as

/*
 * Decompiled with CFR 0.151.
 */
public class Test2 {
    boolean bool;

    public void loop_end() {
    }

    public void bar() {
    }

    public void testmethod() {
        for (int i = 10; i >= 0; i -= 2) {
            if (i < 1) continue;
            this.bar();
            if (!this.bool) continue;
            this.loop_end();
        }
    }
}