{"record":{"id":"0ce9e4b9b016434d","repo":"stanfordnlp/CoreNLP","slug":"error-on-line-0ce9e4","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/BinaryGrammar.java","lineNumber":265,"sourceCode":"  }\n\n  /**\n   * Populates data in this BinaryGrammar from the character stream\n   * given by the Reader r.\n   *\n   * @param in Where input is read from\n   * @throws IOException If format is bung\n   */\n  public void readData(BufferedReader in) throws IOException {\n    //if (Test.verbose) log.info(\">> readData\");\n    String line;\n    int lineNum = 1;\n    line = in.readLine();\n    while (line != null && line.length() > 0) {\n      try {\n        addRule(new BinaryRule(line, index));\n      } catch (Exception e) {\n        throw new IOException(\"Error on line \" + lineNum);\n      }\n      lineNum++;\n      line = in.readLine();\n    }\n    splitRules();\n  }\n\n  /**\n   * Writes out data from this Object to the Writer w.\n   *\n   * @param w Where output is written\n   * @throws IOException If data can't be written\n   */\n  public void writeData(Writer w) throws IOException {\n    PrintWriter out = new PrintWriter(w);\n    for (BinaryRule br : this) {\n      out.println(br.toString(index));\n    }","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/BinaryGrammar.java#L247-L283","documentation":"readData in BinaryGrammar parses the grammar section of a text-format parser grammar file, constructing a BinaryRule from each non-empty line. If BinaryRule's constructor throws for any line (malformed rule syntax, state names absent from the state Index), the original exception is swallowed and replaced with a bare IOException(\"Error on line N\"), losing the cause.","triggerScenarios":"Loading a parser from a text grammar file (getParserFromTextFile) where a line in the binary-rules section is not a valid \"parent @ left right\" style rule or references state names not present in the grammar's state index.","commonSituations":"Hand-edited or truncated grammar/text parser files, files from a different grammar format or older Stanford Parser version, wrong file fed to Options/lexparser load path.","solutions":["Open the grammar file and inspect/fix the rule on the reported line number (lineNum counts from 1 within the binary-grammar section)","Regenerate the grammar file with the same version of the parser that will read it instead of hand-editing","Temporarily recompile readData to wrap 'e' (throw new IOException(\"Error on line \" + lineNum, e)) to see the real parse failure","Verify you are loading the intended .txt/.gz grammar path, not a different or stale file"],"exampleFix":"// before (opaque)\nthrow new IOException(\"Error on line \" + lineNum);\n// after (preserve cause)\nthrow new IOException(\"Error on line \" + lineNum, e);","handlingStrategy":"validation","validationCode":"// pre-scan grammar lines before readData\nint n = 1;\nfor (String line : Files.readAllLines(grammarPath)) {\n  if (!line.isEmpty() && line.split(\"\\\\s+\").length != 3)\n    throw new IllegalArgumentException(\"Bad binary rule at line \" + n + \": \" + line);\n  n++;\n}","typeGuard":null,"tryCatchPattern":"try { bg.readData(in); } catch (IOException e) { log.error(\"Grammar file malformed at \" + e.getMessage() + \" — fix or regenerate grammar file\"); }","preventionTips":["Never hand-edit text grammar files; regenerate them with the same parser version","Keep model files and parser jars version-aligned","Wrap readData with a cause-preserving wrapper during development to see real parse errors"],"tags":["io","parser","grammar-file","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T20:17:13.540Z"}