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

NullPointerException, ConflictResolverInterface, Mutation fails #98

Closed
DeMoss15 opened this issue Jan 14, 2019 · 8 comments
Closed

NullPointerException, ConflictResolverInterface, Mutation fails #98

DeMoss15 opened this issue Jan 14, 2019 · 8 comments
Assignees
Labels
bug Something isn't working pending-response Issue is pending response from the issue requestor

Comments

@DeMoss15
Copy link

  • AppSync SDK Version: 2.7.4
  • aws-android-sdk-mobile-client: 2.10.0

caching strategy NETWORK_ONLY

NPE was on previous versions of the sdk too. But there was no queue.
In latest version requests are being just added to this queue and waited for smth.
In previous versions, even after exception, all mutations were being executed.

here is stack trace of NPE:

V/InterceptorCallback: Thread:[13268]: onResponse()
D/InterceptorCallback: Thread:[13268]: onResponse -- found error
D/InterceptorCallback: Thread:[13268]: onResponse -- Got a string match in the errors for "The conditional request failed".
Thread:[13268]: Conflict String: {"__typename":"UserPost","userId":"3ef6eeb7-d1d3-4060-8d2b-1c929ecef914","createdAt":"2019-01-09T13:44:55.388Z","content":"Hello World","authorType":"USER","author":null,"authorStorefront":null}
Thread:[13268]: Client String: {"createdAt":"2019-01-09T13:44:55.388Z"}
D/InterceptorCallback: Thread:[13268]: onCompleted()
2019-01-09 15:33:36.872 12487-12891/com.moja V/QueueUpdateHandler: Thread:[13124]: Got message to take action on the mutation queue.
2019-01-09 15:33:36.872 12487-12891/com.moja D/QueueUpdateHandler: Thread:[13124]: Got message that a originalMutation process needs to be retried.
2019-01-09 15:33:36.873 12487-12891/com.moja V/QueueUpdateHandler: Thread:[13124]: java.lang.NullPointerException: Attempt to invoke interface method 'void com.amazonaws.mobileconnectors.appsync.ConflictResolverInterface.resolveConflict(com.amazonaws.mobileconnectors.appsync.ConflictResolutionHandler, org.json.JSONObject, org.json.JSONObject, java.lang.String, java.lang.String)' on a null object reference
2019-01-09 15:33:36.873 12487-12891/com.moja W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'void com.amazonaws.mobileconnectors.appsync.ConflictResolverInterface.resolveConflict(com.amazonaws.mobileconnectors.appsync.ConflictResolutionHandler, org.json.JSONObject, org.json.JSONObject, java.lang.String, java.lang.String)' on a null object reference
2019-01-09 15:33:36.874 12487-12891/com.moja W/System.err: at com.amazonaws.mobileconnectors.appsync.AppSyncOfflineMutationInterceptor$QueueUpdateHandler.handleMessage(AppSyncOfflineMutationInterceptor.java:273 )
2019-01-09 15:33:36.874 12487-12891/com.moja W/System.err: at android.os.Handler.dispatchMessage(Handler.java:107 )
2019-01-09 15:33:36.874 12487-12891/com.moja W/System.err: at android.os.Looper.loop(Looper.java:198 )
2019-01-09 15:33:36.874 12487-12891/com.moja W/System.err: at android.os.HandlerThread.run (HandlerThread.java:65 )

whole stack traces:

before:
appsync_version_2,7,4.txt

after:
appsync_version_2,6,28.txt

@scb01 scb01 self-assigned this Jan 14, 2019
@scb01 scb01 added the bug Something isn't working label Jan 14, 2019
@scb01
Copy link
Contributor

scb01 commented Jan 14, 2019

@DeMoss15

Thank you for reporting this issue. I will look into this and post an update here once I have more information.

@scb01
Copy link
Contributor

scb01 commented Jan 15, 2019

@DeMoss15

Version 2.7.5 of the SDK has a fix for this issue. For the Conflict Resolution feature, you have to pass in a custom config resolver. See the following two links for an example of how to do that

Please give it a try and let us know how it goes.

@scb01 scb01 added the pending-response Issue is pending response from the issue requestor label Jan 15, 2019
@DeMoss15
Copy link
Author

@cbommas

Thank you. There is no NPE anymore.

