{"record":{"id":"eef833e947df5400","repo":"stanfordnlp/CoreNLP","slug":"error-on-line-eef833","errorCode":null,"errorMessage":"Error on line ","messagePattern":"Error on line ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/UnaryGrammar.java","lineNumber":297,"sourceCode":"    init();\n  }\n\n  /**\n   * Populates data in this UnaryGrammar from a character stream.\n   *\n   * @param in The Reader the grammar is read from.\n   * @throws IOException If there is a reading problem\n   */\n  public void readData(BufferedReader in) throws IOException {\n    String line;\n    int lineNum = 1;\n    // all lines have one rule per line\n    line = in.readLine();\n    while (line != null && line.length() > 0) {\n      try {\n        addRule(new UnaryRule(line, index));\n      } catch (Exception e) {\n        throw new IOException(\"Error on line \" + lineNum);\n      }\n      lineNum++;\n      line = in.readLine();\n    }\n    purgeRules();\n  }\n\n  /**\n   * Writes out data from this Object.\n   * @param w Data is written to this Writer\n   */\n  public void writeData(Writer w) {\n    PrintWriter out = new PrintWriter(w);\n    // all lines have one rule per line\n    for (UnaryRule ur : this) {\n      out.println(ur.toString(index));\n    }\n    out.flush();","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/UnaryGrammar.java#L279-L315","documentation":"UnaryGrammar.readData parses one unary rule per line from a serialized grammar file; if constructing/adding a UnaryRule from a line throws any exception, it is rethrown as IOException('Error on line ' + lineNum). It identifies a malformed line in the unary-rules section of the model file.","triggerScenarios":"Loading a parser grammar text file where a line in the unary rules section is blank-inconsistent, has wrong field count/format, or references labels not present in the index — e.g., an edited or version-mismatched grammar file.","commonSituations":"Hand-edited grammar files, truncated/corrupted downloads, or loading a model written by a different parser version into a newer loader.","solutions":["Restore the grammar file from a clean, matching-version copy (official model jar).","Inspect the reported line number and fix the malformed unary rule line (correct format: parent child score).","Regenerate the grammar by retraining/serializing with your current parser version.","Check for invisible characters or Windows/Unix line-ending corruption if the file was transferred across platforms."],"exampleFix":"// before (malformed unary rule line in grammar file)\nNP-JJ\n// after\nNP JJ 0.123","handlingStrategy":"validation","validationCode":"List<String> lines = Files.readAllLines(grammarPath);\nfor (int ln = 0; ln < lines.size(); ln++) {\n  String l = lines.get(ln);\n  if (l.length() > 0 && l.trim().split(\"\\\\s+\").length < 3)\n    System.err.println(\"Suspicious unary rule at line \" + (ln+1) + \": \" + l);\n}","typeGuard":null,"tryCatchPattern":"try {\n  parser = LexicalizedParser.loadModel(path);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Error on line \")) {\n    throw new IOException(\"Malformed unary rule in grammar file \" + path + \": \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Never hand-edit serialized grammar files; edit source treebanks and retrain.","Validate downloads (checksum/size).","Match model file version to library version.","Normalize line endings before processing text-format grammars."],"tags":["model-loading","file-format","grammar"],"backgroundTag":"schema-validation-failed","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"}