{"record":{"id":"40f38559c4822ae5","repo":"apache/druid","slug":"s-is-not-a-valid-gz-file-name","errorCode":null,"errorMessage":"[%s] is not a valid gz file name","messagePattern":"\\[(.+?)\\] is not a valid gz file name","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/utils/CompressionUtils.java","lineNumber":790,"sourceCode":"    return fName.endsWith(Format.GZ.getSuffix()) && fName.length() > Format.GZ.getSuffix().length();\n  }\n\n  /**\n   * Get the file name without the .gz extension\n   *\n   * @param fname The name of the gzip file\n   *\n   * @return fname without the \".gz\" extension\n   *\n   * @throws IAE if fname is not a valid \"*.gz\" file name\n   */\n  public static String getGzBaseName(String fname)\n  {\n    final String reducedFname = Files.getNameWithoutExtension(fname);\n    if (isGz(fname) && !reducedFname.isEmpty()) {\n      return reducedFname;\n    }\n    throw new IAE(\"[%s] is not a valid gz file name\", fname);\n  }\n\n  /**\n   * Decompress an input stream from a file, based on the filename.\n   */\n  public static InputStream decompress(final InputStream in, final String fileName) throws IOException\n  {\n    if (fileName.endsWith(Format.GZ.getSuffix())) {\n      return gzipInputStream(in);\n    } else if (fileName.endsWith(Format.LZ4.getSuffix())) {\n      return new LZ4BlockInputStream(in);\n    } else if (fileName.endsWith(Format.BZ2.getSuffix())) {\n      return new BZip2CompressorInputStream(in, true);\n    } else if (fileName.endsWith(Format.XZ.getSuffix())) {\n      return new XZCompressorInputStream(in, true);\n    } else if (fileName.endsWith(Format.SNAPPY.getSuffix())) {\n      return new FramedSnappyCompressorInputStream(in);\n    } else if (fileName.endsWith(Format.ZSTD.getSuffix())) {","sourceCodeStart":772,"sourceCodeEnd":808,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/utils/CompressionUtils.java#L772-L808","documentation":"Thrown by CompressionUtils.getGzBaseName when the input filename does not pass isGz (does not end with the .gz suffix) or its name minus extension is empty. The method's job is to strip the .gz suffix to derive the base file name, so it validates the name is a gzip name first.","triggerScenarios":"Calling getGzBaseName with a name like data.zip, data (no extension), or an empty string; also triggered by a file named only .gz whose reduced name is empty.","commonSituations":"Speculative decompression code calling getGzBaseName on every file in a directory without checking the extension first, firehose configs pointing at non-gz files, or copy-pasted filenames with wrong extensions.","solutions":["Check CompressionUtils.isGz(fname) before calling getGzBaseName and handle non-gz files separately.","Correct the filename/extension of the source file.","For mixed inputs, use CompressionUtils.decompress(in, fileName) which dispatches on extension instead of assuming gzip.","Filter directory listings to *.gz files before deriving base names."],"exampleFix":"// before\nString base = CompressionUtils.getGzBaseName(fileName); // fileName = \"data.zip\"\n// after\nif (CompressionUtils.isGz(fileName)) {\n  String base = CompressionUtils.getGzBaseName(fileName);\n}","handlingStrategy":"validation","validationCode":"if (fname == null || !fname.endsWith(\".gz\")\n    || Files.getNameWithoutExtension(fname).isEmpty()) {\n  throw new IllegalArgumentException(\"Not a valid gz name: \" + fname);\n}","typeGuard":"static boolean isValidGzName(String fname) {\n  return fname != null && CompressionUtils.isGz(fname)\n      && !Files.getNameWithoutExtension(fname).isEmpty();\n}","tryCatchPattern":"try {\n  base = CompressionUtils.getGzBaseName(fname);\n} catch (IllegalArgumentException e) {\n  // not a gz file; handle as uncompressed input\n  base = Files.getNameWithoutExtension(fname);\n}","preventionTips":["Check isGz() before calling getGzBaseName","Filter file listings to *.gz before deriving base names","Use CompressionUtils.decompress() for extension-based dispatch on mixed inputs","Beware of a file named just '.gz' which yields an empty base name"],"tags":["filename","gzip","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}