{"record":{"id":"ce11d79eec36bda4","repo":"stanfordnlp/CoreNLP","slug":"comparing-a-mention-with-itself-for-representative","errorCode":null,"errorMessage":"Comparing a mention with itself for representativeness","messagePattern":"Comparing a mention with itself for representativeness","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/coref/data/Mention.java","lineNumber":1144,"sourceCode":"      // Ensure that both NER tags are neither MISC nor O, or are both not existent\n      assert nerString == null || nerString.equals(m.nerString) || (!nerString.equals(\"O\") && !nerString.equals(\"MISC\") && !m.nerString.equals(\"O\") && !m.nerString.equals(\"MISC\"));\n      // Return larger headIndex - startIndex\n      if (headIndex - startIndex > m.headIndex - m.startIndex) { return true; }\n      else if (headIndex - startIndex < m.headIndex - m.startIndex) { return false; }\n      // Return earlier sentence number\n      else if (sentNum < m.sentNum) { return true; }\n      else if (sentNum > m.sentNum) { return false; }\n      // Return earlier head index\n      else if (headIndex < m.headIndex) { return true; }\n      else if (headIndex > m.headIndex) { return false; }\n      // If the mentions are short, take the longer one\n      else if (originalSpan.size() <= 5 && originalSpan.size() > m.originalSpan.size()) { return true; }\n      else if (originalSpan.size() <= 5 && originalSpan.size() < m.originalSpan.size()) { return false; }\n      // If the mentions are long, take the shorter one (we're getting into the realm of nonsense by here)\n      else if (originalSpan.size() < m.originalSpan.size()) { return true; }\n      else if (originalSpan.size() > m.originalSpan.size()) { return false; }\n      else {\n        throw new IllegalStateException(\"Comparing a mention with itself for representativeness\");\n      }\n    }\n  }\n\n  // Returns filtered premodifiers (no determiners or numerals)\n  public ArrayList<ArrayList<IndexedWord>> getPremodifiers(){\n\n    ArrayList<ArrayList<IndexedWord>> premod = new ArrayList<>();\n\n    if(headIndexedWord == null) return premod;\n    for(Pair<GrammaticalRelation,IndexedWord> child : enhancedDependency.childPairs(headIndexedWord)){\n      String function = child.first().getShortName();\n      if(child.second().index() < headWord.index()\n          && !child.second.tag().equals(\"DT\") && !child.second.tag().equals(\"WRB\")\n          && !function.endsWith(\"det\") && !function.equals(\"nummod\")\n          && !function.startsWith(\"acl\") && !function.startsWith(\"advcl\")\n          && !function.equals(\"punct\")){\n        ArrayList<IndexedWord> phrase = new ArrayList<>(enhancedDependency.descendants(child.second()));","sourceCodeStart":1126,"sourceCodeEnd":1162,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/data/Mention.java#L1126-L1162","documentation":"Mention.moreRepresentativeThan (representativeness comparison) throws IllegalStateException when two mentions have identical originalSpan sizes but neither comparison branch returned — i.e., the method was effectively called comparing a mention with itself (or a mention with equal-size spans through a path assumed impossible). The class treats this as an unreachable internal state.","triggerScenarios":"Calling moreRepresentativeThan on two Mention objects with the same originalSpan size in a code path where all earlier tie-breakers (sentence position, head, NE, etc.) also tie — typically m.moreRepresentativeThan(m) or duplicate mentions.","commonSituations":"Duplicate mentions generated by custom extraction producing the same mention twice in a cluster; patched coref algorithm code that compares a mention against itself when picking cluster representatives; modified tie-breaker conditions removing the original distinctness guarantees.","solutions":["Ensure cluster representative selection never compares a mention with itself (skip identity references / use i < j ordering)","Check for and deduplicate identical Mentions added to the same CorefCluster","If you patched the comparison logic, restore tie-breaker branches so equal-size mentions resolve before the final else","Upgrade to an unmodified CoreNLP version to rule out fork-introduced regressions"],"exampleFix":"// before\nif (m1.moreRepresentativeThan(m2)) rep = m1; // can hit m1 == m2\n// after\nif (m1 != m2 && m1.moreRepresentativeThan(m2)) rep = m1;","handlingStrategy":"try-catch","validationCode":"if (m1 == m2) throw new IllegalArgumentException(\"Cannot compare a mention with itself\");\nif (m1.originalSpan.size() == m2.originalSpan.size())\n  throw new IllegalArgumentException(\"Ambiguous representative: equal-size spans\");","typeGuard":null,"tryCatchPattern":"try {\n  if (m1.moreRepresentativeThan(m2)) rep = m1; else rep = m2;\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Comparing a mention with itself\")) {\n    rep = m1; // already the representative; keep as-is\n  } else throw e;\n}","preventionTips":["Skip identity comparisons (m1 != m2) when choosing cluster representatives","Deduplicate Mentions before building CorefClusters","Do not modify tie-breaker branches in moreRepresentativeThan when forking","Use i < j index ordering when scanning pairs in a cluster"],"tags":["coref","mention","illegal-state","internal-invariant"],"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"}