Source:
<code>private synchronized <E extends BaseRealm> E doCreateRealmOrGetFromCache(RealmConfiguration configuration, Class<E> realmClass, OsSharedRealm.VersionID version) { ReferenceCounter referenceCounter = getRefCounter(realmClass, version); boolean firstRealmInstanceInProcess = (getTotalGlobalRefCount() == 0); boolean realmFileIsBeingCreated = !configuration.realmExists(); if (firstRealmInstanceInProcess) { copyAssetFileIfNeeded(configuration); OsSharedRealm sharedRealm = null; try { <START> if (configuration.isSyncConfiguration()) { <END> if (realmFileIsBeingCreated) { OsRealmConfig osConfig = new OsRealmConfig.Builder(configuration).build(); ObjectServerFacade.getSyncFacadeIfPossible().wrapObjectStoreSessionIfRequired(osConfig); if (ObjectServerFacade.getSyncFacadeIfPossible().isPartialRealm(configuration)) { sharedRealm = OsSharedRealm.getInstance(configuration, OsSharedRealm.VersionID.LIVE); try { ObjectServerFacade.getSyncFacadeIfPossible().downloadInitialRemoteChanges(configuration); } catch (Throwable t) { sharedRealm.close(); sharedRealm = null; deleteRealmFileOnDisk(configuration); throw t; } } else { ObjectServerFacade.getSyncFacadeIfPossible().downloadInitialRemoteChanges(configuration); } } } } finally { if (sharedRealm != null) { sharedRealm.close(); } } this.configuration = configuration; } else { validateConfiguration(configuration); } if (!referenceCounter.hasInstanceAvailableForThread()) { createInstance(realmClass, referenceCounter, realmFileIsBeingCreated, version); } referenceCounter.incrementThreadCount(1); return (E) referenceCounter.getRealmInstance(); }</code><technical_language>collapse realmFileIsBeingCreated condition & remove PMD exclusion warning</technical_language>

Target:
private synchronized <E extends BaseRealm> E doCreateRealmOrGetFromCache(RealmConfiguration configuration, Class<E> realmClass, OsSharedRealm.VersionID version) { ReferenceCounter referenceCounter = getRefCounter(realmClass, version); boolean firstRealmInstanceInProcess = (getTotalGlobalRefCount() == 0); boolean realmFileIsBeingCreated = !configuration.realmExists(); if (firstRealmInstanceInProcess) { copyAssetFileIfNeeded(configuration); OsSharedRealm sharedRealm = null; try { if (configuration.isSyncConfiguration() && realmFileIsBeingCreated) { OsRealmConfig osConfig = new OsRealmConfig.Builder(configuration).build(); ObjectServerFacade.getSyncFacadeIfPossible().wrapObjectStoreSessionIfRequired(osConfig); if (ObjectServerFacade.getSyncFacadeIfPossible().isPartialRealm(configuration)) { sharedRealm = OsSharedRealm.getInstance(configuration, OsSharedRealm.VersionID.LIVE); try { ObjectServerFacade.getSyncFacadeIfPossible().downloadInitialRemoteChanges(configuration); } catch (Throwable t) { sharedRealm.close(); sharedRealm = null; deleteRealmFileOnDisk(configuration); throw t; } } else { ObjectServerFacade.getSyncFacadeIfPossible().downloadInitialRemoteChanges(configuration); } } } finally { if (sharedRealm != null) { sharedRealm.close(); } } this.configuration = configuration; } else { validateConfiguration(configuration); } if (!referenceCounter.hasInstanceAvailableForThread()) { createInstance(realmClass, referenceCounter, realmFileIsBeingCreated, version); } referenceCounter.incrementThreadCount(1); return (E) referenceCounter.getRealmInstance(); }