void (@NotNull Sdk sdk) { Runnable sdkSetter = ()->{ String homePath = sdk.getHomePath(); assert homePath != null : sdk; Path jdkHome = Path.of(homePath); SdkModificator sdkModificator = sdk.getSdkModificator(); List<String> classes = findClasses(jdkHome, false); Set<String> previousRoots = new LinkedHashSet<>(Arrays.asList(sdkModificator.getUrls(OrderRootType.CLASSES))); sdkModificator.removeRoots(OrderRootType.CLASSES); previousRoots.removeAll(new HashSet<>(classes)); for (String url : classes) { sdkModificator.addRoot(url, OrderRootType.CLASSES); } for (String url : previousRoots) { sdkModificator.addRoot(url, OrderRootType.CLASSES); } addSources(jdkHome, sdkModificator); addDocs(jdkHome, sdkModificator, sdk); attachJdkAnnotations(sdkModificator); ApplicationManager.getApplication().invokeAndWait(() -> { ApplicationManager.getApplication().runWriteAction(() -> sdkModificator.commitChanges()); }); }; Application application = ApplicationManager.getApplication(); if (application.isDispatchThread()) { //com.intellij.openapi.projectRoots.impl.UnknownMissingSdkFixLocal.applyLocalFix run everything in EDT, //because some extensions need to show notifications ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { sdkSetter.run(); return null; }, ProjectBundle.message("sdk.lookup.resolving.sdk.progress", sdk.getName()), false, null); } else { sdkSetter.run(); } }