But now I get onFailure() after successful mutation (using default ConflictResolver)
and then everything work fine again.

timestamp: 2019-01-15 17:35:35.575
stack trace:
appsync_version_2,7,5.txt

@scb01
Copy link
Contributor

scb01 commented Jan 15, 2019

@DeMoss15

I took a look at the attached log and this is the expected behavior. It looks like you are not passing in your conflict resolver when you create the AppSync Client. When a conflict resolver is not passed in and a conflict is detected, the default behavior is to fail the mutation and invoke the onError callback method. See below for how you would pass in your conflict resolver

              AWSAppSyncClient.builder()
                .context(context)
                .credentialsProvider(credentialsProvider)
                .serverUrl(endPoint)
                .region(Regions.fromName(appSyncRegion))
                .conflictResolver( YOUR CONFLICT RESOLVER)
                .persistentMutationsCallback(new PersistentMutationsCallback() {
                    @Override
                    public void onResponse(PersistentMutationsResponse response) {
                        Log.d(TAG, response.getMutationClassName());
                    }

                    @Override
                    public void onFailure(PersistentMutationsError error) {
                        Log.e(TAG, error.getMutationClassName());
                        Log.e(TAG, "Error", error.getException());
                    }
                })
           .build();

I am confused by your comment about using the default Conflict Resolver. Can you elaborate?

@DeMoss15
Copy link
Author

@cbommas

I've researched this issue again: this error is on our side.
We call the same mutation twice, accidentally.

Thank you very much for your help!)

@DeMoss15
Copy link
Author

@cbommas
One more question:

What this logs mean and can I suppose it somehow if it's not important

2019-01-16 16:11:48.565 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-01-16 16:11:48.565 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
2019-01-16 16:11:58.606 16346-16550/com.moja V/AppSyncOfflineMutationInterceptor: Thread:[15367]: processing Mutations
2019-01-16 16:11:58.607 16346-16550/com.moja V/QueueUpdateHandler: Thread:[15367]: Got message to take action on the mutation queue.
2019-01-16 16:11:58.608 16346-16550/com.moja V/QueueUpdateHandler: Thread:[15367]: Got message to process next mutation if one exists.
2019-01-16 16:11:58.613 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-01-16 16:11:58.614 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
2019-01-16 16:12:08.649 16346-16550/com.moja V/AppSyncOfflineMutationInterceptor: Thread:[15367]: processing Mutations
2019-01-16 16:12:08.651 16346-16550/com.moja V/QueueUpdateHandler: Thread:[15367]: Got message to take action on the mutation queue.
2019-01-16 16:12:08.652 16346-16550/com.moja V/QueueUpdateHandler: Thread:[15367]: Got message to process next mutation if one exists.
2019-01-16 16:12:08.660 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-01-16 16:12:08.661 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
2019-01-16 16:12:18.693 16346-16550/com.moja V/AppSyncOfflineMutationInterceptor: Thread:[15367]: processing Mutations
2019-01-16 16:12:18.694 16346-16550/com.moja V/QueueUpdateHandler: Thread:[15367]: Got message to take action on the mutation queue.
2019-01-16 16:12:18.695 16346-16550/com.moja V/QueueUpdateHandler: Thread:[15367]: Got message to process next mutation if one exists.
2019-01-16 16:12:18.700 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-01-16 16:12:18.700 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
2019-01-16 16:12:28.734 16346-16550/com.moja V/AppSyncOfflineMutationInterceptor: Thread:[15367]: processing Mutations
2019-01-16 16:12:28.735 16346-16550/com.moja V/QueueUpdateHandler: Thread:[15367]: Got message to take action on the mutation queue.
2019-01-16 16:12:28.736 16346-16550/com.moja V/QueueUpdateHandler: Thread:[15367]: Got message to process next mutation if one exists.
2019-01-16 16:12:28.742 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-01-16 16:12:28.742 16346-16550/com.moja V/AppSyncOfflineMutationManager: Thread:[15367]: In Memory mutations queue was EMPTY!. Nothing to process, exiting

@scb01
Copy link
Contributor

scb01 commented Jan 16, 2019

@DeMoss15
Yeah, this is logging done as part of mutation processing and is safe to ignore.

@ReemaDass
Copy link

hi , i want to format datetime to date in resolver of appsync for my requirement ..
Can anyone help me the formatting template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

4 participants