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

IllegalStateException in onTokenRequestCompleted() #88

Open
barbeau opened this issue Apr 19, 2018 · 7 comments
Open

IllegalStateException in onTokenRequestCompleted() #88

barbeau opened this issue Apr 19, 2018 · 7 comments
Labels

Comments

@barbeau
Copy link
Collaborator

barbeau commented Apr 19, 2018

From the OneBusAway Android rollout via the Android Developer Console - affecting 3 users (3 crashes):

java.lang.IllegalStateException: 
  at android.support.v4.app.Fragment.getResources (Fragment.java:608)
  at android.support.v4.app.Fragment.getString (Fragment.java:632)
  at com.microsoft.embeddedsocial.c.d$1.onTokenRequestCompleted (Unknown Source:30)
  at net.openid.appauth.AuthorizationService$TokenRequestTask.onPostExecute (AuthorizationService.java:308)
  at net.openid.appauth.AuthorizationService$TokenRequestTask.onPostExecute (AuthorizationService.java:238)
  at android.os.AsyncTask.finish (AsyncTask.java:695)
  at android.os.AsyncTask.-wrap1 (Unknown Source)
  at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:712)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6940)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

I'm assuming this happens when someone tries to log into Embedded Social in the OBA app and then closes it, likely under poor wireless conditions that cause a significant delay in onTokenRequestCompleted() returning.

Devices affected:

  • Samsung Galaxy Note8 (greatqlte), 6144MB RAM, Android 8.0
  • Google Pixel 2 (walleye), 4096MB RAM, Android 8.1
  • ZTE Blade X Max (stollen), 2048MB RAM, Android 7.1

Note that the Note 8 and Pixel 2 are affected, so this does affect flagship devices

@barbeau
Copy link
Collaborator Author

barbeau commented Apr 19, 2018

Downstream OBA issue - OneBusAway/onebusaway-android#870

@acrown-msft
Copy link
Member

I gather from the stack trace that the call to getFragment().getString() (line 129 in /auth/GoogleAppAuthAuthenticator.java) generates an exception because the SignIn fragment which contains this object is not attached to an activity (https://stackoverflow.com/a/36745804). I get a similar stack trace by removing the SignIn fragment's mHost in a debugger.

However, I'm unable to come up with a repro without using the debugger to modify data at runtime. I'm trying to kill the app at various points in the execution but have yet to come up with anything.

@barbeau
My proposal is to add better logging information to this code block so we can identify the root cause of the issue the next time it pops up. Is there a system flag we can check to determine if the app has been killed? I'll continue trying to repro, but in the meantime, I'm just taking shots in the dark.

@barbeau
Copy link
Collaborator Author

barbeau commented Apr 23, 2018

I gather from the stack trace that the call to getFragment().getString() (line 129 in /auth/GoogleAppAuthAuthenticator.java) generates an exception because the SignIn fragment which contains this object is not attached to an activity (https://stackoverflow.com/a/36745804).

I've avoided this issue in other async callbacks related to fragments by checking for isAdded() before doing something that would cause an IllegalStateException, and if it's false just returning (effectively a no-op). I've seen this in other Google code as well, including the NavigationDrawerFragment we use in OBA Android that was borrowed from a Google I/O app.

If you're simply getting string resources here, another option would be to use the Application context (which should still exist if your code is running) via Application.get().getApplicationContext().

My proposal is to add better logging information to this code block so we can identify the root cause of the issue the next time it pops up.

That would be great, but how are you going to log this? AFAIK all you get via Android Developer Console is a stack trace, so you'd need to catch the exception and then log via Google Analytics or something similar. But let me know if you have other ideas.

Is there a system flag we can check to determine if the app has been killed?

AFAIK as long as your code is running the application context should still exist

@barbeau
Copy link
Collaborator Author

barbeau commented Jun 20, 2018

We finally got an unobfuscated stack trace, from a Samsung Galaxy Note8 (greatqlteue), 6144MB RAM, Android 8.0, although this is an NPE and not an IllegalStateException:

java.lang.NullPointerException: 
  at android.content.ContextWrapper.getResources (ContextWrapper.java:93)
  at android.view.ContextThemeWrapper.getResourcesInternal (ContextThemeWrapper.java:127)
  at android.view.ContextThemeWrapper.getResources (ContextThemeWrapper.java:121)
  at android.support.v4.app.Fragment.getResources (Fragment.java:678)
  at android.support.v4.app.Fragment.getString (Fragment.java:700)
  at com.microsoft.embeddedsocial.auth.GoogleAppAuthAuthenticator$1.onTokenRequestCompleted (GoogleAppAuthAuthenticator.java:129)
  at net.openid.appauth.AuthorizationService$TokenRequestTask.onPostExecute (AuthorizationService.java:308)
  at net.openid.appauth.AuthorizationService$TokenRequestTask.onPostExecute (AuthorizationService.java:238)
  at android.os.AsyncTask.finish (AsyncTask.java:695)
  at android.os.AsyncTask.-wrap1 (Unknown Source)
  at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:712)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6940)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

@barbeau
Copy link
Collaborator Author

barbeau commented Jun 20, 2018

From a quick look at the code, it looks like this new NPE and the IllegalStateException are separate issues.

@barbeau
Copy link
Collaborator Author

barbeau commented Jun 21, 2018

I opened a new issue for the above NPE at #94.

@Stokesd503
Copy link

Nice I guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants