Source:
private synchronized <E extends BaseRealm> E doCreateRealmOrGetFromCache(RealmConfiguration configuration, Class<E> realmClass) { RefAndCount refAndCount = refAndCountMap.get(RealmCacheType.valueOf(realmClass)); if (getTotalGlobalRefCount() == 0) { copyAssetFileIfNeeded(configuration); boolean fileExists = configuration.realmExists(); SharedRealm sharedRealm = null; try { sharedRealm = SharedRealm.getInstance(configuration); if (!fileExists) { try { ObjectServerFacade.getSyncFacadeIfPossible().downloadRemoteChanges(configuration); sharedRealm.refresh(); } catch (Throwable t) { sharedRealm.close(); sharedRealm = null; Realm.deleteRealm(configuration); throw t; } } if (Table.primaryKeyTableNeedsMigration(sharedRealm)) { sharedRealm.beginTransaction(); if (Table.migratePrimaryKeyTableIfNeeded(sharedRealm)) { sharedRealm.commitTransaction(); } else { sharedRealm.cancelTransaction(); } } } finally { if (sharedRealm != null) { sharedRealm.close(); } } this.configuration = configuration; } else { validateConfiguration(configuration); } if (refAndCount.localRealm.get() == null) { BaseRealm realm; if (realmClass == Realm.class) { realm = Realm.createInstance(this); } else if (realmClass == DynamicRealm.class) { realm = DynamicRealm.createInstance(this); } else { throw new IllegalArgumentException(WRONG_REALM_CLASS_MESSAGE); } refAndCount.localRealm.set(realm); refAndCount.localCount.set(0); if (realmClass == Realm.class && refAndCount.globalCount == 0) { RealmCache.storeColumnIndices(typedColumnIndicesArray, realm.schema.getImmutableColumnIndicies()); } refAndCount.globalCount++; } Integer refCount = refAndCount.localCount.get(); refAndCount.localCount.set(refCount + 1); return (E) refAndCount.localRealm.get(); }

Target:
private synchronized <E extends BaseRealm> E doCreateRealmOrGetFromCache(RealmConfiguration configuration, Class<E> realmClass) { RefAndCount refAndCount = refAndCountMap.get(RealmCacheType.valueOf(realmClass)); if (getTotalGlobalRefCount() == 0) { copyAssetFileIfNeeded(configuration); boolean fileExists = configuration.realmExists(); SharedRealm sharedRealm = null; try { sharedRealm = SharedRealm.getInstance(configuration); if (!fileExists) { try { ObjectServerFacade.getSyncFacadeIfPossible().downloadRemoteChanges(configuration); } catch (Throwable t) { sharedRealm.close(); sharedRealm = null; Realm.deleteRealm(configuration); throw t; } } if (Table.primaryKeyTableNeedsMigration(sharedRealm)) { sharedRealm.beginTransaction(); if (Table.migratePrimaryKeyTableIfNeeded(sharedRealm)) { sharedRealm.commitTransaction(); } else { sharedRealm.cancelTransaction(); } } } finally { if (sharedRealm != null) { sharedRealm.close(); } } this.configuration = configuration; } else { validateConfiguration(configuration); } if (refAndCount.localRealm.get() == null) { BaseRealm realm; if (realmClass == Realm.class) { realm = Realm.createInstance(this); } else if (realmClass == DynamicRealm.class) { realm = DynamicRealm.createInstance(this); } else { throw new IllegalArgumentException(WRONG_REALM_CLASS_MESSAGE); } refAndCount.localRealm.set(realm); refAndCount.localCount.set(0); if (realmClass == Realm.class && refAndCount.globalCount == 0) { RealmCache.storeColumnIndices(typedColumnIndicesArray, realm.schema.getImmutableColumnIndicies()); } refAndCount.globalCount++; } Integer refCount = refAndCount.localCount.get(); refAndCount.localCount.set(refCount + 1); return (E) refAndCount.localRealm.get(); }