{"record":{"id":"862ae6c724d1df76","repo":"stanfordnlp/CoreNLP","slug":"value-cannot-be-null","errorCode":null,"errorMessage":"Value cannot be null","messagePattern":"Value cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/matcher/TrieMap.java","lineNumber":163,"sourceCode":"      return get( (Iterable<K>) key);\n    } else if (key instanceof Object[]) {\n      return get( Arrays.asList( (Object[]) key) );\n    }\n    return null;\n  }\n\n  public V get(Iterable<K> key) {\n    TrieMap<K, V> curTrie = getChildTrie(key);\n    return (curTrie != null) ? curTrie.value: null;\n  }\n\n  public V get(K[] key) {\n    return get(Arrays.asList(key));\n  }\n\n  @Override\n  public V put(Iterable<K> key, V value) {\n    if (value == null) throw new IllegalArgumentException(\"Value cannot be null\");\n    TrieMap<K, V> curTrie = this;\n    // go through each element\n    for(K element:key){\n      if (curTrie.children == null) {\n        curTrie.children = new ConcurrentHashMap<>();//Generics.newConcurrentHashMap();\n      }\n      TrieMap<K, V> parent = curTrie;\n      curTrie = curTrie.children.get(element);\n      if(curTrie == null){\n        parent.children.put(element, curTrie = new TrieMap<>());\n      }\n    }\n    V oldValue = curTrie.value;\n    curTrie.value = value;\n    return oldValue;\n  }\n\n  public V put(K[] key, V value) {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/matcher/TrieMap.java#L145-L181","documentation":"TrieMap.put rejects null values with IllegalArgumentException('Value cannot be null'). TrieMap uses a null value internally to mark non-terminal nodes, so storing an actual null entry is ambiguous and unsupported.","triggerScenarios":"trie.put(key, null) directly, or via putAll with a map containing null values; called from readEntries and the TrieMap tests.","commonSituations":"Bulk-loading phrase tables or maps from deserialized data that contains nulls; assembling rule maps programmatically where an absent mapping was represented as null instead of being filtered out.","solutions":["Filter out entries with null values before put/putAll.","Replace null values with a sentinel object (e.g., Optional.empty() wrapper or a NULL_VALUE constant).","If the key should simply be registered without a value, drop the put call entirely — trie nodes are created by the key walk itself."],"exampleFix":"// before\nfor (Map.Entry<List<K>, V> e : entries.entrySet()) {\n    trie.put(e.getKey(), e.getValue()); // NPE-prone null values\n}\n// after\nfor (Map.Entry<List<K>, V> e : entries.entrySet()) {\n    if (e.getValue() != null) {\n        trie.put(e.getKey(), e.getValue());\n    }\n}","handlingStrategy":"validation","validationCode":"if (value == null) {\n    throw new IllegalArgumentException(\"TrieMap does not accept null values\");\n}","typeGuard":"static <K,V> boolean isInsertable(Map.Entry<List<K>, V> e) {\n    return e != null && e.getKey() != null && !e.getKey().isEmpty() && e.getValue() != null;\n}","tryCatchPattern":"try {\n    trie.put(key, value);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Value cannot be null\")) {\n        log.warn(\"dropped null-valued entry for key \" + key);\n    } else throw e;\n}","preventionTips":["Sanitize source maps with Objects::nonNull filters before putAll.","Use an explicit sentinel object instead of null to represent 'present but empty'.","Remember TrieMap reserves null internally for non-terminal nodes — never store null."],"tags":["java","tokensregex","trie","null-value","illegal-argument"],"backgroundTag":"null-argument","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"}