Source:
<code>private ListenableFuture<Void> initInternal(Context context, AppConfig appConfig) { synchronized (mInitDeinitLock) { Preconditions.checkState(mInitState == InternalInitState.UNINITIALIZED, "CameraX.initInternal() should only be called once per instance"); mInitState = InternalInitState.INITIALIZING; return CallbackToFutureAdapter.getFuture( completer -> { mCameraExecutor.execute(() -> { <START> Exception e = null; do { mContext = context.getApplicationContext(); mCameraFactory = appConfig.getCameraFactory(null); if (mCameraFactory == null) { e = new IllegalArgumentException( "Invalid app configuration provided. Missing " + "CameraFactory."); break; } mSurfaceManager = appConfig.getDeviceSurfaceManager(null); if (mSurfaceManager == null) { e = new IllegalArgumentException( "Invalid app configuration provided. Missing " + "CameraDeviceSurfaceManager."); break; } mSurfaceManager.init(); mDefaultConfigFactory = appConfig.getUseCaseConfigRepository(null); if (mDefaultConfigFactory == null) { e = new IllegalArgumentException( "Invalid app configuration provided. Missing " + "UseCaseConfigFactory."); break; } if (mCameraExecutor instanceof CameraExecutor) { CameraExecutor executor = (CameraExecutor) mCameraExecutor; executor.init(mCameraFactory); } mCameraRepository.init(mCameraFactory); } while (false); synchronized (mInitDeinitLock) { mInitState = InternalInitState.INITIALIZED; } <END> if (e != null) { completer.setException(e); } else { completer.set(null); } }); return "CameraX initInternal"; }); } }</code><technical_language>Another option instead of: do { ... initialization code 'break' ... } while(false); mInitState = InternalInitState.INITIALIZED; ... set result future ... accomplish with: try { ... initialization code 'return' ... } finally { mInitState = InternalInitState.INITIALIZED; ... set result future ... }</technical_language>

Target:
private ListenableFuture<Void> initInternal(Context context, AppConfig appConfig) { synchronized (mInitDeinitLock) { Preconditions.checkState(mInitState == InternalInitState.UNINITIALIZED, "CameraX.initInternal() should only be called once per instance"); mInitState = InternalInitState.INITIALIZING; return CallbackToFutureAdapter.getFuture( completer -> { mCameraExecutor.execute(() -> { Exception e = null; try { mContext = context.getApplicationContext(); mCameraFactory = appConfig.getCameraFactory(null); if (mCameraFactory == null) { e = new IllegalArgumentException( "Invalid app configuration provided. Missing " + "CameraFactory."); return; } mSurfaceManager = appConfig.getDeviceSurfaceManager(null); if (mSurfaceManager == null) { e = new IllegalArgumentException( "Invalid app configuration provided. Missing " + "CameraDeviceSurfaceManager."); return; } mSurfaceManager.init(); mDefaultConfigFactory = appConfig.getUseCaseConfigRepository(null); if (mDefaultConfigFactory == null) { e = new IllegalArgumentException( "Invalid app configuration provided. Missing " + "UseCaseConfigFactory."); return; } if (mCameraExecutor instanceof CameraExecutor) { CameraExecutor executor = (CameraExecutor) mCameraExecutor; executor.init(mCameraFactory); } mCameraRepository.init(mCameraFactory); } finally { synchronized (mInitDeinitLock) { mInitState = InternalInitState.INITIALIZED; } if (e != null) { completer.setException(e); } else { completer.set(null); } } }); return "CameraX initInternal"; }); } }