Source:
private static void initializeSyncedRealm(Realm realm) { boolean commitChanges = false; try { realm.beginTransaction(); long currentVersion = realm.getVersion(); final boolean unversioned = (currentVersion == UNVERSIONED); final RealmProxyMediator mediator = realm.configuration.getSchemaMediator(); final Set<Class<? extends RealmModel>> modelClasses = mediator.getModelClasses(); final ArrayList<RealmObjectSchema> realmObjectSchemas = new ArrayList<>(); for (Class<? extends RealmModel> modelClass : modelClasses) { RealmObjectSchema realmObjectSchema = mediator.createRealmObjectSchema(modelClass, null); realmObjectSchemas.add(realmObjectSchema); } final RealmNativeSchema schema = new RealmNativeSchema(realmObjectSchemas); long newVersion = realm.configuration.getSchemaVersion(); if (realm.sharedRealm.requiresMigration(schema)) { 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 higher than the one in the Realm " + "file (%d) in order to update the schema.", newVersion, currentVersion)); } realm.sharedRealm.updateSchema(schema, 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.schema.setColumnIndices((unversioned) ? newVersion : currentVersion, columnInfoMap); if (unversioned) { final Transaction transaction = realm.configuration.getInitialDataTransaction(); if (transaction != null) { transaction.execute(realm); } } } catch (Exception e) { commitChanges = false; throw e; } finally { if (commitChanges) { realm.commitTransaction(); } else { realm.cancelTransaction(); } } }

Target:
private static void initializeSyncedRealm(Realm realm) { boolean commitChanges = false; try { realm.beginTransaction(); long currentVersion = realm.getVersion(); final boolean unversioned = (currentVersion == UNVERSIONED); final RealmProxyMediator mediator = realm.configuration.getSchemaMediator(); final Set<Class<? extends RealmModel>> modelClasses = mediator.getModelClasses(); final OsRealmSchema.Creator schemaCreator = new OsRealmSchema.Creator(); for (Class<? extends RealmModel> modelClass : modelClasses) { mediator.createRealmObjectSchema(modelClass, schemaCreator); } final OsRealmSchema schema = new OsRealmSchema(schemaCreator); long newVersion = realm.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 higher than the one 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().setColumnIndices((unversioned) ? newVersion : currentVersion, columnInfoMap); if (unversioned) { final Transaction transaction = realm.configuration.getInitialDataTransaction(); if (transaction != null) { transaction.execute(realm); } } } catch (Exception e) { commitChanges = false; throw e; } finally { if (commitChanges) { realm.commitTransaction(); } else { realm.cancelTransaction(); } } }