{"record":{"id":"f91743f880ad1ac2","repo":"apache/hadoop","slug":"this-stream-does-not-support-setting-the-drop-behi","errorCode":null,"errorMessage":"This stream does not support setting the drop-behind caching.","messagePattern":"This stream does not support setting the drop-behind caching\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoOutputStream.java","lineNumber":289,"sourceCode":"  @Override\n  public void write(int b) throws IOException {\n    oneByteBuf[0] = (byte)(b & 0xff);\n    write(oneByteBuf, 0, oneByteBuf.length);\n  }\n  \n  private void checkStream() throws IOException {\n    if (closed) {\n      throw new IOException(\"Stream closed\");\n    }\n  }\n  \n  @Override\n  public void setDropBehind(Boolean dropCache) throws IOException,\n      UnsupportedOperationException {\n    try {\n      ((CanSetDropBehind) out).setDropBehind(dropCache);\n    } catch (ClassCastException e) {\n      throw new UnsupportedOperationException(\"This stream does not \" +\n          \"support setting the drop-behind caching.\");\n    }\n  }\n\n  @Override\n  public void hflush() throws IOException {\n    flush();\n    if (out instanceof Syncable) {\n      ((Syncable)out).hflush();\n    }\n  }\n\n  @Override\n  public void hsync() throws IOException {\n    flush();\n    if (out instanceof Syncable) {\n      ((Syncable)out).hsync();\n    }","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoOutputStream.java#L271-L307","documentation":"CryptoOutputStream encrypts data on top of an underlying FS stream. setDropBehind() tries to forward the drop-behind cache hint to the wrapped stream by casting it to CanSetDropBehind. When the wrapped stream does not implement that interface, the ClassCastException is converted into an UnsupportedOperationException, telling the caller that this stream chain cannot control drop-behind caching.","triggerScenarios":"Calling cryptoOutputStream.setDropBehind(Boolean) when the wrapped `out` stream is not an instance of CanSetDropBehind. Typical with streams over local file system, test streams, or filesystems that never implemented the CanSetDropBehind capability interface.","commonSituations":"Generic code that calls setDropBehind on any stream it receives (DistCp-style loops, HBase WAL writers); wrapping layers where the inner stream is a raw checksum stream or test mock; calling the hint on a CryptoOutputStream built over a wrapped non-capable stream.","solutions":["Catch UnsupportedOperationException and treat it as a no-op hint — drop-behind is only a performance hint, never a correctness requirement","Before wrapping, check the raw stream with `rawStream instanceof CanSetDropBehind` and skip the call when false","Set drop-behind via configuration on the underlying filesystem/stream type instead of per-stream when supported","If you control the wrapped stream class, implement CanSetDropBehind on it"],"exampleFix":"// before\ncryptoOut.setDropBehind(false); // throws UnsupportedOperationException\n\n// after\ntry {\n  cryptoOut.setDropBehind(false);\n} catch (UnsupportedOperationException e) {\n  // drop-behind is a hint; the wrapped stream cannot control page cache\n  LOG.debug(\"Drop-behind not supported by wrapped stream: {}\", e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"// Before wrapping / calling, test the raw stream's capability\nboolean canDropBehind = rawOut instanceof CanSetDropBehind;\nif (canDropBehind) {\n  cryptoOut.setDropBehind(false);\n}","typeGuard":"// Capability check for the wrapped stream (Java)\npublic boolean supportsDropBehind(java.io.OutputStream out) {\n  return out instanceof org.apache.hadoop.fs.CanSetDropBehind;\n}","tryCatchPattern":"try {\n  cryptoOut.setDropBehind(dropBehind);\n} catch (UnsupportedOperationException e) {\n  // hint only: stream chain cannot control page cache; safe to ignore\n  LOG.debug(\"setDropBehind unsupported: {}\", e.toString());\n}","preventionTips":["Treat drop-behind strictly as a performance hint; never fail the write path on it","Check the raw stream for CanSetDropBehind before wrapping with CryptoOutputStream when the hint matters","Set drop-behind policy through filesystem configuration instead of per-stream calls where possible"],"tags":["crypto","stream","drop-behind","unsupported-operation"],"backgroundTag":"unsupported-stream-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}