{"record":{"id":"b2c920f0d6ac4adb","repo":"apache/hadoop","slug":"cannot-clone-underlying-stream-is-not-a-dfsinput","errorCode":null,"errorMessage":"Cannot clone: underlying stream is, not a DFSInputStream","messagePattern":"Cannot clone: underlying stream is, not a DFSInputStream","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java","lineNumber":452,"sourceCode":"   * but shares the same block location metadata.\n   *\n   * @param existing an open input stream obtained from this filesystem\n   * @return a new independent input stream for the same file\n   * @throws IOException if the stream cannot be cloned\n   */\n  public FSDataInputStream cloneDataInputStream(FSDataInputStream existing)\n      throws IOException {\n    statistics.incrementReadOps(1);\n    storageStatistics.incrementOpCounter(OpType.OPEN);\n    InputStream wrapped = existing.getWrappedStream();\n    DFSInputStream dfsis;\n    if (wrapped instanceof DFSInputStream dfsIn) {\n      dfsis = dfsIn;\n    } else if (wrapped instanceof\n        org.apache.hadoop.crypto.CryptoInputStream cryptoIn) {\n      dfsis = (DFSInputStream) cryptoIn.getWrappedStream();\n    } else {\n      throw new IOException(\"Cannot clone: underlying stream is \"\n          + wrapped.getClass().getName() + \", not a DFSInputStream\");\n    }\n    if (dfsis.getDFSClient() != dfs) {\n      throw new IOException(\n          \"Cannot clone: stream belongs to a different DFSClient instance\");\n    }\n    LocatedBlocks locatedBlocks = dfsis.getLocatedBlocks();\n    String src = dfsis.getSrc();\n    DFSInputStream clone = dfs.open(src,\n        dfs.getConf().getIoBufferSize(), verifyChecksum, locatedBlocks);\n    try {\n      return dfs.createWrappedInputStream(clone);\n    } catch (IOException e) {\n      clone.close();\n      throw e;\n    }\n  }\n","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java#L434-L470","documentation":"Error \"Cannot clone: underlying stream is, not a DFSInputStream\" thrown in apache/hadoop.","triggerScenarios":"An open-stream clone is requested on a stream whose underlying input stream is not a DFSInputStream, so the HDFS-specific clone cannot be performed.","commonSituations":"See trigger scenarios.","solutions":["Only clone streams opened via DistributedFileSystem whose underlying stream is a DFSInputStream.","Guard the clone call with an instanceof DFSInputStream check and handle non-DFS streams separately."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}