{"record":{"id":"247b43e642afc200","repo":"apache/beam","slug":"auto-is-applicable-only-to-reading-files","errorCode":null,"errorMessage":"AUTO is applicable only to reading files","messagePattern":"AUTO is applicable only to reading files","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/io/Compression.java","lineNumber":60,"sourceCode":"import 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) {\n      return channel;\n    }\n  },\n\n  /** GZip compression. */\n  GZIP(\".gz\", \".gz\") {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/io/Compression.java#L42-L78","documentation":"Compression.AUTO only applies when reading (compression detection by extension). Its writeCompressed() therefore always throws UnsupportedOperationException, since there is no concrete codec to compress with when writing.","triggerScenarios":"Calling Compression.AUTO.writeCompressed(channel) directly, or configuring a sink's write compression to AUTO (e.g., FileIO.write().withCompression(AUTO) reaching CompressionType.fromCanonical or the enum's write path).","commonSituations":"Reusing a read-side Compression value for writing; pipeline options where compression=AUTO was meant for reads but applied to an output sink.","solutions":["Use a concrete compression for writing (GZIP, BZIP2, ZSTD, or UNCOMPRESSED).","Special-case AUTO in writing code by substituting UNCOMPRESSED or a detected/appropriate type.","Validate user-provided compression options at pipeline construction time and reject AUTO for sinks."],"exampleFix":"// before\nCompression.AUTO.writeCompressed(channel);\n// after\nCompression.GZIP.writeCompressed(channel);","handlingStrategy":"validation","validationCode":"if (compression == Compression.AUTO) {\n  compression = Compression.UNCOMPRESSED; // or GZIP\n}","typeGuard":null,"tryCatchPattern":"try {\n  out = compression.writeCompressed(channel);\n} catch (UnsupportedOperationException e) {\n  out = Compression.UNCOMPRESSED.writeCompressed(channel);\n}","preventionTips":["Never configure sinks with AUTO compression","Separate read-side and write-side compression options","Validate compression config at pipeline construction"],"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"}