apache/beam · error · IllegalArgumentException

Unsupported compression type: " + compression

Error message

Unsupported compression type: " + compression

What it means

CompressedSource.CompressionMode.fromCanonical converts a canonical Compression enum into a CompressionMode; an unrecognized value means the switch has no mapping (unknown enum constant, typically from a version mismatch or corrupted value). It throws IllegalArgumentException naming the offending compression.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/io/CompressedSource.java:170

          return ZIP;

        case ZSTD:
          return ZSTD;

        case LZO:
          return LZO;

        case LZOP:
          return LZOP;

        case DEFLATE:
          return DEFLATE;

        case SNAPPY:
          return SNAPPY;

        default:
          throw new IllegalArgumentException("Unsupported compression type: " + compression);
      }
    }
  }

  private final FileBasedSource<T> sourceDelegate;
  private final DecompressingChannelFactory channelFactory;

  /**
   * Creates a {@code CompressedSource} from an underlying {@code FileBasedSource}. The type of
   * compression used will be based on the file name extension unless explicitly configured via
   * {@link CompressedSource#withDecompression}.
   */
  public static <T> CompressedSource<T> from(FileBasedSource<T> sourceDelegate) {
    return new CompressedSource<>(sourceDelegate, CompressionMode.AUTO);
  }

  /**
   * Return a {@code CompressedSource} that is like this one but will decompress its underlying file

View on GitHub (pinned to 12126d8942)

Solutions

  1. Align all Beam SDK jars to a single version so the enum constant exists.
  2. Use only compression types supported by the deployed Beam version's Compression enum.
  3. Check the switch coverage in CompressedSource.java for your Beam version and pick a mapped value.

Example fix

// before
Compression mode = Compression.ZSTD; // not present in deployed Beam version
CompressedSource.CompressionMode.fromCanonical(mode);
// after
Compression mode = Compression.GZIP; // supported by the deployed version
Defensive patterns

Strategy: try-catch

Validate before calling

Set<String> supported = Set.of("GZIP","BZIP2","ZIP","DEFLATE","SNAPPY");
if (!supported.contains(compression.name())) throw new IllegalArgumentException("unsupported compression: " + compression);

Try / catch

try {
  mode = CompressedSource.CompressionMode.fromCanonical(canonical);
} catch (IllegalArgumentException e) {
  mode = CompressedSource.CompressionMode.GZIP;
}

Prevention

When it happens

Trigger: Passing a Compression value to CompressedSource.CompressionMode.fromCanonical that is not GZIP, BZIP2, ZIP, DEF late, or SNAPPY per the switch in that Beam version — e.g., a newer/older enum constant like ZSTD when running against an older Beam jar.

Common situations: Mixing Beam SDK versions on the classpath; referencing an enum constant added after the deployed Beam version; reflection-based or serialized enum values crossing versions.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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