Skip to content

fix: inline anonymous class wrongly handles field as Classname.this#2367

Merged
skylot merged 2 commits intoskylot:masterfrom
ewt45:fix-class_this
Dec 12, 2024
Merged

fix: inline anonymous class wrongly handles field as Classname.this#2367
skylot merged 2 commits intoskylot:masterfrom
ewt45:fix-class_this

Conversation

@ewt45
Copy link
Copy Markdown
Contributor

@ewt45 ewt45 commented Dec 12, 2024

If option "inline anonymous class" is checked, sometimes the field of the anonymous class is wrongly recoginized as the instance of its parent class, which actually is instance of a random class. This leads to the field being added CLASS_INSTANCE type FieldReplaceAttr and displayed as FieldClassName.this rather than its normal name.

example dex
decompiled code: notice that another is displayed as AnotherClass.this

public class Parent {
    public static Parent test(Class<?> cls) {
        final AnotherClass another = new AnotherClass();
        return new Parent() { // from class: jadxtest.Parent.1
            @Override // jadxtest.Parent
            public String func() {
                return AnotherClass.this.toString();
            }
        };
    }

    public String func() {
        return "";
    }
}

this pr extracts Objects.equals(parentClass, fieldsCls.getClassInfo()), and only add CLASS_INSTANCE replace attr if it is true.

Copy link
Copy Markdown
Owner

@skylot skylot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you 👍

@skylot skylot merged commit 17695ba into skylot:master Dec 12, 2024
@ewt45 ewt45 deleted the fix-class_this branch December 13, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants