Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
konmik opened this issue Sep 5, 2015 · 4 comments

Comments

@konmik
Copy link

konmik commented Sep 5, 2015

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'
    }
}
@luontola
Copy link
Owner

luontola commented Sep 6, 2015

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.

@konmik
Copy link
Author

konmik commented Sep 6, 2015

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

@konmik
Copy link
Author

konmik commented Sep 6, 2015

Thanks! :)

@luontola
Copy link
Owner

luontola commented Sep 6, 2015

This is fixed in Retrolambda 2.0.6

joerg-wille added a commit to joerg-wille/afterburner.fx that referenced this issue Sep 9, 2015
Use Retrolambda 2.0.6 (2015-09-06), which fixed method references to constructors causing VerifyError on Android (luontola/retrolambda#67) to fix SecurityException, when using:
view.getViewAsync(leftPane.getChildren()::add);
view.getView(leftPane.getChildren()::add);

09-04 18:30:55.165: E/AndroidRuntime(14508): java.lang.Error: java.lang.SecurityException: Unsafe access denied
09-04 18:30:55.165: E/AndroidRuntime(14508): 	at java.util.concurrent.CompletableFuture.<clinit>(CompletableFuture.java:3009)
09-04 18:30:55.165: E/AndroidRuntime(14508): 	at com.airhacks.afterburner.views.FXMLView.getView(FXMLView.java:127)
09-04 18:30:55.165: E/AndroidRuntime(14508): 	at com.airhacks.afterburner.views.FXMLView.lambda$getViewAsync$3(FXMLView.java:138)
09-04 18:30:55.165: E/AndroidRuntime(14508): 	at com.airhacks.afterburner.views.FXMLView.access$lambda$3(FXMLView.java)
09-04 18:30:55.165: E/AndroidRuntime(14508): 	at com.airhacks.afterburner.views.FXMLView$$Lambda$5.run(Unknown Source)
09-04 18:30:55.165: E/AndroidRuntime(14508): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-04 18:30:55.165: E/AndroidRuntime(14508): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-04 18:30:55.165: E/AndroidRuntime(14508): 	at java.lang.Thread.run(Thread.java:841)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants