{"record":{"id":"736d8f988d454b60","repo":"apache/hadoop","slug":"unsupported-compression-algorithm-name","errorCode":null,"errorMessage":"Unsupported compression algorithm name: ","messagePattern":"Unsupported compression algorithm name: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/Compression.java","lineNumber":368,"sourceCode":"        CodecPool.returnDecompressor(decompressor);\n      }\n    }\n\n    public String getName() {\n      return compressName;\n    }\n  }\n\n  public static Algorithm getCompressionAlgorithmByName(String compressName) {\n    Algorithm[] algos = Algorithm.class.getEnumConstants();\n\n    for (Algorithm a : algos) {\n      if (a.getName().equals(compressName)) {\n        return a;\n      }\n    }\n\n    throw new IllegalArgumentException(\n        \"Unsupported compression algorithm name: \" + compressName);\n  }\n\n  static String[] getSupportedAlgorithms() {\n    Algorithm[] algos = Algorithm.class.getEnumConstants();\n\n    ArrayList<String> ret = new ArrayList<String>();\n    for (Algorithm a : algos) {\n      if (a.isSupported()) {\n        ret.add(a.getName());\n      }\n    }\n    return ret.toArray(new String[ret.size()]);\n  }\n}\n","sourceCodeStart":350,"sourceCodeEnd":384,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/Compression.java#L350-L384","documentation":"Thrown by Compression.getCompressionAlgorithmByName(String) when the argument matches no Algorithm enum constant (lzo, gz, snappy, none). TFile uses this lookup to translate a compression name into an algorithm, so any unrecognized string is rejected with IllegalArgumentException before a writer is created. Note that a known-but-unsupported name (e.g. \"lzo\" without the codec) does NOT fail here; only a misspelled or unknown name does.","triggerScenarios":"Passing a user- or config-supplied compression string to new TFile.Writer(...) or directly to Compression.getCompressionAlgorithmByName() when it is not exactly one of the enum names: \"gzip\", \"GZ\", \"zlib\", \"snappy4\", \"\" are all rejected.","commonSituations":"Configuration files reusing gzip-style names (\"gzip\" instead of \"gz\"); CLI arguments or job settings with typos or mixed case; code ported from another library whose codec names differ; version drift where an algorithm name was renamed or removed.","solutions":["Validate the name against TFile.getSupportedCompressionAlgorithms() (or the Algorithm enum) before using it","Use the TFile constants (TFile.COMPRESSION_GZ, TFile.COMPRESSION_LZO, TFile.COMPRESSION_SNAPPY, TFile.COMPRESSION_NONE) instead of string literals","Normalize external input: trim and lowercase it, and map known aliases such as \"gzip\"/\"zlib\" to \"gz\""],"exampleFix":"// before\nString name = jobConfig.get(\"my.compression\", \"gzip\");\nTFile.Writer w = new TFile.Writer(out, size, name, null);\n\n// after\nString name = jobConfig.get(\"my.compression\", TFile.COMPRESSION_GZ);\nif (!Arrays.asList(TFile.getSupportedCompressionAlgorithms()).contains(name)) {\n  throw new IllegalArgumentException(\"Unknown compression: \" + name);\n}\nTFile.Writer w = new TFile.Writer(out, size, name, null);","handlingStrategy":"validation","validationCode":"// Whitelist before use\nSet<String> ok = new HashSet<>(Arrays.asList(TFile.getSupportedCompressionAlgorithms()));\nif (!ok.contains(name)) {\n  throw new IllegalArgumentException(\n      \"compression '\" + name + \"' not recognized; valid: \" + ok);\n}\nCompression.Algorithm algo = Compression.getCompressionAlgorithmByName(name);","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) {\n  // report the valid names from TFile.getSupportedCompressionAlgorithms() to the caller\n}","preventionTips":["Always use the TFile.COMPRESSION_* constants instead of string literals","Validate config-sourced names once at startup with a clear message listing valid values","Normalize external names (trim, lowercase, alias-map gzip->gz) at the input boundary"],"tags":["hadoop","tfile","compression","input-validation"],"backgroundTag":"unsupported-parameter-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}