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

Child class overrides lambda in parent class #207

Closed
cpalasanu opened this issue Sep 13, 2016 · 9 comments
Closed

Child class overrides lambda in parent class #207

cpalasanu opened this issue Sep 13, 2016 · 9 comments

Comments

@cpalasanu
Copy link

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

@Yarikx
Copy link

Yarikx commented Sep 13, 2016

@cpalasanu Tested your project. Works fine for me. Parent button shows 'Parent onClick', child button shows 'Child onClick'.
Can you provide more specific configuration to reproduce or try just cleaning the cache

@calvarez-ov
Copy link

calvarez-ov commented Sep 13, 2016

I just cloned this project, built it and ran it. Clicking on the parent button shows "Child onClick".
I made one change: to use build tools 24.0.2. I built this in a new docker container, so there was no cache.

@cpalasanu
Copy link
Author

@Yarikx what other configuration info can I provide?
by cleaning the cache you mean do a ./gradlew clean? I did that and I still get the behavior.

@cpalasanu
Copy link
Author

also deleted ~/.gradle/chaches and the behavior is the same

@calvarez-ov
Copy link

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)

@Yarikx
Copy link

Yarikx commented Sep 13, 2016

@calvarez-ov Super interesting. I believe it's related to latest updates of retrolambda (not gradle-retrolambda). Is it reproducible with lower versions of retrolambda?

@cpalasanu
Copy link
Author

cpalasanu commented Sep 13, 2016

    retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:2.2.0'

this fixes the issue so it's a problem in 2.3.0

@calvarez-ov
Copy link

I did some tests building the retrolambda project locally. It appears the bug appears in this commit: luontola/retrolambda@bf93245

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

@calvarez-ov
Copy link

I opened an issue in the retrolambda project: luontola/retrolambda#109

I guess this one here may be closed.

@evant evant closed this as completed Sep 13, 2016
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

No branches or pull requests

4 participants