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

Decompiler puts super call after synthetic field initialization. #265

Open rehwinkel opened 2 years ago

rehwinkel commented 2 years ago

CFR version

0.152-SNAPSHOT

Compiler

Unknown.

Description

When javac creates a synthetic field, it's initialization can be put before the super call. This means the resulting code throws a compile error, cause super must always be the first call. Here is a bytecode example that illustrates this issue:

  public MyClass(Testing);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #14                 // Field syntheticField:LTesting;
       5: aload_0
       6: aload_1
       7: invokespecial #29                 // Method SuperClass."<init>":(LTesting;)V

And the resulting java code is:

class MyClass extends SuperClass {
    final /* synthetic */ Testing syntheticField;

    public MyClass(Testing var1) {
        this.syntheticField = var1;
        super(var1);
        ...
    }
    ...
}
rehwinkel commented 2 years ago

I'd propose just swapping the generated lines of code to ensure super(x) is always first. Not sure exactly how the code is generated, so this might not be as simple