stanfordnlp/CoreNLP · error · java.io.FileNotFoundException

Could not find inside

Error message

Could not find ${modelName} inside ${zipFilename}

What it means

ParserGrammar.loadModelFromZip() throws this FileNotFoundException when the requested modelName entry does not exist inside the given zip archive. The zip was opened successfully, but it contains no entry matching the model name, so deserialization cannot proceed.

Solutions

  1. List the zip entries (unzip -l zipFilename) and pass the exact entry name as modelName
  2. Download/rebuild the correct parser model zip that contains the expected entry
  3. Check for a version mismatch between the library version and the model file

Example fix

// before
ParserGrammar.loadModelFromZip("englishPCFG.zip", "wrongName.ser.gz");
// after
ParserGrammar.loadModelFromZip("englishPCFG.zip", "englishPCFG.ser.gz");
Defensive patterns

Strategy: validation

Validate before calling

try (ZipFile zf = new ZipFile(zipFilename)) { if (zf.getEntry(modelName) == null) throw new FileNotFoundException("zip lacks entry " + modelName + "; has: " + Collections.list(zf.entries())); }

Try / catch

try { pg = ParserGrammar.loadModelFromZip(zip, name); } catch (RuntimeIOException e) { /* message wraps FileNotFoundException; inspect cause and retry with corrected entry name */ }

Prevention

When it happens

Trigger: Calling loadModelFromZip(zipFilename, modelName) where the zip lacks an entry named modelName, e.g. after the zip was rebuilt with different internal entry names, or a default model name was assumed but the archive stores a different path.

Common situations: Re-zipping a parser model with different entry names; passing the wrong zip file; version changes where the shipped model filename inside the jar/zip changed.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/07f28cb9041615c4. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/common/ParserGrammar.java:229

      File file = new File(zipFilename);
      if (file.exists()) {
        try (ZipFile zin = new ZipFile(file)) {
          ZipEntry zentry = zin.getEntry(modelName);
          if (zentry != null) {
            InputStream in = zin.getInputStream(zentry);
            // gunzip it if necessary
            if (modelName.endsWith(".gz")) {
              in = new GZIPInputStream(in);
            }
            ObjectInputStream ois = new ObjectInputStream(in);
            object = ois.readObject();

            ois.close();
            in.close();
          }
        }
      } else {
        throw new FileNotFoundException("Could not find " + modelName +
                                        " inside " + zipFilename);
      }
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException(e);
    }

    if (object instanceof ParserGrammar) {
      return (ParserGrammar) object;
    }
    throw new ClassCastException("Wanted LexicalizedParser, got " +
                                 object.getClass());
  }


}

View on GitHub (pinned to 1b7edd19c4)