Skip to content

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

@xxh160

Description

@xxh160

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    CoreIssues in jadx-core modulebug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions