{"record":{"id":"2becfd048a2ee8b7","repo":"apache/hadoop","slug":"classname-does-not-support-seek","errorCode":null,"errorMessage":"${className} does not support seek.","messagePattern":"(.+?) does not support seek\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java","lineNumber":540,"sourceCode":"  /** Seek to a position. */\n  @Override\n  public void seek(long pos) throws IOException {\n    if (pos < 0) {\n      throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK);\n    }\n    checkStream();\n    /*\n     * If data of target pos in the underlying stream has already been read\n     * and decrypted in outBuffer, we just need to re-position outBuffer.\n     */\n    if (pos <= streamOffset && pos >= (streamOffset - outBuffer.remaining())) {\n      int forward = (int) (pos - (streamOffset - outBuffer.remaining()));\n      if (forward > 0) {\n        outBuffer.position(outBuffer.position() + forward);\n      }\n    } else {\n      if (!(in instanceof Seekable)) {\n        throw new UnsupportedOperationException(in.getClass().getCanonicalName()\n            + \" does not support seek.\");\n      }\n      ((Seekable) in).seek(pos);\n      resetStreamOffset(pos);\n    }\n  }\n  \n  /** Skip n bytes */\n  @Override\n  public long skip(long n) throws IOException {\n    Preconditions.checkArgument(n >= 0, \"Negative skip length.\");\n    checkStream();\n    \n    if (n == 0) {\n      return 0;\n    } else if (n <= outBuffer.remaining()) {\n      int pos = outBuffer.position() + (int) n;\n      outBuffer.position(pos);","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java#L522-L558","documentation":"CryptoInputStream.seek() can satisfy a target cheaply only when it falls inside the already-decrypted outBuffer window (streamOffset - outBuffer.remaining() .. streamOffset). Otherwise it must reposition the wrapped stream, which requires `in instanceof Seekable`; a non-Seekable inner stream triggers UnsupportedOperationException with the wrapped class name.","triggerScenarios":"Calling seek() to a position outside the buffered decrypted range on a CryptoInputStream over a sequential-only inner stream; note the read(ByteBufferPool,...) path also hits this check when discarding leftover decrypted data.","commonSituations":"Seek-driven readers (record readers, format parsers) on encrypted files where the underlying stream cannot seek (some object-store connectors, wrapped test streams).","solutions":["Reopen the stream at the desired offset (constructor variant taking a streamOffset) instead of seeking","Fall back to skip-based forward navigation when only forward movement is needed","Wrap the source stream in a Seekable implementation before constructing the CryptoInputStream"],"exampleFix":"// before\ncryptoIn.seek(newPos); // UOE when inner stream is not Seekable\n\n// after\n// close and reopen at the offset for encrypted sequential sources\ncryptoIn.close();\nCryptoInputStream fresh = new CryptoInputStream(\n    sourceFactory.open(), codec, bufferSize, key, iv, newPos /* streamOffset */);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  in.seek(pos);\n} catch (UnsupportedOperationException e) {\n  // inner stream not Seekable: reopen at the offset\n  in.close();\n  in = openStreamAt(pos);\n}","preventionTips":["For encrypted sequential sources, reopen at an offset instead of seeking","Read large files front-to-back so seeks never target outside the decrypted window","Know your underlying stream type before enabling seek-driven parsers on encrypted data"],"tags":["crypto","hdfs","stream","seek","hadoop"],"backgroundTag":"unsupported-stream-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}