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 may using unnecessary Object-cast expressions that confuse Java compilers #313

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. When decompiling method invocations of method declarations with the same name while different parameter types, CFR may use the Object-cast expression on the invocation args, which may confuse Java compilers, and even users. The total case is available at error example and I hope it can be helpful.

Example

The source code:

class Test {
    int N;
    {
        int iArr1[][][]= new int[N][N][N];
        init(iArr1 , - 12);
    }
    static void init(float[]a , float seed){
    }
    static void init(Object a , Object seed){
    }
}

The code decompiled by CFR:

class Test {
    int N;
    Test() {
        int[][][] nArray = new int[this.N][this.N][this.N];
        Test.init(nArray, (Object)-12);
    }

    static void init(float[] fArray, float f) {
    }

    static void init(Object object, Object object2) {
    }
}