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

java.lang.NullPointerException calling provider.refresh() #181

Closed
adelpuva opened this issue Jul 27, 2016 · 7 comments
Closed

java.lang.NullPointerException calling provider.refresh() #181

adelpuva opened this issue Jul 27, 2016 · 7 comments

Comments

@adelpuva
Copy link

When I call provider.refresh(), sometimes, is thrown this exception:

java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference at com.amazonaws.auth.CognitoCachingCredentialsProvider.refresh(CognitoCachingCredentialsProvider.java:465)

My code is:

Map<String, String> logins = new HashMap<>();
logins.put(providerName, token);
provider.setLogins(logins);
provider.refresh();

This error is happen with 2.2.20, I upgrade to 2.2.21 only yestarday...

Thank you

@jbailey2010
Copy link

Can you clarify your last comment? Does that mean it's only happening in 2.2.20 but not 2.2.21?

@jbailey2010
Copy link

And can you provide a snippet of how you're initializing your credentials provider so we can trace it through the SDK?

@adelpuva
Copy link
Author

Only with 2.2.20.

Now I'm using 2.2.22 (No 2.3.0 for this reason: #129 (comment)), and the problem is not happen yet.

This is my code:

    public static void init(final Context context) {
        Resources res = context.getResources();

        regions = Regions.fromName(res.getString(R.string.aws_region));

        ClientConfiguration clientConfiguration = new ClientConfiguration();

        provider = new CognitoCachingCredentialsProvider(
                context,
                res.getString(R.string.aws_identity_pool_id),
                regions,
                clientConfiguration
        );

        syncClient = new CognitoSyncManager(context, regions, provider);

        userPool = new CognitoUserPool(context,
                res.getString(R.string.aws_user_pool_id),
                res.getString(R.string.aws_user_pool_client_id),
                res.getString(R.string.aws_user_pool_client_secret),
                clientConfiguration
        );

        AmazonS3 s3 = new AmazonS3Client(provider);
        s3.setRegion(Region.getRegion(Regions.fromName(res.getString(R.string.aws_bucket_region))));

        transferUtility = new TransferUtility(s3, context);

        provider.registerIdentityChangedListener(new IdentityChangedListener() {
            @Override
            public void identityChanged(String oldIdentityId, String newIdentityId) {
                Logs.onlyIfDebug(String.format("[identityChanged] OLD: %s", oldIdentityId));
                Logs.onlyIfDebug(String.format("[identityChanged] NEW: %s", newIdentityId));
            }
        });
    }

    public static void logIn(final Context context, final String providerName, final String token) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Logs.onlyIfDebug(String.format("[logIn / bck] for %s", providerName));
                    Map<String, String> logins = new HashMap<>();
                    logins.put(providerName, token);
                    provider.setLogins(logins);
                    // FIXME Amazon must fix it!
                    // java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference
                    // at com.amazonaws.auth.CognitoCachingCredentialsProvider.refresh(CognitoCachingCredentialsProvider.java:465)
                    // at com.neosperience.android.user.AWSHelper$3.run(AWSHelper.java:354)
                    provider.refresh();
                    createLambdaFactory(context);
                } catch (Exception e) {
                    AWSHelper.logOut(context);
                }
            }
        }).start();
    }

    public static void logOut(Context context) {
        Logs.onlyIfDebug("logOut");

        if (userPool != null && userPool.getCurrentUser() != null) {
            userPool.getCurrentUser().signOut();
            Logs.onlyIfDebug("logOut -> UserPool -> SignOut");
        }

        if (provider != null) {
            provider.getLogins().clear();
            provider.clear();
            Logs.onlyIfDebug("logOut -> Provider -> Clear");
        }

        if (syncClient != null) {
            syncClient.openOrCreateDataset(Const.DATASET).delete();
            syncClient.wipeData();
            Logs.onlyIfDebug("logOut -> sync -> delete/wipeData");
        }
    }

    private static void createLambdaFactory(Context context) {
        Logs.onlyIfDebug("[createLambdaFactory]");
        ClientConfiguration config = new ClientConfiguration();
        config.setSocketTimeout(1 * 60 * 1000); 
        lambdaInvokerFactory = new LambdaInvokerFactory(context, regions, provider, config);
    }

@jbailey2010
Copy link

Just to test, can you give it a run through with 2.3.0?

Were you running into the issue on every run with 2.2.20, or was it intermittent?

@adelpuva
Copy link
Author

adelpuva commented Aug 23, 2016

With 2.2.20 was intermittent, while with 2.2.22 is not happened yet!
(I can not test 2.3.0 because my device test is <19 )

@jbailey2010
Copy link

I have thus far not been able to reproduce with the more recent SDKs, has it been behaving? It may have just been an issue with an older one.

@wdane
Copy link
Contributor

wdane commented Sep 8, 2016

Closing for now, please re-open if issue occurs in newer SDK releases.

@wdane wdane closed this as completed Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants