{"record":{"id":"9882d5451538897a","repo":"apache/beam","slug":"must-resolve-compression-into-a-concrete-value-before","errorCode":null,"errorMessage":"Must resolve compression into a concrete value before calling readDecompressed()","messagePattern":"Must resolve compression into a concrete value before calling readDecompressed\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/io/Compression.java","lineNumber":54,"sourceCode":"import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;\nimport org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream;\nimport org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;\nimport org.apache.commons.compress.compressors.snappy.SnappyCompressorInputStream;\nimport org.apache.commons.compress.compressors.snappy.SnappyCompressorOutputStream;\nimport org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;\nimport org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;\n\n/** Various compression types for reading/writing files. */\n@SuppressWarnings(\"ImmutableEnumChecker\")\npublic enum Compression {\n  /**\n   * When reading a file, automatically determine the compression type based on filename extension.\n   * Not applicable when writing files.\n   */\n  AUTO(\"\") {\n    @Override\n    public ReadableByteChannel readDecompressed(ReadableByteChannel channel) {\n      throw new UnsupportedOperationException(\n          \"Must resolve compression into a concrete value before calling readDecompressed()\");\n    }\n\n    @Override\n    public WritableByteChannel writeCompressed(WritableByteChannel channel) {\n      throw new UnsupportedOperationException(\"AUTO is applicable only to reading files\");\n    }\n  },\n\n  /** No compression. */\n  UNCOMPRESSED(\"\") {\n    @Override\n    public ReadableByteChannel readDecompressed(ReadableByteChannel channel) {\n      return channel;\n    }\n\n    @Override\n    public WritableByteChannel writeCompressed(WritableByteChannel channel) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/io/Compression.java#L36-L72","documentation":"Compression.AUTO means 'detect compression from the filename extension'. Because AUTO has no concrete codec, its readDecompressed() always throws UnsupportedOperationException; the caller must first resolve AUTO to a concrete type (e.g., via Compression.detectFromFile / the file-based source matching logic).","triggerScenarios":"Calling Compression.AUTO.readDecompressed(channel) directly; custom readers that take a Compression enum from user config without resolving AUTO before reading.","commonSituations":"User-supplied pipeline options with compression=AUTO fed directly into a custom read path; utility code that iterates Compression values and invokes readDecompressed without special-casing AUTO.","solutions":["Resolve AUTO first, e.g., Compression.detectFromFile(path) or the CompressionMode.fromCanonical path used by CompressedSource.","Special-case AUTO in custom read code by detecting from filename before calling readDecompressed.","Default user config to a concrete type like GZIP when AUTO semantics are unavailable."],"exampleFix":"// before\nCompression.AUTO.readDecompressed(channel);\n// after\nCompression c = Compression.detectFromFile(filePath);\nReadableByteChannel decompressed = c.readDecompressed(channel);","handlingStrategy":"validation","validationCode":"if (compression == Compression.AUTO) {\n  compression = Compression.detectFromFile(filePath);\n}","typeGuard":null,"tryCatchPattern":"try {\n  channel = compression.readDecompressed(raw);\n} catch (UnsupportedOperationException e) {\n  channel = Compression.detectFromFile(path).readDecompressed(raw);\n}","preventionTips":["Always resolve AUTO via detectFromFile before reading","Special-case AUTO in custom read loops","Default unresolved AUTO to UNCOMPRESSED or GZIP explicitly"],"tags":["java","io","compression","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}