Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Jadx generates incorrect code for lambda expressions #1829

Closed
xxh160 opened this issue Apr 19, 2023 · 3 comments
Closed

[core] Jadx generates incorrect code for lambda expressions #1829

xxh160 opened this issue Apr 19, 2023 · 3 comments
Labels
bug Core Issues in jadx-core module

Comments

@xxh160
Copy link

xxh160 commented Apr 19, 2023

Hi! I found a confusing bug in Jadx! Please take a look!

Here is an example:

interface Function0<R> {
    public R apply();
}
class T2 {
    public long l;
    public T2(long l) {
        this.l = l;
    }
    public void w() {
    }
}
class Demo {
    public Byte foo(Byte b1) {
        Function0<Void> f1 = () -> {
            new T2(94L).w();
            return null;
        };
        f1.apply();
        return null;
    }
}

I decompiled the classes.dex the code above compiled into, and I got this:

package defpackage;
/* compiled from: lambda */
/* renamed from: -$$Lambda$Demo$Nz2D2A1diuN4kp5IRWSVdEJAshI  reason: invalid class name and default package */
public final /* synthetic */ class $$Lambda$Demo$Nz2D2A1diuN4kp5IRWSVdEJAshI implements Function0 {
    public static final /* synthetic */ $$Lambda$Demo$Nz2D2A1diuN4kp5IRWSVdEJAshI INSTANCE = new $$Lambda$Demo$Nz2D2A1diuN4kp5IRWSVdEJAshI();
    private /* synthetic */ $$Lambda$Demo$Nz2D2A1diuN4kp5IRWSVdEJAshI() {
    }
    @Override // defpackage.Function0
    public final Object apply() {
        return new T2(94L).w();
    }
}

The expression apply function returns was undesirable, and it raised a compilation error:

./out/sources/defpackage/$$Lambda$Demo$Nz2D2A1diuN4kp5IRWSVdEJAshI.java:13: error: incompatible types: void cannot be converted to Object
        return new T2(94L).w();
                            ^
1 error

Would you please take a look at this? It is important for me!
Thanks a lot!

Jadx version: the newest jadx binary in Arch Linux.
Java version: 11.0.18
I also attach the source files and the decompilation results and I hope they will be helpful: demo.zip

@xxh160 xxh160 added bug Core Issues in jadx-core module labels Apr 19, 2023
@bhwxha
Copy link

bhwxha commented Apr 19, 2023

Based on my recent use, I feel that jadx still needs more support for lamda decompiling, bitter laugh.

@skylot
Copy link
Owner

skylot commented Apr 19, 2023

Partially fixed. Currently, inline of multi-instruction method not supported, but your case was mistakenly treated as standard synthetic method. I commit a fix for these checks, so an inner lambda method will be not inlined, that will resolve the issue. Support for other lambdas inline will be covered in issue #523.

@skylot skylot closed this as completed Apr 19, 2023
@xxh160
Copy link
Author

xxh160 commented Apr 19, 2023

Very thankful!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module
Projects
None yet
Development

No branches or pull requests

3 participants