apache/hadoop · error · RuntimeException
Cannot create directory %s
Error message
Cannot create directory %s
What it means
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.
Source
Thrown at hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java:223
* Creates a MiniKdc.
*
* @param conf MiniKdc configuration.
* @param workDir working directory, it should be the build directory. Under
* this directory an ApacheDS working directory will be created, this
* directory will be deleted when the MiniKdc stops.
* @throws Exception thrown if the MiniKdc could not be created.
*/
public MiniKdc(Properties conf, File workDir) throws Exception {
if (!conf.keySet().containsAll(PROPERTIES)) {
Set<String> missingProperties = new HashSet<String>(PROPERTIES);
missingProperties.removeAll(conf.keySet());
throw new IllegalArgumentException("Missing configuration properties: "
+ missingProperties);
}
this.workDir = new File(workDir, Long.toString(System.currentTimeMillis()));
if (!this.workDir.exists()
&& !this.workDir.mkdirs()) {
throw new RuntimeException("Cannot create directory " + this.workDir);
}
LOG.info("Configuration:");
LOG.info("---------------------------------------------------------------");
for (Map.Entry<?, ?> entry : conf.entrySet()) {
LOG.info(" {}: {}", entry.getKey(), entry.getValue());
}
LOG.info("---------------------------------------------------------------");
this.conf = conf;
port = Integer.parseInt(conf.getProperty(KDC_PORT));
String orgName= conf.getProperty(ORG_NAME);
String orgDomain = conf.getProperty(ORG_DOMAIN);
realm = orgName.toUpperCase(Locale.ENGLISH) + "."
+ orgDomain.toUpperCase(Locale.ENGLISH);
}
/**
* Returns the port of the MiniKdc.
*View on GitHub (pinned to 2add963021)
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)
Example fix
// before
new MiniKdc(conf, new File("/shared/readonly/dir"));
// after
File workDir = new File("target", "minikdc-" + System.currentTimeMillis());
Files.createDirectories(workDir.toPath());
if (!Files.isWritable(workDir.toPath())) {
throw new IllegalStateException("workDir not writable: " + workDir);
}
new MiniKdc(conf, workDir); Defensive patterns
Strategy: validation
Validate before calling
File workDir = new File("target/minikdc");
Files.createDirectories(workDir.toPath());
if (!Files.isWritable(workDir.toPath())) {
throw new IllegalStateException("MiniKdc workDir not writable: " + workDir);
}
new MiniKdc(conf, workDir); Try / catch
catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Cannot create directory")) {
// fix permissions / pick another workDir, then retry construction
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Already started
- Mkdirs failed to create {} (exists={}, cwd={})
- Permission denied: user=%s, path="%s":%s:%s:%s%s
- {} doesn't support modifyAclEntries
- {} doesn't support removeAclEntries
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/233ea4ac0551a392.
Report an issue: GitHub.