stanfordnlp/CoreNLP · error · java.lang.RuntimeException
Unexpected class in list while converting list to map
Error message
Unexpected class in list while converting list to map
What it means
When converting a List trie node into a Map (to add a new branching word), addPhrase re-inserts every existing element; any element that is not a Phrase aborts with 'Unexpected class in list ... while converting list to map'.
Solutions
- Rebuild the phrase table using only public addPhrase/readPhrases entry points
- Locate and remove non-Phrase elements from list nodes before inserting longer phrases
- Guard population code to run single-threaded or under synchronization
Example fix
// before treeList.add(someMap); // will break later list->map conversion // after Phrase p = new Phrase(wordList, text, tag, data); table.addPhrase(...); // library decides list vs map layout
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure list nodes contain only Phrase before triggering list->map conversion if (listNodeContainsNonPhrase) rebuildTable();
Type guard
static boolean convertibleList(List<?> l) { return l.stream().allMatch(o -> o instanceof Phrase); } Try / catch
try { table.addPhrase(wordList, text, tag, data); } catch (RuntimeException e) { if (e.getMessage().contains("converting list to map")) { rebuildPhraseTableFromSource(); } else throw e; } Prevention
- Only add Phrase objects to list nodes
- Build the table before concurrent reads/writes
- Treat structural exceptions as signals to rebuild from source data
When it happens
Trigger: A list node being promoted to a map contains a non-Phrase element (e.g. the single continuation Map or a foreign object), which cannot be re-keyed under the new word.
Common situations: Same corruption sources as 416–418: direct manipulation of the internal tree, deserialization that lost types, or threaded writes without synchronization.
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
- 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
- More than one map in list while looking up word () in…
- Unexpected class in list while looking up word () in…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/8dbafeecf6104963.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/PhraseTable.java:436
throw new RuntimeException("Unexpected class in list " + obj.getClass() + " while adding word "
+ i + "(" + word + ") in phrase " + phraseText);
}
}
if (!phraseAdded && nMaps == 0) {
// add to list
Phrase newphrase = new Phrase(wordList, phraseText, tag, phraseData);
lookupList.add(newphrase);
newPhraseAdded = true;
phraseAdded = true;
if (lookupList.size() > MAX_LIST_SIZE) {
// convert lookupList (should consist only of phrases) to map
Map newMap = new HashMap<String,Object>(lookupList.size());
for (Object obj:lookupList) {
if (obj instanceof Phrase) {
Phrase oldphrase = (Phrase) obj;
addPhrase(newMap, oldphrase, i+1);
} else {
throw new RuntimeException("Unexpected class in list " + obj.getClass() + " while converting list to map");
}
}
tree.put(word,newMap);
}
}
} else {
throw new RuntimeException("Unexpected class in list " + node.getClass() + " while adding word "
+ i + "(" + word + ") in phrase " + phraseText);
}
if (phraseAdded) {
break;
}
}
if (!phraseAdded) {
if (wordList.size() == 0) {
log.warn(phraseText + " not added");
} else {
Phrase oldphrase = (Phrase) tree.get(PHRASE_END);View on GitHub (pinned to 1b7edd19c4)