JetBrains/intellij-community · error · CantRunException

No JDK specified

Error message

No JDK specified

What it means

Thrown by JavaParameters.getJdkPath() when the run configuration's JavaParameters has no SDK attached (getJdk() returns null). IntelliJ refuses to build the Java command line because there is no java executable to launch. It is a CantRunException, so the run process aborts before the JVM starts.

Source

Thrown at java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java:43

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

public class JavaParameters extends SimpleJavaParameters {
  private static final Logger LOG = Logger.getInstance(JavaParameters.class);
  private static final String JAVA_LIBRARY_PATH_PROPERTY = "java.library.path";

  public static final String JAVA_ENABLE_PREVIEW_PROPERTY = "--enable-preview";
  public static final DataKey<JavaParameters> JAVA_PARAMETERS = DataKey.create("javaParameters");

  public String getJdkPath() throws CantRunException {
    final Sdk jdk = getJdk();
    if (jdk == null) {
      throw new CantRunException(ExecutionBundle.message("no.jdk.specified..error.message"));
    }

    final VirtualFile jdkHome = jdk.getHomeDirectory();
    if (jdkHome == null) {
      throw new CantRunException(ExecutionBundle.message("home.directory.not.specified.for.jdk.error.message"));
    }
    return jdkHome.getPresentableUrl();
  }

  public static final int JDK_ONLY = 0x1;
  public static final int CLASSES_ONLY = 0x2;
  public static final int TESTS_ONLY = 0x4;
  public static final int INCLUDE_PROVIDED = 0x8;
  public static final int JDK_AND_CLASSES = JDK_ONLY | CLASSES_ONLY;
  public static final int JDK_AND_CLASSES_AND_TESTS = JDK_ONLY | CLASSES_ONLY | TESTS_ONLY;
  public static final int CLASSES_AND_TESTS = CLASSES_ONLY | TESTS_ONLY;
  public static final int JDK_AND_CLASSES_AND_PROVIDED = JDK_ONLY | CLASSES_ONLY | INCLUDE_PROVIDED;

View on GitHub (pinned to be881553f2)

Solutions

  1. Open File > Project Structure > Project and set a valid Project SDK
  2. In the Run/Debug Configuration, set the JRE/JDK field to a concrete SDK instead of '<No JDK>'
  3. Check the module's Dependencies tab (Project Structure > Modules) and set 'Module SDK' explicitly instead of inheriting
  4. If the SDK is defined but broken, remove and re-add it in File > Project Structure > SDKs (point it at a real JDK home)
  5. In plugin code, call parameters.configureByModule(module, JavaParameters.JDK_AND_CLASSES, ...) or verify parameters.getJdk() != null before getJdkPath()

Example fix

// before
JavaParameters params = new JavaParameters();
params.getClassPath().add(dir);
String jdkPath = params.getJdkPath(); // CantRunException: No JDK specified

// after
JavaParameters params = new JavaParameters();
Sdk jdk = ProjectRootManager.getInstance(project).getProjectSdk();
if (jdk == null) throw new CantRunException("No project SDK configured");
params.setJdk(jdk);
String jdkPath = params.getJdkPath();
Defensive patterns

Strategy: try-catch

Validate before calling

Sdk jdk = params.getJdk();
if (jdk == null) {
  jdk = ProjectRootManager.getInstance(project).getProjectSdk();
}
if (jdk == null) {
  // show SDK picker / log and abort before calling getJdkPath()
  return;
}

Type guard

static boolean hasJdk(@NotNull JavaParameters params) {
  return params.getJdk() != null;
}

Try / catch

try {
  String path = params.getJdkPath();
} catch (CantRunException e) {
  // surface a 'configure SDK' prompt; do not retry silently
  Messages.showErrorDialog(project, e.getMessage(), "Cannot Run");
}

Prevention

When it happens

Trigger: Calling JavaParameters.getJdkPath() (directly or via a Java run configuration starter that resolves the JDK path) when setJdk()/configureByModule()/configureByProject() never set an SDK, or the module/project JDK resolved to null (e.g. 'No JDK' project SDK and module inherits SDK).

Common situations: Newly created project with no Project SDK configured; run configuration with JDK selector left on '<No JDK>' or a deleted/invalid SDK name; module SDK set to inherit while project SDK is undefined; plugin code building JavaParameters manually without calling configureByModule.

Related errors


AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14). Data as JSON: /api/errors/d87690438607f621. Report an issue: GitHub.