{"record":{"id":"0fc3ff6b80553089","repo":"apache/hadoop","slug":"classname-stream-does-not-support-setting-the-d","errorCode":null,"errorMessage":"${className} stream does not support setting the drop-behind caching setting.","messagePattern":"(.+?) stream does not support setting the drop-behind caching setting\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java","lineNumber":761,"sourceCode":"    }\n    ((HasEnhancedByteBufferAccess) in).releaseBuffer(buffer);\n  }\n\n  @Override\n  public void setReadahead(Long readahead) throws IOException,\n      UnsupportedOperationException {\n    if (!(in instanceof CanSetReadahead)) {\n      throw new UnsupportedOperationException(in.getClass().getCanonicalName()\n          + \" does not support setting the readahead caching strategy.\");\n    }\n    ((CanSetReadahead) in).setReadahead(readahead);\n  }\n\n  @Override\n  public void setDropBehind(Boolean dropCache) throws IOException,\n      UnsupportedOperationException {\n    if (!(in instanceof CanSetReadahead)) {\n      throw new UnsupportedOperationException(in.getClass().getCanonicalName()\n          + \" stream does not support setting the drop-behind caching\"\n          + \" setting.\");\n    }\n    ((CanSetDropBehind) in).setDropBehind(dropCache);\n  }\n\n  @Override\n  public FileDescriptor getFileDescriptor() throws IOException {\n    if (in instanceof HasFileDescriptor) {\n      return ((HasFileDescriptor) in).getFileDescriptor();\n    } else if (in instanceof FileInputStream) {\n      return ((FileInputStream) in).getFD();\n    } else {\n      return null;\n    }\n  }\n  \n  @Override","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java#L743-L779","documentation":"setDropBehind(Boolean) on CryptoInputStream is gated by an instanceof check, but the code tests `in instanceof CanSetReadahead` while casting to CanSetDropBehind — an interface mismatch. Net effect: a stream implementing drop-behind but not readahead gets UnsupportedOperationException here, and a stream implementing readahead but not drop-behind passes the gate and fails with ClassCastException at the cast.","triggerScenarios":"Calling setDropBehind() on a CryptoInputStream whose inner stream does not implement CanSetReadahead (wrong-interface gate); conversely, a custom stream implementing CanSetReadahead but not CanSetDropBehind fails at the cast line below the check.","commonSituations":"Page-cache/drop-behind tuning applied to encrypted reads; custom wrapped streams implementing only one of the two capability interfaces; code that worked against plain HDFS streams failing once encryption is enabled.","solutions":["Make drop-behind tuning best-effort: catch both UnsupportedOperationException and ClassCastException on affected versions","Implement both CanSetReadahead and CanSetDropBehind on custom wrapped streams","Upgrade or patch Hadoop — the gate should test CanSetDropBehind; track the upstream fix if vendor branching"],"exampleFix":"// before\nfsIn.setDropBehind(true); // UOE (or ClassCastException) due to wrong-interface gate\n\n// after\ntry {\n  fsIn.setDropBehind(true);\n} catch (UnsupportedOperationException | ClassCastException e) {\n  LOG.debug(\"Drop-behind tuning not supported for this stream\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  fsIn.setDropBehind(dropBehind);\n} catch (UnsupportedOperationException | ClassCastException e) {\n  // gate checks CanSetReadahead but casts CanSetDropBehind on affected versions\n  LOG.debug(\"Drop-behind tuning unsupported on this stream\");\n}","preventionTips":["Catch both UnsupportedOperationException and ClassCastException around setDropBehind on this code path","Implement both CanSetReadahead and CanSetDropBehind on custom wrapped streams","Track the upstream fix (instanceof should test CanSetDropBehind) and patch vendor branches"],"tags":["crypto","stream","drop-behind","performance","hadoop"],"backgroundTag":"unsupported-stream-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}