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

Misc stuff with nested classes #240

Open Kyuuhachi opened 3 years ago

Kyuuhachi commented 3 years ago

CFR version 0.151, javac version 1.8.0_282

test4a has an unnecessary cast on the qualified this.

test4b does too, and also has the assignment incorrectly moved into the argument for some reason. The test case is quite fragile; the slightest change and it no longer triggers. Yet I have seen it several times in the wild.

Example

class Test4 {
    private A a;
    static class A {
        public B b;
    }
    static class B {
        int c() { return 0; }
    }
    static class D {
        boolean e(int a, int b) { return true; }
    }

    class Test4s {
        D d;
        public void test4a() {
            int i = Test4.this.a.b.c();
        }

        public boolean test4b() {
            int i = Test4.this.a.b.c();
            int j = Test4.this.a.b.c();
            if (this.d.e(i, j)) {
                return true;
            } else {
                return false;
            }
        }
    }
}

Decompiles into

class Test4 {
    private A a;

    Test4() {
    }

    class Test4s {
        D d;

        Test4s() {
        }

        public void test4a() {
            int n = ((Test4)Test4.this).a.b.c();
        }

        public boolean test4b() {
            int n;
            int n2 = ((Test4)Test4.this).a.b.c();
            return this.d.e(n2, n = ((Test4)Test4.this).a.b.c());
        }
    }

    ...
}