{"record":{"id":"3b48093ad506236f","repo":"MuntashirAkon/AppManager","slug":"exists-and-it-is-not-a-directory","errorCode":null,"errorMessage":" exists and it is not a directory.","messagePattern":" exists and it is not a directory\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/io/PathImpl.java","lineNumber":1347,"sourceCode":"            return null;\n        }\n        // FIXME: 9/9/23 This doesn't actually work for content URIs\n        Uri parentUri = Paths.removeLastPathSegment(mountPoint);\n        return new PathImpl(context, parentUri).documentFile;\n    }\n\n    @NonNull\n    private static DocumentFile createArbitraryDirectories(@NonNull DocumentFile documentFile,\n                                                           @NonNull String[] names,\n                                                           int length) throws IOException {\n        DocumentFile file = getRealDocumentFile(documentFile);\n        for (int i = 0; i < length; ++i) {\n            Path fsRoot = VirtualFileSystem.getFsRoot(Paths.appendPathSegment(file.getUri(), names[i]));\n            DocumentFile t = fsRoot != null ? fsRoot.documentFile : file.findFile(names[i]);\n            if (t == null) {\n                t = file.createDirectory(names[i]);\n            } else if (!t.isDirectory()) {\n                throw new IOException(t.getUri() + \" exists and it is not a directory.\");\n            }\n            if (t == null) {\n                throw new IOException(\"Could not create directory \" + file.getUri() + File.separatorChar + names[i]);\n            }\n            file = t;\n        }\n        return file;\n    }\n\n    @NonNull\n    private static DocumentFile getRealDocumentFile(@NonNull DocumentFile documentFile) {\n        Path fsRoot = VirtualFileSystem.getFsRoot(documentFile.getUri());\n        if (fsRoot != null) {\n            return fsRoot.documentFile;\n        }\n        return documentFile;\n    }\n","sourceCodeStart":1329,"sourceCodeEnd":1365,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/io/PathImpl.java#L1329-L1365","documentation":"Thrown by PathImpl's mkdirs helper when an intermediate path segment already exists but is a regular file rather than a directory. While creating the directory chain, the library finds an existing document with the segment's name whose isDirectory() is false and aborts rather than overwrite.","triggerScenarios":"Calling Path.createDirectories()/createDirectoryAndParents-style APIs where a component of the path (e.g. 'a/b/c' with 'a/b' being an existing file) collides with an existing non-directory document.","commonSituations":"Path layout changed between app versions (old file now sits where a folder is expected); data restored from backup creating files where directories should be; typos causing name collisions with existing files.","solutions":["Inspect the existing document at the colliding segment and rename/delete it if appropriate","Use a different base directory for the new tree","Check each segment with findFile() + isDirectory() before creating to give a precise error"],"exampleFix":"// before\ndir.createDirectories(\"logs/session/x\");\n// after\nPath p = dir;\nfor (String seg : new String[]{\"logs\", \"session\", \"x\"}) {\n    Path child = p.findFile(seg);\n    if (child != null && !child.isDirectory()) {\n        throw new FileAlreadyExistsException(\"File blocks directory creation: \" + child);\n    }\n    p = (child != null) ? child : p.createDirectory(seg);\n}","handlingStrategy":"validation","validationCode":"for (String seg : segments) { Path c = base.findFile(seg); if (c != null && !c.isDirectory()) throw new FileAlreadyExistsException(seg); }","typeGuard":"null","tryCatchPattern":"try { dir.createDirectories(chain); } catch (IOException e) { logCollision(chain); throw e; }","preventionTips":["Validate the full path chain before mkdirs","Detect and report collisions with existing files to the user","Avoid reusing names across app versions for different node types"],"tags":["android","io","mkdir","name-collision"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}