{"record":{"id":"ed061ece40f8c25b","repo":"apache/hadoop","slug":"is-not-a-file-the-directory-already-exist-at-ed061e","errorCode":null,"errorMessage":"/ is not a file. The directory / already exist at: {}","messagePattern":"/ is not a file\\. The directory / already exist at: (.+?)","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java","lineNumber":1008,"sourceCode":"    static private void checkPathIsSlash(final Path f) throws IOException {\n      if (f != InodeTree.SlashPath) {\n        throw new IOException (\n        \"Internal implementation error: expected file name to be /\" );\n      }\n    }\n\n    @Override\n    public FSDataOutputStream createInternal(final Path f,\n        final EnumSet<CreateFlag> flag, final FsPermission absolutePermission,\n        final int bufferSize, final short replication, final long blockSize,\n        final Progressable progress, final ChecksumOpt checksumOpt,\n        final boolean createParent) throws AccessControlException,\n        FileAlreadyExistsException, FileNotFoundException,\n        ParentNotDirectoryException, UnsupportedFileSystemException,\n        UnresolvedLinkException, IOException {\n      Preconditions.checkNotNull(f, \"File cannot be null.\");\n      if (InodeTree.SlashPath.equals(f)) {\n        throw new FileAlreadyExistsException(\n            \"/ is not a file. The directory / already exist at: \"\n                + theInternalDir.fullPath);\n      }\n\n      if (this.fsState.getRootFallbackLink() != null) {\n        if (theInternalDir.getChildren().containsKey(f.getName())) {\n          throw new FileAlreadyExistsException(\n              \"A mount path(file/dir) already exist with the requested path: \"\n                  + theInternalDir.getChildren().get(f.getName()).fullPath);\n        }\n\n        AbstractFileSystem linkedFallbackFs =\n            this.fsState.getRootFallbackLink().getTargetFileSystem();\n        Path parent = Path.getPathWithoutSchemeAndAuthority(\n            new Path(theInternalDir.fullPath));\n        String leaf = f.getName();\n        Path fileToCreate = new Path(parent, leaf);\n","sourceCodeStart":990,"sourceCodeEnd":1026,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java#L990-L1026","documentation":"InternalDirOfViewFs.createInternal (the FileContext-side ViewFs implementation) rejects file creation at the root of an internal mount-table directory: if the remaining path equals InodeTree.SlashPath (\"/\"), it throws FileAlreadyExistsException(\"/ is not a file. The directory / already exist at: <internalDirPath>\"). A virtual directory cannot become a file, and the root internal dir always exists.","triggerScenarios":"FileContext.create(new Path(\"viewfs:///\"), ...) or any create whose resolution leaves remainingPath==\"/\" on an internal dir (e.g. creating the mount-table node /data itself when /data only contains links); touch/mkfile-style utilities targeting the viewfs root.","commonSituations":"Job/setup scripts creating sentinel files at the namespace root; Hive staging logic computing a parent that collapses to \"/\" because the user home mount is missing.","solutions":["Create the file under a concrete mounted path (e.g. viewfs:///user/alice/marker)","Mount the intended parent directory with fs.viewfs.mounttable.<n>.link.<parent>","Check path.isRoot() before create and reject early with a clear message"],"exampleFix":"// before\nfc.create(new Path(\"viewfs:///\"), EnumSet.of(CreateFlag.CREATE)); // throws\n\n// after\nPath p = new Path(\"viewfs:///user/alice/marker\");\nif (p.isRoot()) { throw new IllegalArgumentException(\"refusing to create file at viewfs root\"); }\nfc.create(p, EnumSet.of(CreateFlag.CREATE));","handlingStrategy":"validation","validationCode":"static Path validateCreatePath(Path p) {\n  if (p.isRoot() || p.toUri().getPath().equals(\"/\")) {\n    throw new IllegalArgumentException(\"Cannot create a file at viewfs root '/': pick a mounted path\");\n  }\n  return p;\n}","typeGuard":null,"tryCatchPattern":"try {\n  out = fc.create(p, EnumSet.of(CreateFlag.CREATE));\n} catch (FileAlreadyExistsException fae) {\n  if (fae.getMessage().startsWith(\"/ is not a file\")) { /* p resolved to mount-table root */ }\n}","preventionTips":["Reject Path.isRoot() in create/touch helpers up front","Ensure job home/staging dirs are mounted so parents never collapse to '/'"],"tags":["viewfs","mount-table","file-exists","create","hadoop-common"],"backgroundTag":"file-already-exists","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}