{"record":{"id":"edf4a9798d78325c","repo":"stanfordnlp/CoreNLP","slug":"cannot-find-matching-labelled-span-for-s","errorCode":null,"errorMessage":"Cannot find matching labelled span for {s}","messagePattern":"Cannot find matching labelled span for (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/dcoref/CoNLL2011DocumentReader.java","lineNumber":381,"sourceCode":"                openParenIndex = -1;\n              }\n              isDelimiter = true;\n            }\n            if (c == '(') {\n              openParenIndex = j;\n            } else if (c == ')') {\n              Triple<Integer, Integer, String> t = openSpans.pop();\n              if (checkEndLabel) {\n                // NOTE: end parens may cross (usually because mention either start or end on the same token\n                // and it is just an artifact of the ordering\n                String s = val.substring(lastDelimiterIndex+1, j);\n                if (!s.equals(t.third())) {\n                  Stack<Triple<Integer,Integer, String>> saved = new Stack<>();\n                  while (!s.equals(t.third())) {\n                    // find correct match\n                    saved.push(t);\n                    if (openSpans.isEmpty()) {\n                      throw new RuntimeException(\"Cannot find matching labelled span for \" + s);\n                    }\n                    t = openSpans.pop();\n                  }\n                  while (!saved.isEmpty()) {\n                    openSpans.push(saved.pop());\n                  }\n                  assert(s.equals(t.third()));\n                }\n              }\n              t.setSecond(wordPos);\n              spans.add(t);\n            }\n            if (isDelimiter) {\n              lastDelimiterIndex = j;\n            }\n          }\n          if (openParenIndex >= 0) {\n            String s = val.substring(openParenIndex+1, val.length());","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/dcoref/CoNLL2011DocumentReader.java#L363-L399","documentation":"While parsing CoNLL coreference chains, getLabelledSpans matches open span labels to the expected label; if the stack of open spans is exhausted without finding a matching label, it throws RuntimeException indicating the corpus annotations are malformed (unbalanced or mislabeled coref spans).","triggerScenarios":"A CoNLL document contains coref bracket annotations whose labels don't line up — e.g. a closing bracket expecting label s but openSpans contains no span with that label, indicating nested/mismatched coref chains in the source file.","commonSituations":"Corrupt or hand-edited gold_conll files, files mixing CoNLL-2011 and 2012 annotation formats, custom-preprocessed corpus with broken coref brackets.","solutions":["Locate the offending document (the last 'Reading document' log line) and inspect its coref columns","Fix or remove the malformed document from the corpus file list","Regenerate the corpus files from official CoNLL distributions instead of hand edits","Check that you are not mixing CoNLL-2011 and CoNLL-2012 formatted files in one run"],"exampleFix":"// before\ncorpus.list contains: hand-edited_doc.v4_gold_conll  (mismatched coref brackets)\n// after\ncorpus.list contains: official_conll2011_doc.v4_gold_conll  (regenerated, validated brackets)","handlingStrategy":"validation","validationCode":"// pre-validate gold_conll coref columns are balanced\nlong opens = lines.stream().filter(l -> l.contains(\"(\") && !l.contains(\")\")).count();\nlong closes = lines.stream().filter(l -> l.contains(\")\") && !l.contains(\"(\")).count();\nif (opens != closes) throw new IllegalStateException(\"unbalanced coref spans\");","typeGuard":null,"tryCatchPattern":"try {\n  Document d = reader.getNextDocument();\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Cannot find matching labelled span\")) {\n    logger.severe(\"malformed coref annotations; skip this document\");\n    return null;\n  }\n  throw e;\n}","preventionTips":["Use official CoNLL-2011/2012 distributions without hand edits","Do not mix 2011 and 2012 file formats in one corpus","Log 'Reading document' output to locate the offending file quickly"],"tags":["corpus","parsing","conll","annotation"],"backgroundTag":"invalid-argument-format","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"}