{"record":{"id":"2be9f635623a034e","repo":"JetBrains/intellij-community","slug":"home-directory-is-not-specified-for-jdk","errorCode":null,"errorMessage":"Home directory is not specified for JDK","messagePattern":"Home directory is not specified for JDK","errorType":"exception","errorClass":"CantRunException","httpStatus":null,"severity":"error","filePath":"java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java","lineNumber":48,"sourceCode":"import java.util.LinkedHashSet;\nimport java.util.Set;\n\npublic class JavaParameters extends SimpleJavaParameters {\n  private static final Logger LOG = Logger.getInstance(JavaParameters.class);\n  private static final String JAVA_LIBRARY_PATH_PROPERTY = \"java.library.path\";\n\n  public static final String JAVA_ENABLE_PREVIEW_PROPERTY = \"--enable-preview\";\n  public static final DataKey<JavaParameters> JAVA_PARAMETERS = DataKey.create(\"javaParameters\");\n\n  public String getJdkPath() throws CantRunException {\n    final Sdk jdk = getJdk();\n    if (jdk == null) {\n      throw new CantRunException(ExecutionBundle.message(\"no.jdk.specified..error.message\"));\n    }\n\n    final VirtualFile jdkHome = jdk.getHomeDirectory();\n    if (jdkHome == null) {\n      throw new CantRunException(ExecutionBundle.message(\"home.directory.not.specified.for.jdk.error.message\"));\n    }\n    return jdkHome.getPresentableUrl();\n  }\n\n  public static final int JDK_ONLY = 0x1;\n  public static final int CLASSES_ONLY = 0x2;\n  public static final int TESTS_ONLY = 0x4;\n  public static final int INCLUDE_PROVIDED = 0x8;\n  public static final int JDK_AND_CLASSES = JDK_ONLY | CLASSES_ONLY;\n  public static final int JDK_AND_CLASSES_AND_TESTS = JDK_ONLY | CLASSES_ONLY | TESTS_ONLY;\n  public static final int CLASSES_AND_TESTS = CLASSES_ONLY | TESTS_ONLY;\n  public static final int JDK_AND_CLASSES_AND_PROVIDED = JDK_ONLY | CLASSES_ONLY | INCLUDE_PROVIDED;\n\n  public void configureByModule(Module module,\n                                @MagicConstant(valuesFromClass = JavaParameters.class) int classPathType,\n                                Sdk jdk) throws CantRunException {\n    if ((classPathType & JDK_ONLY) != 0) {\n      if (jdk == null) {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java#L30-L66","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (creating an SDK without a home)\nSdkType javaType = JavaSdk.getInstance();\nSdk sdk = ProjectJdkTable.getInstance().createSdk(\"my-jdk\", javaType);\nProjectJdkTable.getInstance().addJdk(sdk);\nparams.setJdk(sdk);\nparams.getJdkPath(); // home directory is not specified\n\n// after\nSdkModificator mod = sdk.getSdkModificator();\nmod.setHomePath(\"/usr/lib/jvm/jbr-21\");\nApplicationManager.getApplication().runWriteAction(mod::commitChanges);\nparams.setJdk(sdk);\nparams.getJdkPath();","handlingStrategy":"validation","validationCode":"Sdk jdk = params.getJdk();\nif (jdk != null) {\n  String home = jdk.getHomePath();\n  if (home == null || !new File(home).isDirectory()) {\n    // prompt to fix SDK home before getJdkPath()\n  }\n}","typeGuard":"static boolean hasValidJdkHome(@NotNull Sdk jdk) {\n  String home = jdk.getHomePath();\n  return home != null && new File(home).isDirectory();\n}","tryCatchPattern":"try {\n  return params.getJdkPath();\n} catch (CantRunException e) {\n  if (e.getMessage().contains(\"Home directory\")) {\n    // guide user to Project Structure > SDKs to fix the path\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["java","jdk","sdk","invalid-path","intellij"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}