{"record":{"id":"3846bc55fbfb5130","repo":"apache/beam","slug":"unable-to-create-parent-directories-for","errorCode":null,"errorMessage":"Unable to create parent directories for ''","messagePattern":"Unable to create parent directories for ''","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/io/LocalFileSystem.java","lineNumber":119,"sourceCode":"  @VisibleForTesting\n  List<MatchResult> match(String baseDir, List<String> specs) throws IOException {\n    ImmutableList.Builder<MatchResult> ret = ImmutableList.builder();\n    for (String spec : specs) {\n      ret.add(matchOne(baseDir, spec));\n    }\n    return ret.build();\n  }\n\n  @Override\n  protected WritableByteChannel create(LocalResourceId resourceId, CreateOptions createOptions)\n      throws IOException {\n    LOG.debug(\"creating file {}\", resourceId);\n    File absoluteFile = resourceId.getPath().toFile().getAbsoluteFile();\n    if (absoluteFile.getParentFile() != null\n        && !absoluteFile.getParentFile().exists()\n        && !absoluteFile.getParentFile().mkdirs()\n        && !absoluteFile.getParentFile().exists()) {\n      throw new IOException(\"Unable to create parent directories for '\" + resourceId + \"'\");\n    }\n    return Channels.newChannel(new BufferedOutputStream(new FileOutputStream(absoluteFile)));\n  }\n\n  @Override\n  protected ReadableByteChannel open(LocalResourceId resourceId) throws IOException {\n    LOG.debug(\"opening file {}\", resourceId);\n    @SuppressWarnings(\"resource\") // The caller is responsible for closing the channel.\n    FileInputStream inputStream = new FileInputStream(resourceId.getPath().toFile());\n    // Use this method for creating the channel (rather than new FileChannel) so that we get\n    // regular FileNotFoundException. Closing the underyling channel will close the inputStream.\n    return inputStream.getChannel();\n  }\n\n  @Override\n  protected void copy(List<LocalResourceId> srcResourceIds, List<LocalResourceId> destResourceIds)\n      throws IOException {\n    checkArgument(","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/io/LocalFileSystem.java#L101-L137","documentation":"LocalFileSystem.create attempts to mkdirs the parent directory of the target file before opening an output channel; if creation fails (and the directory still doesn't exist) it throws IOException 'Unable to create parent directories for ...'.","triggerScenarios":"Writing via FileSystems.create(LocalResourceId...) where the parent directory doesn't exist and mkdirs fails — due to missing write permission on the parent, the path component being an existing regular file, or a read-only filesystem.","commonSituations":"Writing to /tmp-like paths in sandboxed workers where permissions differ; a file exists where a directory is expected (e.g. output prefix collides with an existing file); running in containers with read-only mounts.","solutions":["Check filesystem permissions on the parent path and fix with chmod/chown or run as a user with write access","Verify no regular file exists with the same name as a required parent directory","Create the parent directories yourself before calling create and verify success","Ensure the mount point is writable inside the container/worker"],"exampleFix":"// before\nFile out = new File(\"/data/readonly/out.txt\"); // parent missing, not writable\ntry (WritableByteChannel ch = FileSystems.create(LocalResourceId.fromPath(...), \"text/plain\")) {...}\n// after\nFile parent = out.getParentFile();\nif (!parent.exists() && !parent.mkdirs()) {\n  throw new IOException(\"Cannot create \" + parent + \"; check permissions\");\n}\ntry (WritableByteChannel ch = FileSystems.create(...)) {...}","handlingStrategy":"validation","validationCode":"File parent = new File(path).getAbsoluteFile().getParentFile();\nif (parent != null && !parent.exists() && !parent.mkdirs()) {\n  throw new IOException(\"Cannot create parent dir: \" + parent + \"; check permissions/mounts\");\n}","typeGuard":null,"tryCatchPattern":"try (WritableByteChannel ch = FileSystems.create(resourceId, mimeType)) {\n  // write\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Unable to create parent directories\")) {\n    LOG.error(\"Fix permissions or create {} manually\", new File(path).getParent());\n  }\n  throw e;\n}","preventionTips":["Pre-create output directories in setup scripts with correct ownership","Ensure worker containers mount writable volumes for output paths","Verify the output prefix doesn't collide with an existing regular file","Run a smoke-test write in the target environment before production"],"tags":["java","apache-beam","local-filesystem","mkdir","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}