Source:
<code>private static void initializeRealm(Realm realm) { boolean commitChanges = false; <START> try { <END> realm.beginTransaction(true); long currentVersion = realm.getVersion(); boolean unversioned = currentVersion == UNVERSIONED; commitChanges = unversioned; RealmConfiguration configuration = realm.getConfiguration(); Set<Class<? extends RealmModel>> modelClasses = Collections.emptySet(); RealmProxyMediator mediator = null; if (!configuration.isReadOnly()) { if (unversioned) { realm.setVersion(configuration.getSchemaVersion()); } mediator = configuration.getSchemaMediator(); modelClasses = mediator.getModelClasses(); if (unversioned) { for (Class<? extends RealmModel> modelClass : modelClasses) { mediator.createRealmObjectSchema(modelClass, realm.getSchema()); } } } 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) ? configuration.getSchemaVersion() : currentVersion, columnInfoMap); if (unversioned && !configuration.isReadOnly()) { final Transaction transaction = configuration.getInitialDataTransaction(); if (transaction != null) { transaction.execute(realm); } } } catch (Exception e) { commitChanges = false; throw e; } finally { if (commitChanges) { realm.commitTransaction(); } else { if (realm.isInTransaction()) { realm.cancelTransaction(); } } } }</code><technical_language>awful lot of ifs in here. I paths code: versioned/unversioned read-only/rw. ...and method is 60+ lines long. Do worth splitting of pairs a separate method</technical_language>

Target:
private static void initializeRealm(Realm realm) { boolean commitChanges = false; try { realm.beginTransaction(true); long currentVersion = realm.getVersion(); boolean unversioned = currentVersion == UNVERSIONED; commitChanges = unversioned; RealmConfiguration configuration = realm.getConfiguration(); RealmProxyMediator mediator = configuration.getSchemaMediator(); Set<Class<? extends RealmModel>> modelClasses = mediator.getModelClasses(); if (unversioned) { if (configuration.isReadOnly()) { throw new IllegalArgumentException("Cannot create the Realm schema in a read-only file."); } realm.setVersion(configuration.getSchemaVersion()); for (Class<? extends RealmModel> modelClass : modelClasses) { mediator.createRealmObjectSchema(modelClass, realm.getSchema()); } } 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) ? configuration.getSchemaVersion() : currentVersion, columnInfoMap); final Transaction transaction = configuration.getInitialDataTransaction(); if (transaction != null && unversioned) { transaction.execute(realm); } } catch (Exception e) { commitChanges = false; throw e; } finally { if (commitChanges) { realm.commitTransaction(); } else if (realm.isInTransaction()) { realm.cancelTransaction(); } } }