stanfordnlp/CoreNLP · error · RuntimeException
PARSER RETURNED NULL!!!
Error message
PARSER RETURNED NULL!!!
What it means
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.
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
Example fix
// before
tree = lp.parseTree(s);
if (tree == null) { throw new RuntimeException("PARSER RETURNED NULL!!!"); }
// after
tree = lp.parseTree(s);
if (tree == null) {
log.warning("Failed to parse sentence: " + s);
failedSents++;
continue;
} Defensive patterns
Strategy: try-catch
Validate before calling
// skip sentences the parser cannot handle
if (s.size() > op.testOptions.maxLength) { log.warning("Sentence too long, skipping"); continue; } Try / catch
try { tree = lp.parseTree(s); if (tree == null) { failed++; continue; } } catch (RuntimeException e) { failed++; log.warning("Parse failed: " + s); continue; } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Input word not tagged
- This evaluator only works for the ShiftReduceParser
- This evaluator only works for the ShiftReduceParser
- Arc input is in unexpected format:
- AttachmentScore cannot be used when count
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6fb6bcde3a6da3e2.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/ChineseCharacterBasedLexiconTraining.java:336
log.info("Processing sentence; length: " + goldSentence.size());
}
List<HasWord> s;
if (segmentWords) {
StringBuilder goldCharBuf = new StringBuilder();
for (HasWord aGoldSentence : goldSentence) {
StringLabel word = (StringLabel) aGoldSentence;
goldCharBuf.append(word.value());
}
String goldChars = goldCharBuf.toString();
s = seg.segment(goldChars);
} else {
s = goldSentence;
}
Tree tree;
if (parse) {
tree = lp.parseTree(s);
if (tree == null) {
throw new RuntimeException("PARSER RETURNED NULL!!!");
}
} else {
tree = Trees.toFlatTree(s);
tree = subcategoryStripper.transformTree(tree);
}
if (pw != null) {
if (parse) {
tree.pennPrint(pw);
} else {
Iterator sentIter = s.iterator();
for (; ;) {
Word word = (Word) sentIter.next();
pw.print(word.word());
if (sentIter.hasNext()) {
pw.print(" ");
} else {
break;View on GitHub (pinned to 1b7edd19c4)