Skip to content

Commit

Permalink
[global inspections] check sdk configurations under progress
Browse files Browse the repository at this point in the history
avoid index access from EDT

GitOrigin-RevId: 63a7a4ef90435465d4a7d2fd707a8800d6d6e8b9
  • Loading branch information
akozlova authored and intellij-monorepo-bot committed Jun 18, 2021
1 parent 5de14cb commit 45a689d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.ex;

import com.intellij.CommonBundle;
Expand All @@ -19,6 +19,9 @@
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdk;
Expand Down Expand Up @@ -186,18 +189,25 @@ else if (entry instanceof LibraryOrderEntry) {
}

private static boolean isBadSdk(Project project, Module[] modules) {
boolean anyModuleAcceptsSdk = false;
boolean anyModuleUsesProjectSdk = false;
Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
for (Module module : modules) {
if (ModuleRootManager.getInstance(module).isSdkInherited()) {
anyModuleUsesProjectSdk = true;
if (ModuleType.get(module).isValidSdk(module, projectSdk)) {
anyModuleAcceptsSdk = true;
return ProgressManager.getInstance().run(new Task.WithResult<Boolean, RuntimeException>(project,
JavaBundle.message("dialog.title.check.configuration"), true) {
@Override
protected Boolean compute(@NotNull ProgressIndicator indicator) throws RuntimeException {
boolean anyModuleAcceptsSdk = false;
boolean anyModuleUsesProjectSdk = false;
Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
for (Module module : modules) {
if (ModuleRootManager.getInstance(module).isSdkInherited()) {
anyModuleUsesProjectSdk = true;
if (ModuleType.get(module).isValidSdk(module, projectSdk)) {
anyModuleAcceptsSdk = true;
}
}
}
return anyModuleUsesProjectSdk && !anyModuleAcceptsSdk;
}
}
return anyModuleUsesProjectSdk && !anyModuleAcceptsSdk;
});

}

private static <T> void enqueueRequestImpl(RefElement refElement, Map<SmartPsiElementPointer<?>, List<T>> requestMap, T processor) {
Expand Down
1 change: 1 addition & 0 deletions java/openapi/resources/messages/JavaBundle.properties
Expand Up @@ -1641,3 +1641,4 @@ conflict.message.method.will.override.method.base.class=Renamed {0} will overrid
annotations.panel.used.for.code.generation=Used for code generation
annotations.panel.use.for.code.generation=Use for Code Generation
progress.title.looking.for.jdk=Looking for JDK...
dialog.title.check.configuration=Check Configuration...

0 comments on commit 45a689d

Please sign in to comment.