{"record":{"id":"d63864361cd7ab68","repo":"apache/hadoop","slug":"classname-does-not-support-positioned-reads-wit","errorCode":null,"errorMessage":"${className} does not support positioned reads with byte buffers.","messagePattern":"(.+?) does not support positioned reads with byte buffers\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java","lineNumber":358,"sourceCode":"    final int n = ((PositionedReadable) in).read(position, buffer, offset,\n        length);\n    if (n > 0) {\n      // This operation does not change the current offset of the file\n      decrypt(position, buffer, offset, n);\n    }\n\n    return n;\n  }\n\n  /**\n   * Positioned read using {@link ByteBuffer}s. This method is thread-safe.\n   */\n  @Override\n  public int read(long position, final ByteBuffer buf)\n      throws IOException {\n    checkStream();\n    if (!(in instanceof ByteBufferPositionedReadable)) {\n      throw new UnsupportedOperationException(in.getClass().getCanonicalName()\n          + \" does not support positioned reads with byte buffers.\");\n    }\n    int bufPos = buf.position();\n    final int n = ((ByteBufferPositionedReadable) in).read(position, buf);\n    if (n > 0) {\n      // This operation does not change the current offset of the file\n      decrypt(position, buf, n, bufPos);\n    }\n\n    return n;\n  }\n\n  /**\n   * Positioned readFully using {@link ByteBuffer}s. This method is thread-safe.\n   */\n  @Override\n  public void readFully(long position, final ByteBuffer buf)\n      throws IOException {","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java#L340-L376","documentation":"CryptoInputStream.read(long, ByteBuffer) is the ByteBuffer-variant positioned read; it requires the wrapped stream to implement ByteBufferPositionedReadable. If `in` does not, UnsupportedOperationException with the wrapped class name is thrown after checkStream() passes.","triggerScenarios":"Calling read(position, buf) where the inner stream implements only PositionedReadable (byte[] variant) or neither — typical of filesystem clients predating ByteBufferPositionedReadable.","commonSituations":"Zero-copy/ByteBuffer-oriented readers (query engines, modern parquet readers) hitting encrypted files; mixing a newer client API with older connector stream implementations.","solutions":["Switch to the byte[] positioned variant read(position, bytes, off, len), which only requires PositionedReadable","Fall back to plain sequential read() when positioning is not essential","Upgrade the filesystem client so its streams implement ByteBufferPositionedReadable"],"exampleFix":"// before\nint n = cryptoIn.read(pos, byteBuffer); // UOE without ByteBufferPositionedReadable\n\n// after\nbyte[] tmp = new byte[byteBuffer.remaining()];\nint n = cryptoIn.read(pos, tmp, 0, tmp.length);\nif (n > 0) { byteBuffer.put(tmp, 0, n); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  n = in.read(pos, byteBuffer);\n} catch (UnsupportedOperationException e) {\n  // ByteBufferPositionedReadable missing: use the byte[] positioned variant\n  byte[] tmp = new byte[byteBuffer.remaining()];\n  n = in.read(pos, tmp, 0, tmp.length);\n  if (n > 0) byteBuffer.put(tmp, 0, n);\n}","preventionTips":["Prefer the byte[] positioned APIs; treat ByteBuffer positioned reads as an optimization only","Gate ByteBuffer-based read paths on filesystem client versions that implement ByteBufferPositionedReadable","Keep a single fallback helper for ByteBuffer vs byte[] read dispatch"],"tags":["crypto","hdfs","stream","bytebuffer","positioned-read","hadoop"],"backgroundTag":"unsupported-stream-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}