{"record":{"id":"6fb6bcde3a6da3e2","repo":"stanfordnlp/CoreNLP","slug":"parser-returned-null","errorCode":null,"errorMessage":"PARSER RETURNED NULL!!!","messagePattern":"PARSER RETURNED NULL!!!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ChineseCharacterBasedLexiconTraining.java","lineNumber":336,"sourceCode":"          log.info(\"Processing sentence; length: \" + goldSentence.size());\n        }\n        List<HasWord> s;\n        if (segmentWords) {\n          StringBuilder goldCharBuf = new StringBuilder();\n          for (HasWord aGoldSentence : goldSentence) {\n            StringLabel word = (StringLabel) aGoldSentence;\n            goldCharBuf.append(word.value());\n          }\n          String goldChars = goldCharBuf.toString();\n          s = seg.segment(goldChars);\n        } else {\n          s = goldSentence;\n        }\n        Tree tree;\n        if (parse) {\n          tree = lp.parseTree(s);\n          if (tree == null) {\n            throw new RuntimeException(\"PARSER RETURNED NULL!!!\");\n          }\n        } else {\n          tree = Trees.toFlatTree(s);\n          tree = subcategoryStripper.transformTree(tree);\n        }\n\n        if (pw != null) {\n          if (parse) {\n            tree.pennPrint(pw);\n          } else {\n            Iterator sentIter = s.iterator();\n            for (; ;) {\n              Word word = (Word) sentIter.next();\n              pw.print(word.word());\n              if (sentIter.hasNext()) {\n                pw.print(\" \");\n              } else {\n                break;","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ChineseCharacterBasedLexiconTraining.java#L318-L354","documentation":"During evaluation/testing in ChineseCharacterBasedLexiconTraining.main, if parsing is enabled and lp.parseTree(sentence) returns null — meaning the parser failed to produce any parse for the sentence — the code throws RuntimeException(\"PARSER RETURNED NULL!!!\") instead of silently skipping.","triggerScenarios":"Testing with a character-based lexicon/parser on a sentence that fails to parse (e.g., no reachable analysis under the grammar, extremely long or degenerate input, corrupted lexicon yielding zero-probability everything).","commonSituations":"Feeding test sentences containing characters unseen in training so all analyses score -Inf; misconfigured lexicon/parser options; gold-sentence handling where sentence length exceeds parser limits.","solutions":["Check/raise parser options (e.g., maxLength / sentence length limits) and ensure fallback scoring for unseen characters","Log the failing sentence and either skip it or record a parse failure instead of throwing, so a full test set can be evaluated","Verify the lexicon was trained/loaded correctly (unseen-character backoff present)","Catch the RuntimeException around the parse loop and continue with the next sentence"],"exampleFix":"// before\ntree = lp.parseTree(s);\nif (tree == null) { throw new RuntimeException(\"PARSER RETURNED NULL!!!\"); }\n// after\ntree = lp.parseTree(s);\nif (tree == null) {\n  log.warning(\"Failed to parse sentence: \" + s);\n  failedSents++;\n  continue;\n}","handlingStrategy":"try-catch","validationCode":"// skip sentences the parser cannot handle\nif (s.size() > op.testOptions.maxLength) { log.warning(\"Sentence too long, skipping\"); continue; }","typeGuard":null,"tryCatchPattern":"try { tree = lp.parseTree(s); if (tree == null) { failed++; continue; } } catch (RuntimeException e) { failed++; log.warning(\"Parse failed: \" + s); continue; }","preventionTips":["Train the lexicon with broad character coverage or add unseen-character backoff","Set realistic maxLength and test options","Collect parse failures per sentence rather than aborting the whole evaluation run"],"tags":["parser","parsing-failure","evaluation","null"],"backgroundTag":"parse-error","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}