Promise<Boolean> (@NotNull Sdk sdk) { return ReadAction.nonBlocking(() -> { List<String> pathsChecked = new ArrayList<>(); VirtualFile root = internalJdkAnnotationsPath(pathsChecked, false); if (root != null && !isInternalJdkAnnotationRootCorrect(root)) { root = null; } if (root == null) { String msg = "Paths checked:\n"+ StringUtil.join(pathsChecked, path -> { File file = new File(path); File parentFile = file.getParentFile(); return " "+path+"; exists: "+file.exists()+(parentFile == null ? "" : "; siblings: "+Arrays.toString(parentFile.list())); }, "\n"); LOG.error("JDK annotations not found", msg); return null; } SdkModificator modificator = sdk.getSdkModificator(); return new Pair<>(root, modificator); }) .finishOnUiThread(ModalityState.nonModal(), rootAndModifiactor -> { if (rootAndModifiactor == null) { return; } VirtualFile root = rootAndModifiactor.first; SdkModificator modificator = rootAndModifiactor.second; OrderRootType annoType = AnnotationOrderRootType.getInstance(); if (modificator.getRoots(annoType).length != 0) { modificator.removeRoot(root, annoType); } modificator.addRoot(root, annoType); }) .submit(AppExecutorUtil.getAppExecutorService()) .then(file -> file != null); }