JetBrains/intellij-community · error · CantRunException
Home directory is not specified for JDK
Error message
Home directory is not specified for JDK
What it means
Thrown by JavaParameters.getJdkPath() when an SDK instance exists but jdk.getHomeDirectory() returns null, i.e. the SDK has no valid home directory. The JDK entry is present in the model but its location is unset or does not map to a VirtualFile, so the path to the java executable cannot be resolved.
Source
Thrown at java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java:48
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;
public void configureByModule(Module module,
@MagicConstant(valuesFromClass = JavaParameters.class) int classPathType,
Sdk jdk) throws CantRunException {
if ((classPathType & JDK_ONLY) != 0) {
if (jdk == null) {View on GitHub (pinned to be881553f2)
Solutions
- Open File > Project Structure > SDKs, select the broken SDK and fix its JDK home path to an existing JDK directory
- If the JDK was uninstalled or upgraded, install it again or repoint the SDK, then re-select it in the run configuration
- In plugin code, always call sdkModificator.setHomePath(...) before sdkModificator.commitChanges()
- Check that the home path is not a symlink loop or inaccessible network mount
Example fix
// before (creating an SDK without a home)
SdkType javaType = JavaSdk.getInstance();
Sdk sdk = ProjectJdkTable.getInstance().createSdk("my-jdk", javaType);
ProjectJdkTable.getInstance().addJdk(sdk);
params.setJdk(sdk);
params.getJdkPath(); // home directory is not specified
// after
SdkModificator mod = sdk.getSdkModificator();
mod.setHomePath("/usr/lib/jvm/jbr-21");
ApplicationManager.getApplication().runWriteAction(mod::commitChanges);
params.setJdk(sdk);
params.getJdkPath(); Defensive patterns
Strategy: validation
Validate before calling
Sdk jdk = params.getJdk();
if (jdk != null) {
String home = jdk.getHomePath();
if (home == null || !new File(home).isDirectory()) {
// prompt to fix SDK home before getJdkPath()
}
} Type guard
static boolean hasValidJdkHome(@NotNull Sdk jdk) {
String home = jdk.getHomePath();
return home != null && new File(home).isDirectory();
} Try / catch
try {
return params.getJdkPath();
} catch (CantRunException e) {
if (e.getMessage().contains("Home directory")) {
// guide user to Project Structure > SDKs to fix the path
}
throw e;
} Prevention
- When creating SDKs in code, always setHomePath before commitChanges
- Avoid machine-specific absolute SDK paths in shared settings; use path variables
- After a JDK upgrade/removal, audit File > Project Structure > SDKs for red paths
When it happens
Trigger: Calling getJdkPath() on a JavaParameters whose Sdk was created with an empty/null home path, or whose home path points to a directory that no longer exists on disk (VirtualFileManager cannot materialize it), e.g. after the JDK was uninstalled or moved.
Common situations: SDK defined by path that was deleted (OS update removed /usr/lib/jvm/...); SDK cloned from shared/checked-in settings with a machine-specific path; internal SDK type that lazily resolves home and has not been resolved yet; SDK added programmatically via SdkModificator without setHomePath before commitChanges.
Related errors
- No JDK specified
- No JDK specified
- Please specify SDK name
- {2, choice, 1#flag|1<flags} ''{0}'' not allowed in ''{1}''
- unexpected character ''{0}'' in ''{1}''
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/2be9f635623a034e.
Report an issue: GitHub.