question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

app crashes on getAccounts()

See original GitHub issue

I am following the sample app to try and get silent login, but my app crashes on the getAccounts() function. if i clear the app storage no crash but if there is a previous login it crashes with the following stack trace

* Attempt to get a user and acquireTokenSilent
         * If this fails we do an interactive request
         */
        List<IAccount> accounts = null;
try {
            accounts = myApp.getAccounts(); //crashes here

            if (accounts != null && accounts.size() == 1) {
                /* We have 1 account */
               ...
}...
java.lang.RuntimeException: Unable to resume activity {jbloomfield.macroapp/jbloomfield.macroapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3822)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3854)
        at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:859)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
        at com.microsoft.identity.common.internal.cache.AccountCredentialCache.getAccountsWithKeys(AccountCredentialCache.java:168)
        at com.microsoft.identity.common.internal.cache.AccountCredentialCache.getAccounts(AccountCredentialCache.java:184)
        at com.microsoft.identity.common.internal.cache.AccountCredentialCache.getAccountsFilteredBy(AccountCredentialCache.java:205)
        at com.microsoft.identity.common.internal.cache.MsalOAuth2TokenCache.getAccounts(MsalOAuth2TokenCache.java:337)
        at com.microsoft.identity.client.PublicClientApplication.getAccounts(PublicClientApplication.java:330)
        at jbloomfield.macroapp.AuthManager.getAccs(AuthManager.java:124)
        at jbloomfield.macroapp.MainActivity.onResume(MainActivity.java:129)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1413)
        at android.app.Activity.performResume(Activity.java:7301)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

8reactions
4gus71ncommented, Mar 15, 2019

Hey guys, I’ve implemented a workaround for this issue, I’m just catching the exception and when that happens I:

...
        } catch (e: Exception) {
            val msalPrefs = context.getSharedPreferences("com.microsoft.identity.client.account_credential_cache", Context.MODE_PRIVATE)
            msalPrefs.edit().clear().commit()
            Log.w("MSAL", e)
            callback.onError()
        }
...

I know that this is a super hacky solution, but It’s the only workaround that I’ve been able to find so far. If any of you can confirm that this fixes the issue for you as well, that would be super useful for me.

Thanks!

1reaction
predalphacommented, Sep 4, 2019

The issue is still present on msal 0.2.2

@4gus71n : ty for your workaround

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Calling any of AccountManager getAccounts makes my ...
Just a single activity and creating an instance of AccountManger then calling getAccounts() and it never reaches the for (... line.
Read more >
App crashes on one specific account - Microsoft Community
Hi,. I have downloaded an app and it crashes every time I open it. So I created a new account and guess what,...
Read more >
Demo Website
This screen is visible only in development. It will not appear if the app crashes in production. Open your browser's developer console to...
Read more >
Order SDK changes? App crashing with didn't find class "com ...
Order SDK changes? App crashing with didn't find class "com.clover.sdk.v3.order.Order". Have there been any recent changes to the orders SDK?
Read more >
Identifying the cause of common crashes - Apple Developer
You can identify the causes for many app crashes by looking for specific patterns in the crash report and taking specific diagnostic actions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found