MuntashirAkon/AppManager · error · IOException
Could not create directory
Error message
Could not create directory
What it means
Thrown by PathImpl's mkdirs helper when DocumentsProvider.createDirectory() returns null for an intermediate segment, i.e. the provider could not materialize the directory. Note the null-check is unreachable in practice because createDirectory failure is usually signalled another way; it guards against providers that return null.
Source
Thrown at app/src/main/java/io/github/muntashirakon/io/PathImpl.java:1350
Uri parentUri = Paths.removeLastPathSegment(mountPoint);
return new PathImpl(context, parentUri).documentFile;
}
@NonNull
private static DocumentFile createArbitraryDirectories(@NonNull DocumentFile documentFile,
@NonNull String[] names,
int length) throws IOException {
DocumentFile file = getRealDocumentFile(documentFile);
for (int i = 0; i < length; ++i) {
Path fsRoot = VirtualFileSystem.getFsRoot(Paths.appendPathSegment(file.getUri(), names[i]));
DocumentFile t = fsRoot != null ? fsRoot.documentFile : file.findFile(names[i]);
if (t == null) {
t = file.createDirectory(names[i]);
} else if (!t.isDirectory()) {
throw new IOException(t.getUri() + " exists and it is not a directory.");
}
if (t == null) {
throw new IOException("Could not create directory " + file.getUri() + File.separatorChar + names[i]);
}
file = t;
}
return file;
}
@NonNull
private static DocumentFile getRealDocumentFile(@NonNull DocumentFile documentFile) {
Path fsRoot = VirtualFileSystem.getFsRoot(documentFile.getUri());
if (fsRoot != null) {
return fsRoot.documentFile;
}
return documentFile;
}
@Nullable
private static DocumentFile resolveFileOrNull(@NonNull DocumentFile documentFile) {
DocumentFile realDocumentFile = getRealDocumentFile(documentFile);View on GitHub (pinned to 0152f468fc)
Solutions
- Check parent.canWrite() before creating the chain
- Sanitize each segment name (avoid trailing dots/spaces and illegal characters)
- Verify free space and storage permissions
- Catch IOException and log the segment + parent URI from the message to identify the failing level
Example fix
// before
dir.createDirectories(dirName);
// after
if (!dir.canWrite()) throw new IOException("Cannot write in " + dir);
String safe = dirName.replaceAll("[\\u0000/.]+$", "");
dir.createDirectories(safe); Defensive patterns
Strategy: try-catch
Validate before calling
if (!dir.canWrite()) throw new IOException("Cannot create directories in " + dir); Type guard
boolean canMkdir(Path base, String seg) { return base.isDirectory() && base.canWrite() && !seg.isEmpty(); } Try / catch
try { dir.createDirectories(chain); } catch (IOException e) { throw new IOException("Provider failed to create directory chain under " + dir, e); } Prevention
- Sanitize segment names (strip trailing dots/spaces, illegal chars)
- Check canWrite() on the base directory first
- Verify free storage before bulk directory creation
When it happens
Trigger: Calling Path.createDirectories(...) where a segment cannot be created by the provider — read-only volume, invalid/illegal segment name for the provider, storage full, or provider bug returning null.
Common situations: Creating directories on read-only external storage; segment names with characters the provider rejects (trailing dots/spaces on some providers); low-storage devices; legacy AccessStorageFramework quirks.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- Unable to open output stream.
- Could not create directory named
- Could not resolve Uri:
- Target is not backed by a real file
- exists and it is not a directory.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/51c584a1e4286596.
Report an issue: GitHub.