stanfordnlp/CoreNLP · error · java.lang.RuntimeException
Unexpected class in list while looking up
Error message
Unexpected class in list while looking up
What it means
In the exhaustive multi-match lookup routine, each element popped from a List node must be a Phrase or a Map to push on the search stack. Any other class triggers this RuntimeException, signaling the trie's internal structure is not what the search expects.
Solutions
- Populate the table under a single lock, then use it read-only from multiple threads.
- Rebuild from the phrase list rather than repairing the corrupted instance.
- Avoid keeping references to internal Map/List nodes returned by reflection.
- Upgrade/report to Stanford NLP if single-threaded usage still throws.
Example fix
// before thread1: table.addPhrase(p1); thread2: table.lookupByRegex(...); // after buildTable(); // complete all addPhrase calls first matches = table.lookupByRegex(...); // now read-only
Defensive patterns
Strategy: try-catch
Validate before calling
// finish all addPhrase calls before multi-match lookups
if (building) throw new IllegalStateException("table still being populated"); Try / catch
try { matches = table.lookupByRegex(...); } catch (RuntimeException e) { if (e.getMessage().contains("while looking up")) { table = rebuildTable(phrases); } else { throw e; } } Prevention
- Complete population before enumerating matches.
- Do not share partially built tables.
- Avoid reflective access to rootTree.
When it happens
Trigger: Calling the public lookup variants that enumerate all matches on a table whose lists contain foreign objects - after concurrent writes or external corruption.
Common situations: Unsynchronized population followed by multi-match lookups; direct manipulation of internal maps; version-mismatched deserialization.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- More than one map in list while looking up word () in…
- Unexpected class while adding word () in phrase
- More than one map in list while adding word () in phrase
- Unexpected class in list while adding word () in phrase
- Unexpected class in list while converting list to map
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/0319f779fd2876c9.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/PhraseTable.java:826
tree = (Map<String, Object>) node;
} else if (node instanceof List) {
// Search through list for matches to word (at this point, the table is small, so no Map)
List lookupList = (List) node;
for (Object obj:lookupList) {
if (obj instanceof Phrase) {
// check rest of the phrase matches
Phrase phrase = (Phrase) obj;
if (acceptablePhrases == null || acceptablePhrases.contains(phrase)) {
int matchedTokenEnd = checkWordListMatch(
phrase, tokens, cur.tokenStart, cur.tokenEnd, i+1, matchEnd);
if (matchedTokenEnd >= 0) {
matched.add(new PhraseMatch(phrase, cur.tokenStart, matchedTokenEnd));
}
}
} else if (obj instanceof Map) {
todoStack.push(new StackEntry((Map<String,Object>) obj, cur.tokenStart, i+1, cur.tokenEnd, -1));
} else {
throw new RuntimeException("Unexpected class in list " + obj.getClass() + " while looking up " + word);
}
}
break;
} else {
throw new RuntimeException("Unexpected class " + node.getClass() + " while looking up " + word);
}
}
if (cur.continueAt >= 0) {
int newStart = (cur.continueAt > cur.tokenStart)? cur.continueAt: cur.tokenStart+1;
if (newStart < cur.tokenEnd) {
todoStack.push(new StackEntry(cur.tree, newStart, newStart, cur.tokenEnd, newStart+1));
}
}
}
return matched;
}
public Iterator<Phrase> iterator() {View on GitHub (pinned to 1b7edd19c4)