{"record":{"id":"233ea4ac0551a392","repo":"apache/hadoop","slug":"cannot-create-directory-s","errorCode":null,"errorMessage":"Cannot create directory %s","messagePattern":"Cannot create directory (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java","lineNumber":223,"sourceCode":"   * Creates a MiniKdc.\n   *\n   * @param conf MiniKdc configuration.\n   * @param workDir working directory, it should be the build directory. Under\n   * this directory an ApacheDS working directory will be created, this\n   * directory will be deleted when the MiniKdc stops.\n   * @throws Exception thrown if the MiniKdc could not be created.\n   */\n  public MiniKdc(Properties conf, File workDir) throws Exception {\n    if (!conf.keySet().containsAll(PROPERTIES)) {\n      Set<String> missingProperties = new HashSet<String>(PROPERTIES);\n      missingProperties.removeAll(conf.keySet());\n      throw new IllegalArgumentException(\"Missing configuration properties: \"\n              + missingProperties);\n    }\n    this.workDir = new File(workDir, Long.toString(System.currentTimeMillis()));\n    if (!this.workDir.exists()\n            && !this.workDir.mkdirs()) {\n      throw new RuntimeException(\"Cannot create directory \" + this.workDir);\n    }\n    LOG.info(\"Configuration:\");\n    LOG.info(\"---------------------------------------------------------------\");\n    for (Map.Entry<?, ?> entry : conf.entrySet()) {\n      LOG.info(\"  {}: {}\", entry.getKey(), entry.getValue());\n    }\n    LOG.info(\"---------------------------------------------------------------\");\n    this.conf = conf;\n    port = Integer.parseInt(conf.getProperty(KDC_PORT));\n    String orgName= conf.getProperty(ORG_NAME);\n    String orgDomain = conf.getProperty(ORG_DOMAIN);\n    realm = orgName.toUpperCase(Locale.ENGLISH) + \".\"\n            + orgDomain.toUpperCase(Locale.ENGLISH);\n  }\n\n  /**\n   * Returns the port of the MiniKdc.\n   *","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java#L205-L241","documentation":"Thrown by the MiniKdc constructor (hadoop-minikdc) when the timestamped working directory it creates under the supplied workDir cannot be created: the path does not exist and File.mkdirs() returned false. The RuntimeException aborts KDC construction before any further configuration, so the whole Kerberos test fixture fails to initialize.","triggerScenarios":"Calling new MiniKdc(conf, workDir) where the subdirectory workDir/<System.currentTimeMillis()> cannot be created: the JVM lacks write permission on workDir, workDir is on a read-only mount, a plain file already occupies the exact timestamped name, or the parent chain cannot be created (disk full, quota).","commonSituations":"Kerberos-enabled Hadoop unit tests in CI containers where the build output directory is not writable; passing a shared read-only directory as workDir; path-length or locking quirks on Windows; parallel JVMs racing on the same millisecond-timestamped name.","solutions":["Verify the workDir passed to the MiniKdc constructor is writable by the test JVM and pre-create it with Files.createDirectories before constructing MiniKdc","Pass an explicit per-test directory (e.g. build output + test method name) instead of a fixed shared path","Check for a plain file occupying the target path, and for free disk space / quota on the filesystem holding workDir","In containers, point workDir at a writable volume or temp directory (e.g. Files.createTempDirectory)"],"exampleFix":"// before\nnew MiniKdc(conf, new File(\"/shared/readonly/dir\"));\n\n// after\nFile workDir = new File(\"target\", \"minikdc-\" + System.currentTimeMillis());\nFiles.createDirectories(workDir.toPath());\nif (!Files.isWritable(workDir.toPath())) {\n  throw new IllegalStateException(\"workDir not writable: \" + workDir);\n}\nnew MiniKdc(conf, workDir);","handlingStrategy":"validation","validationCode":"File workDir = new File(\"target/minikdc\");\nFiles.createDirectories(workDir.toPath());\nif (!Files.isWritable(workDir.toPath())) {\n  throw new IllegalStateException(\"MiniKdc workDir not writable: \" + workDir);\n}\nnew MiniKdc(conf, workDir);","typeGuard":null,"tryCatchPattern":"catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot create directory\")) {\n    // fix permissions / pick another workDir, then retry construction\n  }\n  throw e;\n}","preventionTips":["Always pass a freshly created, writable workDir (e.g. Files.createTempDirectory or target/<test-name>) to MiniKdc","Keep MiniKdc working directories inside the build output dir so CI sandboxing stays writable","Run CI containers with a writable volume for the build directory"],"tags":["kerberos","minikdc","test-infrastructure","filesystem","permissions"],"backgroundTag":"cannot-create-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}