{"record":{"id":"941458159569ae2a","repo":"MuntashirAkon/AppManager","slug":"empty-display-name","errorCode":null,"errorMessage":"Empty display name.","messagePattern":"Empty display name\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/io/PathImpl.java","lineNumber":366,"sourceCode":"                return f.createNewFile();\n            } catch (IOException | SecurityException e) {\n                return false;\n            }\n        }\n        // In other cases, open OutputStream to make the file empty.\n        // We can directly use openOutputStream because if it were a mount point, it would be a directory.\n        try (OutputStream ignored = openOutputStream(false)) {\n            return true;\n        } catch (IOException e) {\n            return false;\n        }\n    }\n\n    @NonNull\n    public Path createNewFile(@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        return createFileAsDirectChild(context, documentFile, displayName, mimeType);\n    }\n\n    @NonNull\n    public Path createNewDirectory(@NonNull String displayName) 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        checkVfs(Paths.appendPathSegment(documentFile.getUri(), displayName));","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/io/PathImpl.java#L348-L384","documentation":"PathImpl.createNewFile(displayName, mimeType) first sanitizes the requested display name; Paths.sanitize with emptyOk=true returns null when the name is empty or reduces to nothing after removing invalid segments. The library throws this IOException to reject creating a file with no usable name.","triggerScenarios":"Calling createNewFile with an empty string, a string of only separators/invalid characters (e.g. \"/\", \"..\", trailing dots on some providers), or a name that sanitize strips entirely.","commonSituations":"Building the name from user input without validation; splitting a path and passing an empty trailing segment; trimming logic that removes all characters before the call.","solutions":["Validate the display name is non-empty and contains only valid filename characters before calling createNewFile","If the name comes from user input, show a validation error instead of calling the API","If the name may contain path segments, use createNewArbitraryFile or createDirectoriesIfRequired instead"],"exampleFix":"// before\npath.createNewFile(name, \"text/plain\"); // name may be \"\"\n// after\nif (name == null || name.trim().isEmpty()) throw new IllegalArgumentException(\"File name required\");\npath.createNewFile(name.trim(), \"text/plain\");","handlingStrategy":"validation","validationCode":"if (displayName == null || displayName.trim().isEmpty() || displayName.matches(\".*[\\\\/:*?\\\"<>|].*\")) { rejectInput(); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate filename input at the UI layer before touching the storage API","Trim user input and refuse empty results early","Avoid constructing names by joining path fragments that can yield empty segments"],"tags":["android","validation","filename"],"backgroundTag":"empty-required-field","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}