apache/beam · error · UnsupportedOperationException

Must resolve compression into a concrete value before callin

Error message

Must resolve compression into a concrete value before calling readDecompressed()

What it means

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).

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/io/Compression.java:54

import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;
import org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.compress.compressors.snappy.SnappyCompressorInputStream;
import org.apache.commons.compress.compressors.snappy.SnappyCompressorOutputStream;
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;

/** Various compression types for reading/writing files. */
@SuppressWarnings("ImmutableEnumChecker")
public enum Compression {
  /**
   * When reading a file, automatically determine the compression type based on filename extension.
   * Not applicable when writing files.
   */
  AUTO("") {
    @Override
    public ReadableByteChannel readDecompressed(ReadableByteChannel channel) {
      throw new UnsupportedOperationException(
          "Must resolve compression into a concrete value before calling readDecompressed()");
    }

    @Override
    public WritableByteChannel writeCompressed(WritableByteChannel channel) {
      throw new UnsupportedOperationException("AUTO is applicable only to reading files");
    }
  },

  /** No compression. */
  UNCOMPRESSED("") {
    @Override
    public ReadableByteChannel readDecompressed(ReadableByteChannel channel) {
      return channel;
    }

    @Override
    public WritableByteChannel writeCompressed(WritableByteChannel channel) {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Resolve AUTO first, e.g., Compression.detectFromFile(path) or the CompressionMode.fromCanonical path used by CompressedSource.
  2. Special-case AUTO in custom read code by detecting from filename before calling readDecompressed.
  3. Default user config to a concrete type like GZIP when AUTO semantics are unavailable.

Example fix

// before
Compression.AUTO.readDecompressed(channel);
// after
Compression c = Compression.detectFromFile(filePath);
ReadableByteChannel decompressed = c.readDecompressed(channel);
Defensive patterns

Strategy: validation

Validate before calling

if (compression == Compression.AUTO) {
  compression = Compression.detectFromFile(filePath);
}

Try / catch

try {
  channel = compression.readDecompressed(raw);
} catch (UnsupportedOperationException e) {
  channel = Compression.detectFromFile(path).readDecompressed(raw);
}

Prevention

When it happens

Trigger: Calling Compression.AUTO.readDecompressed(channel) directly; custom readers that take a Compression enum from user config without resolving AUTO before reading.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/9882d5451538897a. Report an issue: GitHub.