{"record":{"id":"6ce120cb36759df1","repo":"stanfordnlp/CoreNLP","slug":"resource-or-file-looks-like-a-gzip-file-but-is-no","errorCode":null,"errorMessage":"Resource or file looks like a gzip file, but is not: ${textFileOrUrl}","messagePattern":"Resource or file looks like a gzip file, but is not: (.+?)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":512,"sourceCode":"        try {\n          // Maybe this happens to be some other format of URL?\n          URL u = new URL(textFileOrUrl);\n          URLConnection uc = u.openConnection();\n          in = uc.getInputStream();\n        } catch (IOException e2) {\n          // Don't make the original exception a cause, since it is usually bogus\n          throw new IOException(\"Unable to open \\\"\" +\n                  textFileOrUrl + \"\\\" as \" + \"class path, filename or URL\"); // , e2);\n        }\n      }\n    }\n\n    // If it is a GZIP stream then ungzip it\n    if (textFileOrUrl.endsWith(\".gz\")) {\n      try {\n        in = new GZIPInputStream(in);\n      } catch (Exception e) {\n        throw new RuntimeIOException(\"Resource or file looks like a gzip file, but is not: \" + textFileOrUrl, e);\n      }\n    }\n\n    // buffer this stream.  even gzip streams benefit from buffering,\n    // such as for the shift reduce parser [cdm 2016: I think this is only because default buffer is small; see below]\n    in = new BufferedInputStream(in);\n\n    return in;\n  }\n\n\n  // todo [cdm 2015]: I think GZIPInputStream has its own buffer and so we don't need to buffer in that case.\n  // todo: Though it's default size is 512 bytes so need to make 8K in constructor. Or else buffering outside gzip is faster\n  // todo: final InputStream is = new GZIPInputStream( new FileInputStream( file ), 65536 );\n  /**\n   * Quietly opens a File. If the file ends with a \".gz\" extension,\n   * automatically opens a GZIPInputStream to wrap the constructed\n   * FileInputStream.","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L494-L530","documentation":"If the resource name ends with .gz, IOUtils wraps the opened stream in a GZIPInputStream. If the stream is not actually gzip-compressed, wrapping throws and the method rethrows RuntimeIOException 'Resource or file looks like a gzip file, but is not: <name>'.","triggerScenarios":"Opening a file whose name ends in .gz but whose content is plain text, an HTML error page (e.g. failed download), a truncated/corrupt gzip file, or already-decompressed data left with a .gz suffix.","commonSituations":"Download interrupted or proxy returned an HTML 404 page saved as models.ser.gz; a preprocessing step gunzipped in place without renaming; copy truncated by disk full.","solutions":["Verify the file really is gzip: run `file x.gz` or `gunzip -t x.gz`; re-download/recreate if corrupt.","Rename the file to drop .gz if it's actually uncompressed.","Remove the .gz suffix from the name passed to IOUtils so it won't try to ungzip.","Check the download step's HTTP status; don't save error pages as .gz."],"exampleFix":"// before\nInputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(\"model.ser.gz\"); // not gzip\n// after\nFile f = new File(\"model.ser.gz\");\ntry (java.util.zip.GZIPInputStream test = new java.util.zip.GZIPInputStream(new java.io.FileInputStream(f))) {\n  // ok: really gzip\n}\nInputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(f.getPath());","handlingStrategy":"try-catch","validationCode":"try (InputStream test = new FileInputStream(f)) {\n  byte[] magic = test.readNBytes(2);\n  if (f.getName().endsWith(\".gz\") && !(magic[0] == 0x1f && magic[1] == (byte)0x8b)) {\n    throw new IllegalStateException(f + \" has .gz name but is not gzip\");\n  }\n}","typeGuard":"boolean isRealGzip(File f) throws IOException {\n  try (InputStream in = new FileInputStream(f)) {\n    int b0 = in.read(), b1 = in.read();\n    return b0 == 0x1f && b1 == 0x8b;\n  }\n}","tryCatchPattern":"try {\n  InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(name);\n} catch (RuntimeIOException e) {\n  if (e.getMessage().contains(\"looks like a gzip file\")) {\n    log.severe(\"Corrupt/mislabeled .gz: \" + e.getMessage());\n  }\n}","preventionTips":["Verify downloads with checksums and HTTP status","Run `gunzip -t` on .gz files before use","Rename files after decompressing in place"],"tags":["gzip","io","corrupt-file"],"backgroundTag":"corrupt-file","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}