{"record":{"id":"51dab3ffd5d04d38","repo":"apache/pulsar","slug":"invalid-compression-type","errorCode":null,"errorMessage":"Invalid compression type","messagePattern":"Invalid compression type","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/compression/CompressionCodecProvider.java","lineNumber":70,"sourceCode":"        return codecs.get(convertToWireProtocol(type));\n    }\n\n    public static org.apache.pulsar.common.api.proto.CompressionType convertToWireProtocol(\n            CompressionType compressionType) {\n        switch (compressionType) {\n        case NONE:\n            return org.apache.pulsar.common.api.proto.CompressionType.NONE;\n        case LZ4:\n            return org.apache.pulsar.common.api.proto.CompressionType.LZ4;\n        case ZLIB:\n            return org.apache.pulsar.common.api.proto.CompressionType.ZLIB;\n        case ZSTD:\n            return org.apache.pulsar.common.api.proto.CompressionType.ZSTD;\n        case SNAPPY:\n            return org.apache.pulsar.common.api.proto.CompressionType.SNAPPY;\n\n        default:\n            throw new RuntimeException(\"Invalid compression type\");\n        }\n    }\n\n    public static CompressionType convertFromWireProtocol(\n            org.apache.pulsar.common.api.proto.CompressionType compressionType) {\n        switch (compressionType) {\n        case NONE:\n            return CompressionType.NONE;\n        case LZ4:\n            return CompressionType.LZ4;\n        case ZLIB:\n            return CompressionType.ZLIB;\n        case ZSTD:\n            return CompressionType.ZSTD;\n        case SNAPPY:\n            return CompressionType.SNAPPY;\n\n        default:","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/compression/CompressionCodecProvider.java#L52-L88","documentation":"CompressionCodecProvider.convertToWireProtocol maps the public client CompressionType enum onto the wire-protocol CompressionType. Every known codec (NONE, LZ4, ZLIB, ZSTD, SNAPPY) is handled by the switch; reaching the default branch means an unknown/unsupported enum value, and it throws RuntimeException 'Invalid compression type'.","triggerScenarios":"Passing a CompressionType value not covered by the switch — typically null, a custom/exotic enum constant, or an enum from a different library version with a codec this provider doesn't recognize.","commonSituations":"Client/server version skew where a newer codec enum isn't handled; configuration loading a compression name that maps to an unexpected enum; passing null compression type into conversion paths; reflective/dynamic codec selection picking an unsupported value.","solutions":["Verify the CompressionType passed is one of NONE, LZ4, ZLIB, ZSTD, or SNAPPY; validate or default to NONE before conversion.","Align client and broker library versions so both sides support the same codec set.","Null-check / whitelist-check the configured codec name at startup and fail fast with a clear configuration error.","Catch the RuntimeException where conversion happens and log the offending enum value to identify the source."],"exampleFix":"// before\nCompressionType type = CompressionType.valueOf(config.getCompression()); // may yield unknown/null\nsend(convertToWireProtocol(type));\n// after\nCompressionType type = SUPPORTED.contains(config.getCompression())\n    ? CompressionType.valueOf(config.getCompression())\n    : CompressionType.NONE; // whitelist: NONE, LZ4, ZLIB, ZSTD, SNAPPY","handlingStrategy":"validation","validationCode":"private static final Set<CompressionType> SUPPORTED = EnumSet.of(\n    CompressionType.NONE, CompressionType.LZ4, CompressionType.ZLIB,\n    CompressionType.ZSTD, CompressionType.SNAPPY);\nif (type == null || !SUPPORTED.contains(type)) {\n    throw new IllegalArgumentException(\"unsupported compression type: \" + type);\n}","typeGuard":null,"tryCatchPattern":"try {\n    wire = CompressionCodecProvider.convertToWireProtocol(type);\n} catch (RuntimeException e) {\n    log.warn(\"Invalid compression type {}, falling back to NONE\", type);\n    wire = org.apache.pulsar.common.api.proto.CompressionType.NONE;\n}","preventionTips":["Whitelist compression settings at configuration load time.","Null-check configured compression values before conversion.","Keep client and broker versions aligned on supported codecs."],"tags":["compression","enum","configuration","wire-protocol"],"backgroundTag":"invalid-compression-type","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}