leibnitz27 / cfr

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

Operator-assign on arrays #239

Open Kyuuhachi opened 3 years ago

Kyuuhachi commented 3 years ago

CFR version 0.151, javac version 1.8.0_282

When operator-assigning to an array field, the field is read twice in the decompiled output. This could cause race conditions in multithreaded contexts.

This doesn't happen with function calls, though the output is quite awkward.

This is a regression since version 0.146, where the result with fields was similar to that with functions.

Example

class Test3 {
    int[] a;
    int[] a() { return null; }
}

class Test3s {
    void test3a(Test3 a) {
        a.a[0] |= 0xFF;
    }

    void test3b(Test3 a) {
        a.a[0] = a.a[0] | 0xFF;
    }

    void test3c(Test3 a) {
        a.a()[0] |= 0xFF;
    }

    void test3d(Test3 a) {
        // This one is decompiled 100% correctly
        a.a()[0] = a.a()[0] | 0xFF;
    }
}

Decompiles into

class Test3s {
    Test3s() {
    }

    void test3a(Test3 test3) {
        test3.a[0] = test3.a[0] | 0xFF;
    }

    void test3b(Test3 test3) {
        test3.a[0] = test3.a[0] | 0xFF;
    }

    void test3c(Test3 test3) {
        int[] nArray = test3.a();
        nArray[0] = nArray[0] | 0xFF;
    }

    void test3d(Test3 test3) {
        test3.a()[0] = test3.a()[0] | 0xFF;
    }
}