{"record":{"id":"a1b4c2b2ed187f8d","repo":"stanfordnlp/CoreNLP","slug":"cannot-put-a-child-trie-with-no-keys","errorCode":null,"errorMessage":"Cannot put a child trie with no keys","messagePattern":"Cannot put a child trie with no keys","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/matcher/TrieMap.java","lineNumber":78,"sourceCode":"    TrieMap<K, V> curTrie = this;\n    Iterator<K> keyIter = key.iterator();\n    // go through each element\n    while (keyIter.hasNext()) {\n      K element = keyIter.next();\n      boolean isLast = !keyIter.hasNext();\n      if (curTrie.children == null) {\n        curTrie.children = new ConcurrentHashMap<>();//Generics.newConcurrentHashMap();\n      }\n      parentTrie = curTrie;\n      curTrie = curTrie.children.get(element);\n      if (isLast) {\n        parentTrie.children.put(element, child);\n      } else if(curTrie == null){\n        parentTrie.children.put(element, curTrie = new TrieMap<>());\n      }\n    }\n    if (parentTrie == null) {\n      throw new IllegalArgumentException(\"Cannot put a child trie with no keys\");\n    }\n    return curTrie;\n  }\n\n  public Map<K, TrieMap<K, V>> getChildren() {\n    return children;\n  }\n\n  public V getValue() {\n    return value;\n  }\n\n  public boolean isLeaf() {\n    return value != null;\n  }\n\n\n  public String toFormattedString() {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/matcher/TrieMap.java#L60-L96","documentation":"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.","triggerScenarios":"Calling putChildTrie (directly or via put) with an empty key Iterable, so the loop never descends and parentTrie remains null.","commonSituations":"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.","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."],"exampleFix":"// before\ntrie.put(tokens, value); // tokens may be empty\n// after\nif (tokens == null || tokens.isEmpty()) {\n    return; // or handle root-level value\n}\ntrie.put(tokens, value);","handlingStrategy":"validation","validationCode":"if (key == null || key.isEmpty()) {\n    throw new IllegalArgumentException(\"cannot insert empty key into TrieMap\");\n}","typeGuard":"static <K> boolean hasKey(Iterable<K> key) {\n    return key != null && key.iterator().hasNext();\n}","tryCatchPattern":"try {\n    trie.put(key, value);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"no keys\")) {\n        log.warn(\"skipped empty-key insert\");\n    } else throw e;\n}","preventionTips":["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."],"tags":["java","tokensregex","trie","empty-key","illegal-argument"],"backgroundTag":"empty-required-field","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}