Child class overrides lambda in parent class
See original GitHub issueThis 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: https://github.com/orfjackal/retrolambda/commit/bf932457e45817cdee07f34c8c2059db44848e03 (between releases 2.2.0 and 2.3.0) The PR for that commit: https://github.com/orfjackal/retrolambda/pull/86
I have not done any investigation to understand what part of that commit introduces the bug.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:16
- Comments:6 (3 by maintainers)
Top GitHub Comments
I’ve made a fix for this which converts the private instance methods into package-private static methods. Please try it out. I’ll release a new version soon.
The fix to this has been released in Retrolambda 2.5.0