Source:
private void completedAsyncRealmObject(QueryUpdateTask.Result result) { Set<WeakReference<RealmObject>> updatedRowKey = result.updatedRow.keySet(); if (updatedRowKey.size() > 0) { WeakReference<RealmObject> realmObjectWeakReference = updatedRowKey.iterator().next(); RealmObject realmObject = realmObjectWeakReference.get(); if (realmObject != null) { SharedGroup.VersionID callerVersionID = realm.sharedGroupManager.getVersion(); int compare = callerVersionID.compareTo(result.versionID); if (compare == 0) { long rowPointer = result.updatedRow.get(realmObjectWeakReference); if (rowPointer != 0 && emptyAsyncRealmObject.containsKey(realmObjectWeakReference)) { emptyAsyncRealmObject.remove(realmObjectWeakReference); realmObjects.put(realmObjectWeakReference, null); } realmObject.onCompleted(rowPointer); realmObject.notifyChangeListeners(); } else { if (compare > 0) { RealmLog.d("[COMPLETED_ASYNC_REALM_OBJECT "+ realmObject + "] , realm:" + HandlerController.this + " caller is more advanced. Schedule a retry on current version"); } else { RealmLog.d("[COMPLETED_ASYNC_REALM_OBJECT "+ realmObject + "] , realm:" + HandlerController.this + " worker is more advanced. Schedule a retry on current version."); } if (realmObject.isValid()) { realmObject.notifyChangeListeners(); } else { RealmQuery<?> realmQuery = realmObjects.get(realmObjectWeakReference); if (realmQuery == null) { realmQuery = emptyAsyncRealmObject.get(realmObjectWeakReference); } QueryUpdateTask queryUpdateTask = QueryUpdateTask.newBuilder() .realmConfiguration(realm.getConfiguration()) .addObject(realmObjectWeakReference, realmQuery.handoverQueryPointer(), realmQuery.getArgument()) .sendToHandler(realm.handler, COMPLETED_ASYNC_REALM_OBJECT) .build(); Realm.asyncQueryExecutor.submit(queryUpdateTask); } } } } }

Target:
private void completedAsyncRealmObject(QueryUpdateTask.Result result) { Set<WeakReference<RealmObject>> updatedRowKey = result.updatedRow.keySet(); if (updatedRowKey.size() > 0) { WeakReference<RealmObject> realmObjectWeakReference = updatedRowKey.iterator().next(); RealmObject realmObject = realmObjectWeakReference.get(); if (realmObject != null) { SharedGroup.VersionID callerVersionID = realm.sharedGroupManager.getVersion(); int compare = callerVersionID.compareTo(result.versionID); if (compare == 0) { long rowPointer = result.updatedRow.get(realmObjectWeakReference); if (rowPointer != 0 && emptyAsyncRealmObject.containsKey(realmObjectWeakReference)) { emptyAsyncRealmObject.remove(realmObjectWeakReference); realmObjects.put(realmObjectWeakReference, null); } realmObject.onCompleted(rowPointer); realmObject.notifyChangeListeners(); } else if (compare > 0) { if (realmObject.isValid()) { RealmLog.d("[COMPLETED_ASYNC_REALM_OBJECT "+ realmObject + "] , realm:" + HandlerController.this + " RealmObject is already loaded, just notify it."); realmObject.notifyChangeListeners(); } else { RealmLog.d("[COMPLETED_ASYNC_REALM_OBJECT "+ realmObject + "] , realm:" + HandlerController.this + " RealmObject is not loaded yet. Rerun the query."); RealmQuery<?> realmQuery = realmObjects.get(realmObjectWeakReference); if (realmQuery == null) { realmQuery = emptyAsyncRealmObject.get(realmObjectWeakReference); } QueryUpdateTask queryUpdateTask = QueryUpdateTask.newBuilder() .realmConfiguration(realm.getConfiguration()) .addObject(realmObjectWeakReference, realmQuery.handoverQueryPointer(), realmQuery.getArgument()) .sendToHandler(realm.handler, COMPLETED_ASYNC_REALM_OBJECT) .build(); Realm.asyncQueryExecutor.submit(queryUpdateTask); } } else { throw new IllegalStateException("Caller thread behind the Worker thread"); } } } }