{"record":{"id":"89c8f02152ebef19","repo":"stanfordnlp/CoreNLP","slug":"file-not-found","errorCode":null,"errorMessage":"File not found: ","messagePattern":"File not found: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/LexicalizedParser.java","lineNumber":580,"sourceCode":"    return null;\n  }\n\n\n  public static LexicalizedParser getParserFromSerializedFile(String serializedFileOrUrl) {\n    try {\n      Timing tim = new Timing();\n      ObjectInputStream in = IOUtils.readStreamFromString(serializedFileOrUrl);\n      LexicalizedParser pd = loadModel(in);\n\n      in.close();\n      log.info(\"Loading parser from serialized file \" + serializedFileOrUrl + \" ... done [\" + tim.toSecondsString() + \" sec].\");\n      return pd;\n    } catch (InvalidClassException ice) {\n      // For this, it's not a good idea to continue and try it as a text file!\n      throw new RuntimeException(\"Invalid class in file: \" + serializedFileOrUrl, ice);\n    } catch (FileNotFoundException fnfe) {\n      // For this, it's not a good idea to continue and try it as a text file!\n      throw new RuntimeException(\"File not found: \" + serializedFileOrUrl, fnfe);\n    } catch (StreamCorruptedException sce) {\n      // suppress error message, on the assumption that we've really got\n      // a text grammar, and that'll be tried next\n      log.info(\"Attempting to load \" + serializedFileOrUrl +\n               \" as a serialized grammar caused error below, but this may just be because it's a text grammar!\");\n      log.info(sce);\n    } catch (Exception e) {\n      log.error(e);\n    }\n    return null;\n  }\n\n\n  private static void printOptions(boolean train, Options op) {\n    op.display();\n    if (train) {\n      op.trainOptions.display();\n    } else {","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/LexicalizedParser.java#L562-L598","documentation":"getParserFromSerializedFile could not open the serialized parser file: java.io.FileNotFoundException was caught and rethrown as RuntimeException(\"File not found: ...\"). The requested model path/URL does not exist or is not readable.","triggerScenarios":"Calling LexicalizedParser.loadModel(path) or the -model CLI option with a path that does not exist, a typo'd filename, a path relative to the wrong working directory, or an inaccessible URL/classpath resource.","commonSituations":"Running from a different working directory than assumed in the script; model not extracted from a zip/tarball; missing model artifact dependency (e.g. models jar not on classpath); typo like englishPCFG.ser.gx; file removed after a clean build.","solutions":["Verify the exact path in the message exists: ls <path> / resolve it relative to the process working directory","Use a fully qualified path or load from classpath resource (e.g. \"/edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz\")","Install/download the matching models package (Stanford CoreNLP models jar or zip) that contains the grammar","Check file permissions and that the user running the JVM can read it"],"exampleFix":"// before\nLexicalizedParser lp = LexicalizedParser.loadModel(\"englishPCFG.ser.gz\"); // only works if cwd is right\n// after\nLexicalizedParser lp = LexicalizedParser.loadModel(\"/models/englishPCFG.ser.gz\"); // absolute path","handlingStrategy":"validation","validationCode":"java.io.File f = new java.io.File(modelPath);\nif (!f.isFile() || !f.canRead()) throw new IllegalArgumentException(\"Parser model missing/unreadable: \" + f.getAbsolutePath());","typeGuard":null,"tryCatchPattern":"try {\n  LexicalizedParser lp = LexicalizedParser.loadModel(path);\n} catch (RuntimeException e) {\n  if (e.getCause() instanceof FileNotFoundException) {\n    throw new IllegalStateException(\"Model file not found: \" + path + \" (cwd=\" + new File(\".\").getAbsolutePath() + \")\", e);\n  }\n  throw e;\n}","preventionTips":["Log the resolved absolute path and working directory before loading","Ship models on the classpath and load via classpath resource paths","Add the models artifact to your build (CoreNLP models jar) so models always exist"],"tags":["file-not-found","parser","model-loading","java"],"backgroundTag":"file-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"}