{"record":{"id":"0792aaa81871e61d","repo":"apache/hadoop","slug":"already-exits","errorCode":null,"errorMessage":"/ already exits","messagePattern":"/ already exits","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java","lineNumber":1690,"sourceCode":"      long[] summary = {0, 0, 0};\n      for (FileStatus status : listStatus(p)) {\n        Path targetPath =\n            Path.getPathWithoutSchemeAndAuthority(status.getPath());\n        InodeTree.ResolveResult<FileSystem> res =\n            fsState.resolve(targetPath.toString(), true);\n        FsStatus child = res.targetFileSystem.getStatus(res.remainingPath);\n        summary[0] += child.getCapacity();\n        summary[1] += child.getUsed();\n        summary[2] += child.getRemaining();\n      }\n      return new FsStatus(summary[0], summary[1], summary[2]);\n    }\n\n    @Override\n    public boolean mkdirs(Path dir, FsPermission permission)\n        throws IOException {\n      if (theInternalDir.isRoot() && dir == null) {\n        throw new FileAlreadyExistsException(\"/ already exits\");\n      }\n      // Note dir starts with /\n      if (theInternalDir.getChildren().containsKey(\n          dir.toString().substring(1))) {\n        return true; // this is the stupid semantics of FileSystem\n      }\n\n      if (this.fsState.getRootFallbackLink() != null) {\n        FileSystem linkedFallbackFs =\n            this.fsState.getRootFallbackLink().getTargetFileSystem();\n        Path parent = Path.getPathWithoutSchemeAndAuthority(\n            new Path(theInternalDir.fullPath));\n        String leafChild = (InodeTree.SlashPath.equals(dir)) ?\n            InodeTree.SlashPath.toString() :\n            dir.getName();\n        Path dirToCreate = new Path(parent, leafChild);\n\n        try {","sourceCodeStart":1672,"sourceCodeEnd":1708,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java#L1672-L1708","documentation":"ViewFileSystem.InternalDir.mkdirs guards against a null directory argument at the mount-table root with FileAlreadyExistsException('/ already exits') (message typo is in the source). The root internal dir always exists, so creating it is a no-op at best; a null dir indicates a caller bug and is rejected explicitly.","triggerScenarios":"Some caller invokes mkdirs(null) on a FileSystem that resolves to the viewfs root internal dir - typically a wrapper that stripped a path component and passed null, or custom code that assumes mkdirs accepts null. The check only fires when theInternalDir.isRoot() and dir == null.","commonSituations":"Buggy path-manipulation code building parent paths and passing null for the root; older third-party libraries calling mkdirs with a possibly-null Path; rarely hit because it requires both root internal dir and null argument.","solutions":["Fix the caller to pass a concrete Path; FileSystem.mkdirs(null) is invalid API use","Add a null/empty guard before calling mkdirs and construct the intended directory path explicitly","If the intent was to ensure '/', drop the call - the viewfs root always exists","Catch FileAlreadyExistsException defensively in generic filesystem wrappers and log the offending argument"],"exampleFix":"// before\nfs.mkdirs(null); // caller bug -> FileAlreadyExistsException(\"/ already exits\")\n\n// after\nPath dir = targetDir != null ? targetDir : new Path(\"/\");\nif (!dir.isRoot()) {\n  fs.mkdirs(dir);\n}","handlingStrategy":"validation","validationCode":"// Null-check before mkdirs\njava.util.Objects.requireNonNull(dir, \"mkdirs target must not be null\");\nif (!dir.isRoot()) {\n  fs.mkdirs(dir);\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.mkdirs(dir);\n} catch (FileAlreadyExistsException e) {\n  // dir was null or '/' on the viewfs root internal dir: nothing to create\n  LOG.debug(\"root exists; skipping mkdirs\", e);\n}","preventionTips":["Never pass null paths to FileSystem APIs; validate arguments at wrapper boundaries","The viewfs root always exists - drop redundant mkdirs('/') calls","Unit-test path-building helpers for the empty/root case"],"tags":["viewfs","hadoop","mkdir","null-argument","api-misuse"],"backgroundTag":"file-already-exists","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}