luontola / retrolambda

Backport of Java 8's lambda expressions to Java 7, 6 and 5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Calling SomeClass::new with method reference sometimes causes a crash on Android

konmik opened this issue · comments

I didn't test it on JVM.

public class Factory {
    public Factory(Runnable runnable) {
    }
}

public class BuggyClass {

    public BuggyClass() {
    }

    static Factory FACTORY = new Factory(BuggyClass::new);
}


public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new BuggyClass();
    }
}

Causes:

java.lang.VerifyError: Rejecting class com.example.konmik.retrobug.BuggyClass because it failed compile-time verification (declaration of 'com.example.konmik.retrobug.BuggyClass' appears in /data/app/com.example.konmik.retrobug-1/base.apk)
        at com.example.konmik.retrobug.MainActivity.onCreate(MainActivity.java:11)

Tested on Android 5.1, 4.2.2

using

buildscript {
    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.2.0'
    }
}

This might be caused by the hack I left in place when fixing #60. Please try your sample project with the the following two Retrolambda versions and tell me which ones of them work.

https://oss.sonatype.org/content/groups/public/net/orfjackal/retrolambda/retrolambda/2.0.6-SNAPSHOT/retrolambda-2.0.6-20150906.085425-1.jar
https://oss.sonatype.org/content/groups/public/net/orfjackal/retrolambda/retrolambda/2.0.6-SNAPSHOT/retrolambda-2.0.6-20150906.090454-3.jar

Please also post a copy of your sample project so that I can try running it myself. The VerifyError happens only on Android, so I can't test it properly on JVM.

Thank you for the quick response! :)

Both of your versions work.

Here is the repo that can be used to debug the issue:

https://github.com/konmik/retrobug

Here is where you can set your custom builds:

https://github.com/konmik/retrobug/blob/master/app/build.gradle#L30

Put them here:

https://github.com/konmik/retrobug/tree/master/app/libs

Thanks! :)

This is fixed in Retrolambda 2.0.6