{"record":{"id":"a5b9da3440870c8f","repo":"stanfordnlp/CoreNLP","slug":"failed-to-handle-s","errorCode":null,"errorMessage":"Failed to handle |${s}|","messagePattern":"Failed to handle \\|(.+?)\\|","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/util/XMLUtils.java","lineNumber":418,"sourceCode":"      b.append((char) c);\n      c = r.read();\n    }\n    return b.toString();\n  }\n\n  /**\n   * @return the new XMLTag object, or null if couldn't be created\n   */\n  public static XMLTag readAndParseTag(Reader r) throws IOException {\n    String s = readTag(r);\n    if (s == null) {\n      return null;\n    }\n    XMLTag ret = null;\n    try {\n      ret = new XMLTag(s);\n    } catch (Exception e) {\n      log.warn(\"Failed to handle |\" + s + \"|\");\n    }\n    return ret;\n  }\n\n  // Pattern is reentrant, going by the statement \"many matchers can share the same pattern\"\n  // on the Pattern javadoc.  Therefore, this should be safe as a static final variable.\n  private static final Pattern xmlEscapingPattern = Pattern.compile(\"&.+?;\");\n\n  public static String unescapeStringForXML(String s) {\n    StringBuilder result = new StringBuilder();\n    Matcher m = xmlEscapingPattern.matcher(s);\n    int end = 0;\n    while (m.find()) {\n      int start = m.start();\n      result.append(s, end, start);\n      end = m.end();\n      result.append(translate(s.substring(start, end)));\n    }","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/XMLUtils.java#L400-L436","documentation":"readAndParseTag constructs an XMLTag from the given string; any Exception thrown by the XMLTag constructor is caught and logged as 'Failed to handle |s|', and the method returns null. The |s| in the message is the offending input string. This means the argument was not a recognizable XML tag, and callers who do not null-check will hit a NullPointerException downstream.","triggerScenarios":"Calling XMLUtils.readAndParseTag(s) (also reached via XMLUtils.tag(...)) with a string that XMLTag cannot parse — missing angle brackets, malformed attributes, empty/null-like input, or text that is not a single tag.","commonSituations":"Splitting documents into tokens and feeding non-tag text fragments; hand-built tag strings with unescaped quotes or stray characters; off-by-one slicing that cuts off the closing '>' ; assuming the return is never null.","solutions":["Null-check the return value of readAndParseTag before use","Validate that the input starts with '<' and ends with '>' and contains a tag name before calling","Read the logged warning to see which string failed and correct its construction","Wrap the call in your own try/catch or Optional handling at the call site"],"exampleFix":"// before\nXMLTag t = XMLUtils.readAndParseTag(s);\nString name = t.name; // NPE when s is not a valid tag\n// after\nXMLTag t = XMLUtils.readAndParseTag(s);\nif (t == null) { throw new IllegalArgumentException(\"Not a valid XML tag: \" + s); }\nString name = t.name;","handlingStrategy":"type-guard","validationCode":"if (s == null || !(s.startsWith(\"<\") && s.endsWith(\">\") && s.length() > 2))\n  throw new IllegalArgumentException(\"Not an XML tag: \" + s);","typeGuard":"XMLTag t = XMLUtils.readAndParseTag(s);\nif (t == null) throw new IllegalArgumentException(\"readAndParseTag could not parse: \" + s);","tryCatchPattern":"XMLTag t = XMLUtils.readAndParseTag(s);\nif (t == null) {\n  throw new IllegalArgumentException(\"Invalid XML tag input: \" + s);\n}","preventionTips":["Always null-check the result — it returns null on any parse failure","Ensure sliced tag strings retain their delimiters","Check logs for 'Failed to handle |...|' to find malformed inputs","Validate tag syntax before calling"],"tags":["xml","null","parsing","java"],"backgroundTag":"xml-parse-error","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"}