void (@NotNull Project project, @NotNull Sdk sdk) { project.putUserData(ANNOTATIONS_BEING_ATTACHED, Boolean.TRUE); ApplicationManager.getApplication().invokeLater(() -> { JavaSdkImpl.attachIDEAAnnotationsToJdkAsync(sdk) .onSuccess(success -> { // daemon will restart automatically if (success) { SdkModificator modificator = sdk.getSdkModificator(); modificator.commitChanges(); } if (success) { ReadAction.nonBlocking(() -> { // check if we really attached the necessary annotations, to avoid IDEA-247322 return getJDKToAnnotate(project) == null; }).finishOnUiThread(ModalityState.nonModal(), hasNoJdkToAnnotate -> { if (hasNoJdkToAnnotate) { // avoid endless loop on JDK misconfiguration project.putUserData(ANNOTATIONS_BEING_ATTACHED, null); } }).inSmartMode(project) .submit(AppExecutorUtil.getAppExecutorService()); } }); }, project.getDisposed()); }