MuntashirAkon/AppManager · error · IllegalArgumentException
Display name contains file separator.
Error message
Display name contains file separator.
What it means
findOrCreateFile() requires a single-segment display name; if the sanitized name still contains the file separator character it throws IllegalArgumentException("Display name contains file separator."). Nested paths must be created level by level. This is a path-traversal/nesting guard.
Source
Thrown at app/src/main/java/io/github/muntashirakon/io/PathImpl.java:484
}
@NonNull
public Path findFile(@NonNull String displayName) throws FileNotFoundException {
DocumentFile nextPath = findFileInternal(documentFile, displayName);
if (nextPath == null) {
throw new FileNotFoundException("Cannot find " + this + File.separatorChar + displayName);
}
return new PathImpl(context, nextPath);
}
@NonNull
public Path findOrCreateFile(@NonNull String displayName, @Nullable String mimeType) throws IOException {
displayName = Paths.sanitize(displayName, true);
if (displayName == null) {
throw new IOException("Empty display name.");
}
if (displayName.indexOf(File.separatorChar) != -1) {
throw new IllegalArgumentException("Display name contains file separator.");
}
DocumentFile documentFile = getRealDocumentFile(this.documentFile);
if (!documentFile.isDirectory()) {
throw new IOException("Current file is not a directory.");
}
String extension = null;
if (mimeType != null) {
extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);
} else mimeType = DEFAULT_MIME;
String nameWithExtension = displayName + (extension != null ? "." + extension : "");
checkVfs(Paths.appendPathSegment(documentFile.getUri(), nameWithExtension));
DocumentFile file = documentFile.findFile(displayName);
if (file != null) {
if (file.isDirectory()) {
throw new IOException("Directory cannot be converted to file");
}
return new PathImpl(context, file);
}View on GitHub (pinned to 0152f468fc)
Solutions
- Extract only the final segment (substring after last separator) before calling.
- Create intermediate directories with createDirectories/findOrCreateDirectory first, then findOrCreateFile on the leaf name.
- Replace or reject separator characters in user-derived filenames at input time.
- Use Paths helpers to split the path rather than manual string handling.
Example fix
// before
path.findOrCreateFile("sub/dir/file.txt", mime); // IllegalArgumentException
// after
path.createDirectories("sub/dir");
path.findOrCreateDirectory("dir"); // on the sub Path
String leaf = new File("sub/dir/file.txt").getName();
leafPath.findOrCreateFile(leaf, mime); Defensive patterns
Strategy: validation
Validate before calling
if (displayName.indexOf(File.separatorChar) != -1) {
throw new IllegalArgumentException("Expected a single-segment file name: " + displayName);
} Type guard
boolean isSingleSegment(String n) { return n != null && n.indexOf(File.separatorChar) == -1; } Try / catch
try { dir.findOrCreateFile(name, mime); } catch (IllegalArgumentException e) { /* split path, create dirs, retry on leaf */ } Prevention
- Always take the leaf via lastIndexOf(separator)
- Create parent directories explicitly first
- Never join base dir + filename before calling
When it happens
Trigger: Calling findOrCreateFile with names like "sub/dir/file.txt" or an absolute path "/data/file.txt" — anything containing File.separatorChar after sanitization.
Common situations: Passing a full path where only a filename is expected (common when reusing Path handling code); joining base dir and filename with "/" yourself; names taken from URLs containing slashes.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Display name is empty
- Couldn't find any writable Obb dir
- Could not delete the selected backups
- Data directory cannot be empty.
- Could not create package staging directory
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/769bbdafe54d6754.
Report an issue: GitHub.