canelmas / let

Annotation based simple API flavored with AOP to handle new Android runtime permission model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Let annotation crashes on Android N devices

olsontl opened this issue · comments

Hey there,
Thought you'd like to know about this crash on Android N:

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String[] com.canelmas.let.AskPermission.value()' on a null object reference
    at com.canelmas.let.RuntimePermissionRequest.proceed(RuntimePermissionRequest.java:61)
    at com.canelmas.let.RuntimePermissionRequest.proceed(RuntimePermissionRequest.java:52)
    at com.canelmas.let.LetAspect.ajc$inlineAccessMethod$com_canelmas_let_LetAspect$com_canelmas_let_RuntimePermissionRequest$proceed(LetAspect.java:1)
    at com.canelmas.let.LetAspect.annotatedMethods(LetAspect.java:57)

Here's the line of code where it crashed:
@AskPermission({ Manifest.permission.ACCESS_FINE_LOCATION })

Just thought I'd give you a heads up for when the full OS release actually comes out. Love the library!

Same problem in my app, crashing on Android N devices. I am asking for:

@AskPermission({Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE})

And the crash looks like this:

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String[] com.canelmas.let.AskPermission.value()' on a null object reference
    at com.canelmas.let.RuntimePermissionRequest.proceed(RuntimePermissionRequest.java:61)
    at com.canelmas.let.RuntimePermissionRequest.proceed(RuntimePermissionRequest.java:52)
    at com.canelmas.let.LetAspect.ajc$inlineAccessMethod$com_canelmas_let_LetAspect$com_canelmas_let_RuntimePermissionRequest$proceed(LetAspect.java:1)
    at com.canelmas.let.LetAspect.annotatedMethods(LetAspect.java:57)
    at com.mendhak.gpslogger.ui.fragments.display.GenericViewFragment.requestToggleLogging(GenericViewFragment.java:98)
    at com.mendhak.gpslogger.ui.fragments.display.GpsSimpleViewFragment$1.onClick(GpsSimpleViewFragment.java:101)
    at android.view.View.performClick(View.java:5565)
    at android.view.View$PerformClick.run(View.java:22047)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5849)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:763)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653)

@olsontl @mendhak hey, thanks for reporting. I'm also able to reproduce the crash.

I believe the issue is related to the retention policy set to RetentionPolicy.CLASS for @AskPermission

To be honest, I don't really remember what was I really thinking when I changed it from Runtime to Class in the first place. I will fix it in a day.

But the thing is I'm having trouble understanding why it's working on pre-N and not on N.

it should be fixed with 0.1.10

Looks good. Thanks!

It seems that retention policies are not being honored in certain cases; which is fixed and should be expected with the upcoming new N releases.

You can check official issue here : https://code.google.com/p/android/issues/detail?id=203109

this problem still happens on 0.1.11:

    Process: com.craftlog.android.cooking, PID: 14695
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.annotation.Annotation java.lang.reflect.Method.getAnnotation(java.lang.Class)' on a null object reference
        at com.canelmas.let.RuntimePermissionRequest.proceed(SourceFile:61)
        at com.canelmas.let.RuntimePermissionRequest.proceed(SourceFile:52)
        at com.canelmas.let.LetAspect.ajc$inlineAccessMethod$com_canelmas_let_LetAspect$com_canelmas_let_RuntimePermissionRequest$proceed(SourceFile:1)
        at com.canelmas.let.LetAspect.annotatedMethods(SourceFile:57)

it started happening after we disabled D8 compiler.

Do you think this library should never crash? Maybe a big-O try/catch will be necessary, regardless of android bugs.