{"record":{"id":"ef6fbe8d0073292c","repo":"apache/hadoop","slug":"filesystem-is-not-a-dfs","errorCode":null,"errorMessage":"FileSystem {} is not a DFS.","messagePattern":"FileSystem (.+?) is not a DFS\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/HAUtil.java","lineNumber":271,"sourceCode":"    // Check whether the failover proxy provider uses logical URI.\n    return provider.useLogicalURI();\n  }\n\n  /**\n   * Get the internet address of the currently-active NN. This should rarely be\n   * used, since callers of this method who connect directly to the NN using the\n   * resulting InetSocketAddress will not be able to connect to the active NN if\n   * a failover were to occur after this method has been called.\n   * \n   * @param fs the file system to get the active address of.\n   * @return the internet address of the currently-active NN.\n   * @throws IOException if an error occurs while resolving the active NN.\n   */\n  public static InetSocketAddress getAddressOfActive(FileSystem fs)\n      throws IOException {\n    InetSocketAddress inAddr = null;\n    if (!(fs instanceof DistributedFileSystem)) {\n      throw new IllegalArgumentException(\"FileSystem \" + fs + \" is not a DFS.\");\n    }\n    // force client address resolution.\n    fs.exists(new Path(\"/\"));\n    DistributedFileSystem dfs = (DistributedFileSystem) fs;\n    Configuration dfsConf = dfs.getConf();\n    URI dfsUri = dfs.getUri();\n    String nsId = dfsUri.getHost();\n    if (isHAEnabled(dfsConf, nsId)) {\n      List<ClientProtocol> namenodes =\n          getProxiesForAllNameNodesInNameservice(dfsConf, nsId);\n      for (ClientProtocol proxy : namenodes) {\n        try {\n          if (proxy.getHAServiceState().equals(HAServiceState.ACTIVE)) {\n            inAddr = RPC.getServerAddress(proxy);\n          }\n        } catch (Exception e) {\n          //Ignore the exception while connecting to a namenode.\n          LOG.debug(\"Error while connecting to namenode\", e);","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/HAUtil.java#L253-L289","documentation":"HAUtil.getAddressOfActive requires an HDFS handle: it immediately checks fs instanceof DistributedFileSystem and throws IllegalArgumentException otherwise, because it needs to inspect dfs.getConf()/dfs.getUri(), resolve the nameservice and probe every NN proxy for the active one.","triggerScenarios":"Calling HAUtil.getAddressOfActive(fs) with any non-HDFS FileSystem: LocalFileSystem (file:///), RawLocalFileSystem, WebHdfsFileSystem, ViewFileSystem, S3A, etc. Happens when fs.defaultFS is not hdfs:// or when the URI scheme was left to default.","commonSituations":"Generic tools written against the FileSystem API calling this HA helper; unit tests that run with LocalFileSystem; fs.defaultFS misconfigured (or unset, defaulting to file:///) so FileSystem.get(conf) returns a local handle.","solutions":["Construct the FileSystem from an explicit HDFS URI: FileSystem.get(URI.create(\"hdfs://\" + nameservice), conf)","Set fs.defaultFS to the HA nameservice URI (e.g. hdfs://mycluster) before obtaining the FileSystem","Guard with instanceof DistributedFileSystem before calling getAddressOfActive"],"exampleFix":"// before\nFileSystem fs = FileSystem.get(conf);              // may be LocalFileSystem\nHAUtil.getAddressOfActive(fs);\n// after\nFileSystem fs = FileSystem.get(URI.create(\"hdfs://ns1\"), conf);\nif (!(fs instanceof DistributedFileSystem)) {\n  throw new IllegalStateException(\"expected an HDFS FileSystem, got \" + fs.getUri());\n}\nHAUtil.getAddressOfActive(fs);","handlingStrategy":"type-guard","validationCode":"if (!\"hdfs\".equalsIgnoreCase(fs.getUri().getScheme())) {\n  throw new IllegalArgumentException(\n      \"HAUtil.getAddressOfActive needs an hdfs:// FileSystem, got \" + fs.getUri());\n}","typeGuard":"static DistributedFileSystem asDistributedFileSystem(FileSystem fs) {\n  return (fs instanceof DistributedFileSystem)\n      ? (DistributedFileSystem) fs\n      : null;\n}\n\n// usage\nDistributedFileSystem dfs = asDistributedFileSystem(fs);\nif (dfs == null) { /* handle non-HDFS fs */ }","tryCatchPattern":"catch (IllegalArgumentException e) at the call site; the message names the actual FileSystem class - report it and fix the URI/defaultFS instead of catching repeatedly.","preventionTips":["Always construct HDFS FileSystems from an explicit hdfs:// URI in code that needs HDFS-specific APIs","Check fs.getUri().getScheme() before calling HDFS-only helpers like getAddressOfActive","Set fs.defaultFS correctly so FileSystem.get(conf) cannot silently return LocalFileSystem"],"tags":["hdfs","ha","filesystem","type-mismatch","uri"],"backgroundTag":"invalid-argument-type","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}