stanfordnlp/CoreNLP · warning
not added
Error message
${phraseText} not added What it means
PhraseTable.addPhrase inserts a phrase into a trie. If after trying all insertion strategies nothing was added and the token list is empty (the phrase produced no words), a warning '<phraseText> not added' is logged. Non-empty duplicate phrases are handled separately via the oldphrase branch.
Solutions
- Skip blank/whitespace-only lines when loading the phrase file.
- Trim and validate phraseText before calling addPhrase.
- Sanitize the source file so each record has a non-empty first field.
Example fix
// before
for (String line : lines) table.addPhrase(line, null, null);
// after
for (String line : lines) {
if (line == null || line.trim().isEmpty()) continue;
table.addPhrase(line, null, null);
} Defensive patterns
Strategy: validation
Validate before calling
if (phraseText == null || phraseText.trim().isEmpty()) {
return; // nothing to add
} Type guard
static boolean isBlank(String s) { return s == null || s.trim().isEmpty(); } Prevention
- Filter blank lines when loading phrase files.
- Trim phrases before insertion.
- Log and count skipped lines at load time.
When it happens
Trigger: Calling addPhrase with a phraseText that normalizes/splits to zero tokens (empty string, only delimiters/whitespace), so wordList.size()==0 and no trie node can be created.
Common situations: Loading a phrase file with blank lines or lines whose first field is empty after splitting; passing empty strings programmatically from user input.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Annotation field cannot be null
- Attribute already defined:
- Attribute already defined
- Attribute match already defined:
- Attribute match already defined
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/4e5d3061a38b28b1.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/PhraseTable.java:452
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);
if (oldphrase != null) {
int matchedTokenEnd = checkWordListMatch(
oldphrase, wordList, 0, wordList.size(), wordList.size(), true);
if (matchedTokenEnd >= 0) {
oldPhraseNewFormAdded = oldphrase.addForm(phraseText);
} else {
// create list with this phrase and other and put it here
Phrase newphrase = new Phrase(wordList, phraseText, tag, phraseData);
List<Phrase> list = new ArrayList<>(2);
list.add(oldphrase);
list.add(newphrase);
tree.put(PHRASE_END, list);
newPhraseAdded = true;
}
} else {
Phrase newphrase = new Phrase(wordList, phraseText, tag, phraseData);View on GitHub (pinned to 1b7edd19c4)