{"record":{"id":"3df0ca28518eae9e","repo":"apache/hadoop","slug":"byte-arrays-are-not-supported-for-directdecompre","errorCode":null,"errorMessage":"byte[] arrays are not supported for DirectDecompressor","messagePattern":"byte\\[\\] arrays are not supported for DirectDecompressor","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/snappy/SnappyDecompressor.java","lineNumber":335,"sourceCode":"      super.reset();\n      endOfInput = true;\n    }\n\n    private boolean endOfInput;\n\n    @Override\n    public void decompress(ByteBuffer src, ByteBuffer dst)\n        throws IOException {\n      assert dst.isDirect() : \"dst.isDirect()\";\n      assert src.isDirect() : \"src.isDirect()\";\n      assert dst.remaining() > 0 : \"dst.remaining() > 0\";\n      this.decompressDirect(src, dst);\n      endOfInput = !src.hasRemaining();\n    }\n\n    @Override\n    public void setDictionary(byte[] b, int off, int len) {\n      throw new UnsupportedOperationException(\n          \"byte[] arrays are not supported for DirectDecompressor\");\n    }\n\n    @Override\n    public int decompress(byte[] b, int off, int len) {\n      throw new UnsupportedOperationException(\n          \"byte[] arrays are not supported for DirectDecompressor\");\n    }\n  }\n}\n","sourceCodeStart":317,"sourceCodeEnd":346,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/snappy/SnappyDecompressor.java#L317-L346","documentation":"SnappyCodec can return a DirectDecompressor (via createDirectDecompressor()) whose implementation, SnappyDecompressor.DirectDecompressor, works exclusively on direct ByteBuffers (decompress(ByteBuffer src, ByteBuffer dst)). The DirectDecompressor interface intentionally does not support dictionary-based APIs, so setDictionary(byte[], int, int) always throws UnsupportedOperationException with this message. Calling it means generic Decompressor-style code is being run against a direct-buffer-only object.","triggerScenarios":"Obtaining a DirectDecompressor (codec.createDirectDecompressor(), or an allocator/pool handing one back) and invoking setDictionary(b, off, len) on it — e.g. generic codec utilities that call setDictionary when a dictionary is configured, or code casting DirectDecompressor back to Decompressor and driving the full array-based API.","commonSituations":"Shared compression helpers handling both regular and direct codecs; frameworks that apply preset dictionaries (mostly zlib-oriented) uniformly to all Decompressors; codec pools where the object's concrete type is erased; code migrated from zlib/snappy array paths to the direct path without removing dictionary setup.","solutions":["Branch on type before calling: skip setDictionary when the decompressor implements DirectDecompressor.","If you need dictionary or byte[] APIs, use the normal path: codec.createDecompressor() (array-based SnappyDecompressor) instead of createDirectDecompressor().","Keep the two code paths separate: ByteBuffer-to-ByteBuffer for DirectDecompressor, byte[] for Decompressor.","If you own the interface design, feature-test capabilities once (instanceof DirectDecompressor) rather than catching UnsupportedOperationException in production flow."],"exampleFix":"// before\nDecompressor d = (Decompressor) snappyCodec.createDirectDecompressor();\nd.setDictionary(dict, 0, dict.length); // UnsupportedOperationException\n\n// after\nif (snappyCodec instanceof DirectDecompressionCodec) {\n  DirectDecompressor dd = snappyCodec.createDirectDecompressor();\n  dd.decompress(srcBuf, dstBuf); // ByteBuffer path, no dictionary\n} else {\n  Decompressor d = snappyCodec.createDecompressor();\n  d.setDictionary(dict, 0, dict.length);\n}","handlingStrategy":"type-guard","validationCode":"if (decompressor instanceof DirectDecompressor) {\n  // direct path: no dictionary API exists — do not call setDictionary\n  ((DirectDecompressor) decompressor).decompress(srcBuf, dstBuf);\n} else {\n  decompressor.setDictionary(dict, 0, dict.length);\n}","typeGuard":"static boolean supportsArrayDictionary(Object codecResult) {\n  return !(codecResult instanceof DirectDecompressor);\n}","tryCatchPattern":null,"preventionTips":["Type-check results of createDirectDecompressor() before using classic Decompressor APIs.","Keep dictionary setup (a zlib-oriented feature) out of snappy/direct paths.","Key codec pools by capability (array vs direct), not just codec class name."],"tags":["snappy","compression","unsupported-operation","direct-buffer","hadoop"],"backgroundTag":"unsupported-operation-exception","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}