{"record":{"id":"1cdc390fcfdb508d","repo":"stanfordnlp/CoreNLP","slug":"failed-to-find-end-for-tag","errorCode":null,"errorMessage":"Failed to find end for ${tag}","messagePattern":"Failed to find end for (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/ie/crf/NERGUI.java","lineNumber":587,"sourceCode":"      Pattern endPattern = Pattern.compile(\"</(\" + tagPattern + \")>\");\n\n      String finalText = taggedContents;\n\n      Matcher m = startPattern.matcher(finalText);\n      while (m.find()) {\n        String tag = m.group(1);\n        Color col = tagToColorMap.get(tag);\n        if (col != null) {\n          String color = colorToHTML(col);\n          String newTag = \"<span style=\\\"background-color: \" + color + \"; color: white\\\">\";\n          finalText = m.replaceFirst(newTag);\n          int start = m.start() + newTag.length();\n          Matcher m1 = endPattern.matcher(finalText);\n          if (m1.find(m.end())) {\n            String entity = finalText.substring(start, m1.start());\n            log.info(tag + \": \" + entity);\n          } else {\n            log.warn(\"Failed to find end for \" + tag);\n          }\n          finalText = m1.replaceFirst(\"</span>\");\n          m = startPattern.matcher(finalText);\n        }\n      }\n      // System.out.println(finalText);\n      editorPane.setText(finalText);\n      editorPane.revalidate();\n      editorPane.repaint();\n\n      // log.info(finalText);\n    }\n    saveTaggedAs.setEnabled(true);\n  }\n\n  private AttributeSet getAttributeSet(String tag) {\n    MutableAttributeSet attr = new SimpleAttributeSet();\n    Color color = tagToColorMap.get(tag);","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/NERGUI.java#L569-L605","documentation":"In NERGUI.extract, after a start tag (e.g. <ORGANIZATION>) is matched in the text, the code searches for the corresponding closing end pattern after the match. If no end marker is found, the entity cannot be delimited, so a warning is logged instead of extracting the entity.","triggerScenarios":"Running the NERGUI extract on text where a tag-opening pattern matches but the matching end pattern never occurs — i.e. a start tag for `tag` appears without its counterpart end tag.","commonSituations":"Hand-edited or truncated HTML fed to the GUI; custom tag formats whose end markers were stripped by sanitization; concatenating chunks so a start tag in one chunk has its end tag in another.","solutions":["Inspect the input text for unbalanced start tags and repair the malformed markup.","Ensure the endPattern for the tag matches your actual tag format (custom tag sets need matching end patterns).","Pre-validate input: count occurrences of each start/end tag and reject unbalanced input before calling extract."],"exampleFix":"// before\nString text = \"<ORGANIZATION> Stanford University\"; // no end tag\n// after\nString text = \"<ORGANIZATION> Stanford University </ORGANIZATION>\";","handlingStrategy":"validation","validationCode":"static boolean balanced(String text, String startTag, String endTag) {\n  return countOccurrences(text, startTag) == countOccurrences(text, endTag);\n}","typeGuard":null,"tryCatchPattern":"Matcher m1 = endPattern.matcher(finalText);\nif (!m1.find(m.end())) {\n  log.warn(\"Skipping entity with unbalanced tags for \" + tag);\n  continue; // don't call m1.replaceFirst on an unfound match\n}","preventionTips":["Validate HTML/tag balance before running extract.","Don't sanitize away closing tags in preprocessing.","Test with truncated input chunks."],"tags":["java","ner","gui","parsing"],"backgroundTag":"unexpected-response-shape","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"}