{"record":{"id":"0319f779fd2876c9","repo":"stanfordnlp/CoreNLP","slug":"unexpected-class-in-list-while-looking-up","errorCode":null,"errorMessage":"Unexpected class in list  while looking up ","messagePattern":"Unexpected class in list  while looking up ","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/PhraseTable.java","lineNumber":826,"sourceCode":"          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          for (Object obj:lookupList) {\n            if (obj instanceof Phrase) {\n              // check rest of the phrase matches\n              Phrase phrase = (Phrase) obj;\n              if (acceptablePhrases == null || acceptablePhrases.contains(phrase)) {\n                int matchedTokenEnd = checkWordListMatch(\n                  phrase, tokens, cur.tokenStart, cur.tokenEnd, i+1, matchEnd);\n                if (matchedTokenEnd >= 0) {\n                  matched.add(new PhraseMatch(phrase, cur.tokenStart, matchedTokenEnd));\n                }\n              }\n            } else if (obj instanceof Map) {\n              todoStack.push(new StackEntry((Map<String,Object>) obj, cur.tokenStart, i+1, cur.tokenEnd, -1));\n            } else  {\n              throw new RuntimeException(\"Unexpected class in list \" + obj.getClass() + \" while looking up \" + word);\n            }\n          }\n          break;\n        } else {\n          throw new RuntimeException(\"Unexpected class \" + node.getClass() + \" while looking up \" + word);\n        }\n      }\n      if (cur.continueAt >= 0) {\n        int newStart = (cur.continueAt > cur.tokenStart)? cur.continueAt: cur.tokenStart+1;\n        if (newStart < cur.tokenEnd) {\n          todoStack.push(new StackEntry(cur.tree, newStart, newStart, cur.tokenEnd, newStart+1));\n        }\n      }\n    }\n    return matched;\n  }\n\n  public Iterator<Phrase> iterator() {","sourceCodeStart":808,"sourceCodeEnd":844,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/PhraseTable.java#L808-L844","documentation":"In the exhaustive multi-match lookup routine, each element popped from a List node must be a Phrase or a Map to push on the search stack. Any other class triggers this RuntimeException, signaling the trie's internal structure is not what the search expects.","triggerScenarios":"Calling the public lookup variants that enumerate all matches on a table whose lists contain foreign objects - after concurrent writes or external corruption.","commonSituations":"Unsynchronized population followed by multi-match lookups; direct manipulation of internal maps; version-mismatched deserialization.","solutions":["Populate the table under a single lock, then use it read-only from multiple threads.","Rebuild from the phrase list rather than repairing the corrupted instance.","Avoid keeping references to internal Map/List nodes returned by reflection.","Upgrade/report to Stanford NLP if single-threaded usage still throws."],"exampleFix":"// before\nthread1: table.addPhrase(p1); thread2: table.lookupByRegex(...);\n// after\nbuildTable(); // complete all addPhrase calls first\nmatches = table.lookupByRegex(...); // now read-only","handlingStrategy":"try-catch","validationCode":"// finish all addPhrase calls before multi-match lookups\nif (building) throw new IllegalStateException(\"table still being populated\");","typeGuard":null,"tryCatchPattern":"try { matches = table.lookupByRegex(...); } catch (RuntimeException e) { if (e.getMessage().contains(\"while looking up\")) { table = rebuildTable(phrases); } else { throw e; } }","preventionTips":["Complete population before enumerating matches.","Do not share partially built tables.","Avoid reflective access to rootTree."],"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-16T04:17:20.429Z"}