Source:
private static void initializeSyncedRealm(Realm realm) { boolean commitChanges = false; OsRealmSchema schema = null; try { realm.beginTransaction(); long currentVersion = realm.getVersion(); final boolean unversioned = currentVersion == UNVERSIONED; RealmConfiguration configuration = realm.getConfiguration(); final RealmProxyMediator mediator = configuration.getSchemaMediator(); final Set<Class<? extends RealmModel>> modelClasses = mediator.getModelClasses(); OsRealmSchema.Creator schemaCreator = new OsRealmSchema.Creator(); try { for (Class<? extends RealmModel> modelClass : modelClasses) { mediator.createRealmObjectSchema(modelClass, schemaCreator); } schema = new OsRealmSchema(schemaCreator); } finally { schemaCreator.close(); schemaCreator = null; } long newVersion = configuration.getSchemaVersion(); long schemaNativePointer = schema.getNativePtr(); if (realm.sharedRealm.requiresMigration(schemaNativePointer)) { if (currentVersion >= newVersion) { throw new IllegalArgumentException(String.format( "The schema was changed but the schema version was not updated. " + "The configured schema version (%d) must be greater than the version " + " in the Realm file (%d) in order to update the schema.", newVersion, currentVersion)); } realm.sharedRealm.updateSchema(schemaNativePointer, newVersion); realm.setVersion(newVersion); commitChanges = true; } final Map<Class<? extends RealmModel>, ColumnInfo> columnInfoMap = new HashMap<>(modelClasses.size()); for (Class<? extends RealmModel> modelClass : modelClasses) { columnInfoMap.put(modelClass, mediator.validateTable(modelClass, realm.sharedRealm, false)); } realm.getSchema().setInitialColumnIndices( (unversioned) ? newVersion : currentVersion, columnInfoMap); if (unversioned) { final Transaction transaction = configuration.getInitialDataTransaction(); if (transaction != null) { transaction.execute(realm); } } } catch (RuntimeException e) { commitChanges = false; throw e; } finally { if (schema != null) { schema.close(); } if (commitChanges) { realm.commitTransaction(); } else { realm.cancelTransaction(); } } }

Target:
private static void initializeSyncedRealm(Realm realm) { boolean commitChanges = false; OsRealmSchema schema = null; OsRealmSchema.Creator schemaCreator = null; try { realm.beginTransaction(); long currentVersion = realm.getVersion(); final boolean unversioned = currentVersion == UNVERSIONED; RealmConfiguration configuration = realm.getConfiguration(); final RealmProxyMediator mediator = configuration.getSchemaMediator(); final Set<Class<? extends RealmModel>> modelClasses = mediator.getModelClasses(); schemaCreator = new OsRealmSchema.Creator(); for (Class<? extends RealmModel> modelClass : modelClasses) { mediator.createRealmObjectSchema(modelClass, schemaCreator); } schema = new OsRealmSchema(schemaCreator); schemaCreator.close(); schemaCreator = null; long newVersion = configuration.getSchemaVersion(); long schemaNativePointer = schema.getNativePtr(); if (realm.sharedRealm.requiresMigration(schemaNativePointer)) { if (currentVersion >= newVersion) { throw new IllegalArgumentException(String.format( "The schema was changed but the schema version was not updated. " + "The configured schema version (%d) must be greater than the version " + " in the Realm file (%d) in order to update the schema.", newVersion, currentVersion)); } realm.sharedRealm.updateSchema(schemaNativePointer, newVersion); realm.setVersion(newVersion); commitChanges = true; } final Map<Class<? extends RealmModel>, ColumnInfo> columnInfoMap = new HashMap<>(modelClasses.size()); for (Class<? extends RealmModel> modelClass : modelClasses) { columnInfoMap.put(modelClass, mediator.validateTable(modelClass, realm.sharedRealm, false)); } realm.getSchema().setInitialColumnIndices( (unversioned) ? newVersion : currentVersion, columnInfoMap); if (unversioned) { final Transaction transaction = configuration.getInitialDataTransaction(); if (transaction != null) { transaction.execute(realm); } } } catch (RuntimeException e) { commitChanges = false; throw e; } finally { if (schemaCreator != null) { schemaCreator.close(); } if (schema != null) { schema.close(); } if (commitChanges) { realm.commitTransaction(); } else { realm.cancelTransaction(); } } }