Skip to content

Child class overrides lambda in parent class #109

Closed
@calvarez-ov

Description

@calvarez-ov

This was initially reported in the gradle-retrolambda project, but the problem appears to come from this project.

Copying the report here:


public abstract class ParentActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentView());
        findViewById(R.id.button_parent).setOnClickListener(view -> Toast.makeText(this, "Parent onClick", Toast.LENGTH_LONG).show());
    }

    public abstract int getContentView();
}
public class MainActivity extends ParentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        findViewById(R.id.button_child).setOnClickListener(view -> Toast.makeText(this, "Child onClick", Toast.LENGTH_LONG).show());
    }

    @Override
    public int getContentView() {
        return R.layout.activity_main;
    }
}

Clicking on button_parent shows a Toast with "Child onClick"

test app: https://github.com/cpalasanu/RetrolambdaTest


Using the cfr decompiler, we see that the child activity class has a method that overrides the parent activity class:

Parent:

/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  android.content.Context
 *  android.os.Bundle
 *  android.support.annotation.Nullable
 *  android.support.v7.app.AppCompatActivity
 *  android.view.View
 *  android.view.View$OnClickListener
 *  android.widget.Toast
 */
package com.orange.retrolambdatest;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import com.orange.retrolambdatest.ParentActivity$$Lambda$1;

public abstract class ParentActivity
extends AppCompatActivity {
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(this.getContentView());
        this.findViewById(2131427412).setOnClickListener(ParentActivity$$Lambda$1.lambdaFactory$(this));
    }

    public abstract int getContentView();

    /* synthetic */ void lambda$onCreate$0(View view) {
        Toast.makeText((Context)this, (CharSequence)"Parent onClick", (int)1).show();
    }
}

Child:

/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  android.content.Context
 *  android.os.Bundle
 *  android.view.View
 *  android.view.View$OnClickListener
 *  android.widget.Toast
 */
package com.orange.retrolambdatest;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.orange.retrolambdatest.MainActivity$$Lambda$1;
import com.orange.retrolambdatest.ParentActivity;

public class MainActivity
extends ParentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.findViewById(2131427413).setOnClickListener(MainActivity$$Lambda$1.lambdaFactory$(this));
    }

    @Override
    public int getContentView() {
        return 2130968602;
    }

    @Override
    /* synthetic */ void lambda$onCreate$0(View view) {
        Toast.makeText((Context)this, (CharSequence)"Child onClick", (int)1).show();
    }
}

Both parent and child have the same method lambda$onCreate$0(View view)


I did some tests building the retrolambda project locally. It appears the bug appears in this commit: bf93245 (between releases 2.2.0 and 2.3.0) The PR for that commit: #86

I have not done any investigation to understand what part of that commit introduces the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions