{"record":{"id":"671e582a11ee24ee","repo":"apache/hadoop","slug":"getserverdefaults-on-empty-path-is-invalid","errorCode":null,"errorMessage":"getServerDefaults on empty path is invalid","messagePattern":"getServerDefaults on empty path is invalid","errorType":"exception","errorClass":"NotInMountpointException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java","lineNumber":963,"sourceCode":"        throw new RuntimeException(errMsg, ex);\n      }\n    }\n    return fsMap;\n  }\n\n  @Override\n  public long getDefaultBlockSize() {\n    throw new NotInMountpointException(\"getDefaultBlockSize\");\n  }\n\n  @Override\n  public short getDefaultReplication() {\n    throw new NotInMountpointException(\"getDefaultReplication\");\n  }\n\n  @Override\n  public FsServerDefaults getServerDefaults() throws IOException {\n    throw new NotInMountpointException(\"getServerDefaults\");\n  }\n\n  @Override\n  public long getDefaultBlockSize(Path f) {\n    try {\n      InodeTree.ResolveResult<FileSystem> res =\n        fsState.resolve(getUriPath(f), true);\n      return res.targetFileSystem.getDefaultBlockSize(res.remainingPath);\n    } catch (FileNotFoundException e) {\n      throw new NotInMountpointException(f, \"getDefaultBlockSize\");\n    } catch (IOException e) {\n      throw new RuntimeException(\"Not able to initialize fs in \"\n          + \" getDefaultBlockSize for path \" + f + \" with exception\", e);\n    }\n  }\n\n  @Override\n  public short getDefaultReplication(Path f) {","sourceCodeStart":945,"sourceCodeEnd":981,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java#L945-L981","documentation":"ViewFileSystem (viewfs) is a client-side mount table that forwards each operation to the backing FileSystem of the mount point that owns the path. It has no single underlying server, so the no-argument getServerDefaults() (and the sibling no-arg getDefaultBlockSize()/getDefaultReplication()) cannot return meaningful values and always throws NotInMountpointException, an UnsupportedOperationException. Server defaults only exist per target cluster, so the path-aware overloads must be used instead.","triggerScenarios":"Calling fs.getServerDefaults(), fs.getDefaultBlockSize(), or fs.getDefaultReplication() on a FileSystem whose URI is viewfs://<cluster> (e.g. new Path(\"viewfs://cluster/\").getFileSystem(conf)). Typical producers are framework code (distcp, job submission, Hive/Spark writers) that derives default block size or replication from the default FileSystem when fs.defaultFS points at viewfs.","commonSituations":"fs.defaultFS switched to viewfs://cluster during an HDFS federation/router migration while tools still assume a plain HDFS handle; mount table without linkMergeSlash so even the root path resolves nowhere; old client code using the deprecated no-arg methods.","solutions":["Switch to the path-aware overloads on a path that resolves into a mount point: fs.getServerDefaults(new Path(\"/mounted/dir\")), fs.getDefaultBlockSize(path), fs.getDefaultReplication(path)","Add a root mount so every path resolves: set fs.viewfs.mounttable.default.linkMergeSlash=hdfs://nameservice1/ in core-site.xml","If only default values are needed, read them from the target cluster config (dfs.blocksize, dfs.replication) or from getServerDefaults() of the target HDFS FileSystem instead of the viewfs handle","As a last resort catch NotInMountpointException (or its parent UnsupportedOperationException) and fall back to known cluster defaults"],"exampleFix":"// before\nFileSystem fs = FileSystem.get(new URI(\"viewfs://cluster\"), conf);\nlong bs = fs.getDefaultBlockSize(); // throws NotInMountpointException\n\n// after\nFileSystem fs = FileSystem.get(new URI(\"viewfs://cluster\"), conf);\nlong bs = fs.getDefaultBlockSize(new Path(\"/data/somefile\")); // path inside a mount point\n// or, for cluster-wide defaults, ask the target FS directly:\n// FsServerDefaults d = fs.getServerDefaults(new Path(\"/data\"));","handlingStrategy":"try-catch","validationCode":"// No-arg server-default calls on viewfs are invalid by design; there is nothing to validate.\n// Route the call through a mounted path instead:\nPath mounted = new Path(\"viewfs://cluster/data\");\nFileSystem fs = mounted.getFileSystem(conf);\nFsServerDefaults d = fs.getServerDefaults(mounted);","typeGuard":null,"tryCatchPattern":"import org.apache.hadoop.fs.viewfs.NotInMountpointException;\ntry {\n  long bs = fs.getDefaultBlockSize();\n} catch (NotInMountpointException | UnsupportedOperationException e) {\n  // viewfs has no cluster-wide defaults; use target-cluster config\n  long bs = conf.getLongBytes(\"dfs.blocksize\", 128L * 1024 * 1024);\n}","preventionTips":["Never call the no-arg getDefaultBlockSize/getDefaultReplication/getServerDefaults on a FileSystem you did not create from a concrete HDFS URI","Wrap default-FS access in a utility that detects viewfs:// schemes and delegates to path-aware overloads","Add linkMergeSlash to the mount table so root-level default queries succeed during migrations"],"tags":["viewfs","hadoop","mount-table","configuration","server-defaults"],"backgroundTag":"viewfs-not-in-mountpoint","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}