stanfordnlp/CoreNLP · error · java.lang.RuntimeException

More than one map in list while adding word () in phrase

Error message

More than one map in list while adding word () in phrase 

What it means

While descending a List trie node, addPhrase expects at most one nested Map (the continuation of the phrase prefix). Finding a second Map means the trie structure is invalid — two map children under the same list node — so it throws 'More than one map in list'.

Solutions

  1. Rebuild the phrase table from scratch using only public addPhrase calls
  2. Find and remove the offending direct writes to the internal tree
  3. Load all phrase sources through PhraseTable's own read/add methods so invariants hold

Example fix

// before
listNode.add(new HashMap<String,Object>()); // second map
// after
table.addPhrase(...); // let the library create the single nested map
Defensive patterns

Strategy: fallback

Validate before calling

// no pre-call check possible without touching internals; ensure all inserts go through addPhrase
if (usedDirectTreeInsertion) rebuildTable();

Type guard

static boolean listNodeOk(List<?> l) { long maps = l.stream().filter(o -> o instanceof Map).count(); return maps <= 1 && l.stream().allMatch(o -> o instanceof Phrase || o instanceof Map); }

Try / catch

try { table.addPhrase(wordList, text, tag, data); } catch (RuntimeException e) { if (e.getMessage().startsWith("More than one map in list")) { rebuildPhraseTableFromSource(); } else throw e; }

Prevention

When it happens

Trigger: Adding phrases such that a list node accumulates a second Map element, e.g. inconsistent node layouts produced by prior bad insertions or by code mutating the tree directly.

Common situations: Custom/bulk insertion code that bypasses PhraseTable invariants; mixing phrase tables loaded from different formats into one tree with hand-written merge logic.

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


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/58f4c6586ab6a5ea. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/PhraseTable.java:412

        tree = (Map<String, Object>) node;
      } else if (node instanceof List) {
        // Search through list for matches to word (at this point, the table is small, so no Map)
        List lookupList = (List) node;
        int nMaps = 0;
        for (Object obj:lookupList) {
          if (obj instanceof Phrase) {
            // check rest of the phrase matches
            Phrase oldphrase = (Phrase) obj;
            int matchedTokenEnd = checkWordListMatch(
              oldphrase, wordList, 0, wordList.size(), i, true);
            if (matchedTokenEnd >= 0) {
              oldPhraseNewFormAdded = oldphrase.addForm(phraseText);
              phraseAdded = true;
              break;
            }
          } else if (obj instanceof Map) {
            if (nMaps == 1) {
              throw new RuntimeException("More than one map in list while adding word "
                      + i + "(" + word + ") in phrase " + phraseText);
            }
            tree = (Map<String, Object>) obj;
            nMaps++;
          } else  {
            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());

View on GitHub (pinned to 1b7edd19c4)