{"record":{"id":"e22a160fb175f5d9","repo":"stanfordnlp/CoreNLP","slug":"more-than-one-map-in-list-while-looking-up-word","errorCode":null,"errorMessage":"More than one map in list while looking up word () in phrase ","messagePattern":"More than one map in list while looking up word \\(\\) in phrase ","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/PhraseTable.java","lineNumber":565,"sourceCode":"      } else if (node instanceof Map) {\n        tree = (Map<String, Object>) node;\n      } else if (node instanceof List) {\n        // Search through list for matches to word (at this point, the table is small, so no Map)\n        List lookupList = (List) node;\n        int nMaps = 0;\n        for (Object obj:lookupList) {\n          if (obj instanceof Phrase) {\n            // check rest of the phrase matches\n            Phrase phrase = (Phrase) obj;\n            int matchedTokenEnd = checkWordListMatch(\n              phrase, wordList, 0, wordList.size(), i, true);\n\n            if (matchedTokenEnd >= 0) {\n              return phrase;\n            }\n          } else if (obj instanceof Map) {\n            if (nMaps == 1) {\n              throw new RuntimeException(\"More than one map in list while looking up word \"\n                      + i + \"(\" + word + \") in phrase \" + wordList.toString());\n            }\n            tree = (Map<String, Object>) obj;\n            nMaps++;\n          } else  {\n            throw new RuntimeException(\"Unexpected class in list \" + obj.getClass() + \" while looking up word \"\n                    + i + \"(\" + word + \") in phrase \" + wordList.toString());\n          }\n        }\n        if (nMaps == 0) {\n          return null;\n        }\n      } else {\n        throw new RuntimeException(\"Unexpected class in list \" + node.getClass() + \" while looking up word \"\n                + i + \"(\" + word + \") in phrase \" + wordList.toString());\n      }\n    }\n    Phrase phrase = (Phrase) tree.get(PHRASE_END);","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/PhraseTable.java#L547-L583","documentation":"During lookup, when a trie node is a List, PhraseTable scans it expecting at most one sub-Map (the collapsed table for that prefix). Finding two Maps means the list was never converted to a map at MAX_LIST_SIZE as the invariant requires, so the structure is inconsistent. This is an internal-corruption error, not a user-input error.","triggerScenarios":"lookupIgnoringCase/lookup on a PhraseTable whose internal lookupList contains two Map entries - typically after concurrent addPhrase calls racing past the MAX_LIST_SIZE conversion step.","commonSituations":"Unsynchronized concurrent phrase insertion; custom code or reflection modifying the table's lists; running a table built by a different (buggy) version.","solutions":["Guard all writes with synchronization and rebuild the table from the original phrase list.","Ensure phrases are added only via addPhrase/addPhrases, never by mutating internal structures.","Update to a current CoreNLP version where list-to-map conversion bugs are fixed.","Report to Stanford NLP with the word list if built single-threaded - it signals an internal bug."],"exampleFix":"// before\nsynchronized(table) { table.addPhrase(a); }\n// elsewhere, unsynchronized: table.addPhrase(b); // race corrupts list\n// after\nsynchronized(table) { table.addPhrase(a); table.addPhrase(b); }","handlingStrategy":"validation","validationCode":"// build fully under one lock before any lookup\nsynchronized (table) { for (String p : phrases) table.addPhrase(p); }","typeGuard":null,"tryCatchPattern":"try { return table.lookup(wordList); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"More than one map\")) { return null; } throw e; }","preventionTips":["Serialize all writes to the table with a lock.","Never add phrases concurrently with lookups.","Rebuild the table rather than reusing suspect instances.","Keep CoreNLP up to date."],"tags":["tokensregex","internal-state","concurrency"],"backgroundTag":"internal-invariant-violation","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"}