leibnitz27 / cfr

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

CFR tries to convert integer variables into boolean ones #316

Open AIRTEspresso opened 2 years ago

AIRTEspresso commented 2 years ago

CFR version

CFR version: 0.152

Compiler

Java openJDK, version: 11.0.13

Description

Here is another case that CFR may generate invalid Java code. In this example, for the source code 'boolean b2 = false; bArr1[i20]= b2;', CFR generated 'int n2; blArray[n] = n2 = 0;' accordingly. I know that compilers tend to use integer 0 and 1 as false and true in the bytecode, and maybe it is the reason for this incompatible type conversion. The total case is available at error example and I hope it can be helpful.

Example

The source code:

class Test {
    int N;
    {
        int i20 = 35;
        boolean bArr1[]= new boolean[N];
        switch(30){
            case 32 : {
                boolean b2 = false;
                bArr1[i20]= b2;
            }
            short s1 = 31371;
        }
    }
}
}

The code decompiled by CFR:

class Test {
    int N;
    Test() {
        int n = 35;
        boolean[] blArray = new boolean[this.N];
        switch (30) {
            case 32: {
                int n2;
                blArray[n] = n2 = 0;
                n2 = 31371;
            }
        }
    }
}