{"record":{"id":"07f28cb9041615c4","repo":"stanfordnlp/CoreNLP","slug":"could-not-find-modelname-inside-zipfilename","errorCode":null,"errorMessage":"Could not find ${modelName} inside ${zipFilename}","messagePattern":"Could not find (.+?) inside (.+?)","errorType":"exception","errorClass":"java.io.FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/common/ParserGrammar.java","lineNumber":229,"sourceCode":"      File file = new File(zipFilename);\n      if (file.exists()) {\n        try (ZipFile zin = new ZipFile(file)) {\n          ZipEntry zentry = zin.getEntry(modelName);\n          if (zentry != null) {\n            InputStream in = zin.getInputStream(zentry);\n            // gunzip it if necessary\n            if (modelName.endsWith(\".gz\")) {\n              in = new GZIPInputStream(in);\n            }\n            ObjectInputStream ois = new ObjectInputStream(in);\n            object = ois.readObject();\n\n            ois.close();\n            in.close();\n          }\n        }\n      } else {\n        throw new FileNotFoundException(\"Could not find \" + modelName +\n                                        \" inside \" + zipFilename);\n      }\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    } catch (ClassNotFoundException e) {\n      throw new RuntimeException(e);\n    }\n\n    if (object instanceof ParserGrammar) {\n      return (ParserGrammar) object;\n    }\n    throw new ClassCastException(\"Wanted LexicalizedParser, got \" +\n                                 object.getClass());\n  }\n\n\n}\n","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/common/ParserGrammar.java#L211-L247","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["List the zip entries (unzip -l zipFilename) and pass the exact entry name as modelName","Download/rebuild the correct parser model zip that contains the expected entry","Check for a version mismatch between the library version and the model file"],"exampleFix":"// before\nParserGrammar.loadModelFromZip(\"englishPCFG.zip\", \"wrongName.ser.gz\");\n// after\nParserGrammar.loadModelFromZip(\"englishPCFG.zip\", \"englishPCFG.ser.gz\");","handlingStrategy":"validation","validationCode":"try (ZipFile zf = new ZipFile(zipFilename)) { if (zf.getEntry(modelName) == null) throw new FileNotFoundException(\"zip lacks entry \" + modelName + \"; has: \" + Collections.list(zf.entries())); }","typeGuard":null,"tryCatchPattern":"try { pg = ParserGrammar.loadModelFromZip(zip, name); } catch (RuntimeIOException e) { /* message wraps FileNotFoundException; inspect cause and retry with corrected entry name */ }","preventionTips":["List zip entries before loading to confirm the exact model entry name","Keep model archive names aligned with the library version you ship","Do not hard-code default model entry names across library versions"],"tags":["java","zip","file-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}