@@ -45,14 +45,17 @@ private interface Callback {
45
45
46
46
public static final String TAG = "FirebaseCb" ;
47
47
48
+ // Object used to synchronize around. All synchronization should be done with this,
49
+ // as there isn't a guarantee on which function will be called first.
50
+ private final Object lockObject = new Object ();
51
+
48
52
/**
49
53
* This class is registered with a Task object as an OnSuccessListener, OnFailureListener, and
50
54
* OnCanceledListener, redirecting completion status to the C++ method nativeOnResult.
51
55
*/
52
56
private class TaskCallback <TResult >
53
57
implements OnSuccessListener <TResult >, OnFailureListener , OnCanceledListener , Callback {
54
58
private Task <TResult > task ;
55
- private final Object lockObject = new Object ();
56
59
/**
57
60
* Register with a Task instance to capture the completion callback.
58
61
*/
@@ -129,7 +132,7 @@ protected void initializeNativeCallbackFunctionAndData(long callbackFn, long cal
129
132
130
133
/** Initialize / attach the instance to a pending result or task object. */
131
134
protected void initializeWithTask (Task <TResult > task ) {
132
- synchronized (this ) {
135
+ synchronized (lockObject ) {
133
136
callbackHandler = new TaskCallback <TResult >(task );
134
137
callbackHandler .register ();
135
138
}
@@ -146,7 +149,7 @@ public void cancel() {
146
149
/** Call nativeOnResult with the registered callbackFn and callbackData. */
147
150
public void onCompletion (
148
151
Object result , boolean success , boolean cancelled , String statusMessage ) {
149
- synchronized (this ) {
152
+ synchronized (lockObject ) {
150
153
if (callbackHandler != null ) {
151
154
nativeOnResult (result , success , cancelled , statusMessage , callbackFn , callbackData );
152
155
callbackHandler .disconnect ();
0 commit comments