stanfordnlp/CoreNLP · error · RuntimeIOException
Resource or file looks like a gzip file, but is not
Error message
Resource or file looks like a gzip file, but is not: ${textFileOrUrl} What it means
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>'.
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.
Example fix
// before
InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem("model.ser.gz"); // not gzip
// after
File f = new File("model.ser.gz");
try (java.util.zip.GZIPInputStream test = new java.util.zip.GZIPInputStream(new java.io.FileInputStream(f))) {
// ok: really gzip
}
InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(f.getPath()); Defensive patterns
Strategy: try-catch
Validate before calling
try (InputStream test = new FileInputStream(f)) {
byte[] magic = test.readNBytes(2);
if (f.getName().endsWith(".gz") && !(magic[0] == 0x1f && magic[1] == (byte)0x8b)) {
throw new IllegalStateException(f + " has .gz name but is not gzip");
}
} Type guard
boolean isRealGzip(File f) throws IOException {
try (InputStream in = new FileInputStream(f)) {
int b0 = in.read(), b1 = in.read();
return b0 == 0x1f && b1 == 0x8b;
}
} Try / catch
try {
InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(name);
} catch (RuntimeIOException e) {
if (e.getMessage().contains("looks like a gzip file")) {
log.severe("Corrupt/mislabeled .gz: " + e.getMessage());
}
} Prevention
- Verify downloads with checksums and HTTP status
- Run `gunzip -t` on .gz files before use
- Rename files after decompressing in place
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not open jar file:
- Could not read from double initial LOP scales file
- Could not read from double initial weight file
- Could not read from float initial weight file
- argsToProperties could not read properties file: " + file
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6ce120cb36759df1.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/io/IOUtils.java:512
try {
// Maybe this happens to be some other format of URL?
URL u = new URL(textFileOrUrl);
URLConnection uc = u.openConnection();
in = uc.getInputStream();
} catch (IOException e2) {
// Don't make the original exception a cause, since it is usually bogus
throw new IOException("Unable to open \"" +
textFileOrUrl + "\" as " + "class path, filename or URL"); // , e2);
}
}
}
// If it is a GZIP stream then ungzip it
if (textFileOrUrl.endsWith(".gz")) {
try {
in = new GZIPInputStream(in);
} catch (Exception e) {
throw new RuntimeIOException("Resource or file looks like a gzip file, but is not: " + textFileOrUrl, e);
}
}
// buffer this stream. even gzip streams benefit from buffering,
// such as for the shift reduce parser [cdm 2016: I think this is only because default buffer is small; see below]
in = new BufferedInputStream(in);
return in;
}
// todo [cdm 2015]: I think GZIPInputStream has its own buffer and so we don't need to buffer in that case.
// todo: Though it's default size is 512 bytes so need to make 8K in constructor. Or else buffering outside gzip is faster
// todo: final InputStream is = new GZIPInputStream( new FileInputStream( file ), 65536 );
/**
* Quietly opens a File. If the file ends with a ".gz" extension,
* automatically opens a GZIPInputStream to wrap the constructed
* FileInputStream.View on GitHub (pinned to 1b7edd19c4)