{"record":{"id":"769bbdafe54d6754","repo":"MuntashirAkon/AppManager","slug":"display-name-contains-file-separator","errorCode":null,"errorMessage":"Display name contains file separator.","messagePattern":"Display name contains file separator\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/io/PathImpl.java","lineNumber":484,"sourceCode":"    }\n\n    @NonNull\n    public Path findFile(@NonNull String displayName) throws FileNotFoundException {\n        DocumentFile nextPath = findFileInternal(documentFile, displayName);\n        if (nextPath == null) {\n            throw new FileNotFoundException(\"Cannot find \" + this + File.separatorChar + displayName);\n        }\n        return new PathImpl(context, nextPath);\n    }\n\n    @NonNull\n    public Path findOrCreateFile(@NonNull String displayName, @Nullable String mimeType) throws IOException {\n        displayName = Paths.sanitize(displayName, true);\n        if (displayName == null) {\n            throw new IOException(\"Empty display name.\");\n        }\n        if (displayName.indexOf(File.separatorChar) != -1) {\n            throw new IllegalArgumentException(\"Display name contains file separator.\");\n        }\n        DocumentFile documentFile = getRealDocumentFile(this.documentFile);\n        if (!documentFile.isDirectory()) {\n            throw new IOException(\"Current file is not a directory.\");\n        }\n        String extension = null;\n        if (mimeType != null) {\n            extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);\n        } else mimeType = DEFAULT_MIME;\n        String nameWithExtension = displayName + (extension != null ? \".\" + extension : \"\");\n        checkVfs(Paths.appendPathSegment(documentFile.getUri(), nameWithExtension));\n        DocumentFile file = documentFile.findFile(displayName);\n        if (file != null) {\n            if (file.isDirectory()) {\n                throw new IOException(\"Directory cannot be converted to file\");\n            }\n            return new PathImpl(context, file);\n        }","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/io/PathImpl.java#L466-L502","documentation":"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.","triggerScenarios":"Calling findOrCreateFile with names like \"sub/dir/file.txt\" or an absolute path \"/data/file.txt\" — anything containing File.separatorChar after sanitization.","commonSituations":"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.","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."],"exampleFix":"// before\npath.findOrCreateFile(\"sub/dir/file.txt\", mime); // IllegalArgumentException\n// after\npath.createDirectories(\"sub/dir\");\npath.findOrCreateDirectory(\"dir\"); // on the sub Path\nString leaf = new File(\"sub/dir/file.txt\").getName();\nleafPath.findOrCreateFile(leaf, mime);","handlingStrategy":"validation","validationCode":"if (displayName.indexOf(File.separatorChar) != -1) {\n    throw new IllegalArgumentException(\"Expected a single-segment file name: \" + displayName);\n}","typeGuard":"boolean isSingleSegment(String n) { return n != null && n.indexOf(File.separatorChar) == -1; }","tryCatchPattern":"try { dir.findOrCreateFile(name, mime); } catch (IllegalArgumentException e) { /* split path, create dirs, retry on leaf */ }","preventionTips":["Always take the leaf via lastIndexOf(separator)","Create parent directories explicitly first","Never join base dir + filename before calling"],"tags":["android","filesystem","illegal-argument","path"],"backgroundTag":"invalid-argument-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}