stanfordnlp/CoreNLP · error · IllegalArgumentException
Cannot put a child trie with no keys
Error message
Cannot put a child trie with no keys
What it means
TrieMap.putChildTrie throws IllegalArgumentException('Cannot put a child trie with no keys') when the computed parent trie is null — i.e., the key path used to locate the parent was empty, so there is nowhere to attach the child. The trie requires a non-empty key sequence to insert.
Solutions
- Skip the insert when the key is empty, or treat empty key as the root value separately.
- Sanitize input data so rules/phrases never produce zero-length keys.
- If an empty key is meaningful, store the value in the root TrieMap's value field instead.
Example fix
// before
trie.put(tokens, value); // tokens may be empty
// after
if (tokens == null || tokens.isEmpty()) {
return; // or handle root-level value
}
trie.put(tokens, value); Defensive patterns
Strategy: validation
Validate before calling
if (key == null || key.isEmpty()) {
throw new IllegalArgumentException("cannot insert empty key into TrieMap");
} Type guard
static <K> boolean hasKey(Iterable<K> key) {
return key != null && key.iterator().hasNext();
} Try / catch
try {
trie.put(key, value);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("no keys")) {
log.warn("skipped empty-key insert");
} else throw e;
} Prevention
- Filter empty token lists/phrases before loading rules into tries.
- Decide explicitly how empty keys should be treated (skip vs root value).
- Validate phrase-table inputs at load time.
When it happens
Trigger: Calling putChildTrie (directly or via put) with an empty key Iterable, so the loop never descends and parentTrie remains null.
Common situations: Inserting empty token lists into a token trie (e.g., empty phrases/rules read from a config); upstream code that filters out tokens but still attempts the insert.
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
- Value cannot be null
- Invalid nextBranchIndex=
- Invalid captureGroupId=
- Invalid minMatch=
- Unsupported subScoreType
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/a1b4c2b2ed187f8d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/matcher/TrieMap.java:78
TrieMap<K, V> curTrie = this;
Iterator<K> keyIter = key.iterator();
// go through each element
while (keyIter.hasNext()) {
K element = keyIter.next();
boolean isLast = !keyIter.hasNext();
if (curTrie.children == null) {
curTrie.children = new ConcurrentHashMap<>();//Generics.newConcurrentHashMap();
}
parentTrie = curTrie;
curTrie = curTrie.children.get(element);
if (isLast) {
parentTrie.children.put(element, child);
} else if(curTrie == null){
parentTrie.children.put(element, curTrie = new TrieMap<>());
}
}
if (parentTrie == null) {
throw new IllegalArgumentException("Cannot put a child trie with no keys");
}
return curTrie;
}
public Map<K, TrieMap<K, V>> getChildren() {
return children;
}
public V getValue() {
return value;
}
public boolean isLeaf() {
return value != null;
}
public String toFormattedString() {View on GitHub (pinned to 1b7edd19c4)