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 to short ones #317

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, CFR used the var 'int n' for value 14756, and after that 'n' is assigned to the short arrays, where the error is. I think it is a minor mistake and CFR can easily solve it by adding a cast expression here, right? The total case is available at error example and I hope it can be helpful.

Example

The source code:

class Test {
    int N;
    {
        short s1 = 14756 , sArr[][][]= new short[N][N][N];
        int i15 = 67;
        sArr[i15][i15][i15]= s1;
    }
}

The code decompiled by CFR:

class Test {
    int N;

    Test() {
        int n = 14756;
        short[][][] sArray = new short[this.N][this.N][this.N];
        int n2 = 67;
        sArray[n2][n2][n2] = n;
    }
}
Kroppeb commented 2 years ago

@AIRTEspresso Do you have a way to generate random java code samples?

AICT20 commented 2 years ago

@Kroppeb Yes, I use the JavaFuzzer: it can be found in Github JavaFuzzer