{"record":{"id":"4e4cd0c9bd917321","repo":"apache/hadoop","slug":"classname-does-not-support-setting-the-readahea","errorCode":null,"errorMessage":"${className} does not support setting the readahead caching strategy.","messagePattern":"(.+?) does not support setting the readahead caching strategy\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java","lineNumber":751,"sourceCode":"      }\n    }\n    return buffer;\n  }\n\n  @Override\n  public void releaseBuffer(ByteBuffer buffer) {\n    if (!(in instanceof HasEnhancedByteBufferAccess)) {\n      throw new UnsupportedOperationException(in.getClass().getCanonicalName()\n          + \" does not support release buffer.\");\n    }\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 {","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java#L733-L769","documentation":"CryptoInputStream.setReadahead(Long) can only delegate readahead tuning to the wrapped stream, which must implement CanSetReadahead; otherwise UnsupportedOperationException names the wrapped class. The method's signature declares UnsupportedOperationException exactly for this capability-miss case.","triggerScenarios":"Performance-tuning code calling setReadahead() on an FSDataInputStream that wraps a CryptoInputStream whose inner stream lacks CanSetReadahead — e.g. encrypted reads over connector streams without readahead control.","commonSituations":"Client frameworks applying per-stream readahead hints uniformly to every opened file, including encrypted ones; tuning copied from HDFS-native deployments to other filesystems.","solutions":["Make readahead tuning best-effort: catch UnsupportedOperationException and continue with defaults","Set readahead at filesystem/client configuration level rather than per-stream for encrypted data","Skip the call when the path is inside an encryption zone"],"exampleFix":"// before\nfsIn.setReadahead(64L * 1024L); // UOE when inner stream lacks CanSetReadahead\n\n// after\ntry {\n  fsIn.setReadahead(64L * 1024L);\n} catch (UnsupportedOperationException e) {\n  LOG.debug(\"Readahead tuning not supported for this stream; using default\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  fsIn.setReadahead(readahead);\n} catch (UnsupportedOperationException e) {\n  LOG.debug(\"Readahead tuning unsupported on this stream; using default\");\n}","preventionTips":["Treat per-stream tuning calls (readahead, drop-behind) as best-effort optimizations","Prefer configuration-level readahead settings over per-stream calls for encrypted data","Wrap all optional tuning calls in one guarded helper instead of scattering try/catch"],"tags":["crypto","stream","readahead","performance","hadoop"],"backgroundTag":"unsupported-stream-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}