{"record":{"id":"58bf648d939b33fa","repo":"apache/hadoop","slug":"unterminated-code-point-escape-string-broke-off-i","errorCode":null,"errorMessage":"unterminated code point escape: string broke off in the middle","messagePattern":"unterminated code point escape: string broke off in the middle","errorType":"exception","errorClass":"UnmanglingError","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/XMLUtils.java","lineNumber":234,"sourceCode":"        slashPosition = 0;\n      } else {\n        boolean startingEntityRef = false;\n        if (decodeEntityRefs) {\n          startingEntityRef = (ch == '&');\n        }\n        if (startingEntityRef) {\n          entityRef = new StringBuilder();\n          entityRef.append(\"&\");\n        } else {\n          bld.append(ch);\n        }\n      }\n    }\n    if (entityRef != null) {\n      throw new UnmanglingError(\"unterminated entity ref starting with \" +\n          entityRef.toString());\n    } else if (slashPosition != -1) {\n      throw new UnmanglingError(\"unterminated code point escape: string \" +\n          \"broke off in the middle\");\n    }\n    return bld.toString();\n  }\n  \n  /**\n   * Add a SAX tag with a string inside.\n   *\n   * @param contentHandler     the SAX content handler\n   * @param tag                the element tag to use  \n   * @param val                the string to put inside the tag\n   */\n  public static void addSaxString(ContentHandler contentHandler,\n      String tag, String val) throws SAXException {\n    contentHandler.startElement(\"\", \"\", tag, new AttributesImpl());\n    char c[] = mangleXmlString(val, false).toCharArray();\n    contentHandler.characters(c, 0, c.length);\n    contentHandler.endElement(\"\", \"\", tag);","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/XMLUtils.java#L216-L252","documentation":"If the string ends while a backslash escape is still in progress (slashPosition != -1 — fewer than 4 hex digits were consumed after the '\\', or the 4 digits were consumed but end-of-string arrived before the ';'), unmangleXmlString throws UnmanglingError(\"unterminated code point escape: string broke off in the middle\"). This is the truncation twin of the 'expected semicolon' error, detected after the loop.","triggerScenarios":"Input ending in an incomplete escape: \"abc\\\\00\" or \"abc\\\\0041\" with no trailing semicolon — the character cut lands anywhere between the backslash and the required ';'.","commonSituations":"Value truncated mid-escape by a fixed-width cut or partial stream read; manual deletion of characters in fsimage XML; splitting a mangled string on a boundary that lands inside an escape.","solutions":["Restore the full \\\\hhhh; sequence including the semicolon","Re-copy the original mangled value from its source instead of repairing by hand","Guard with a completeness check before unmangling: every '\\' must be followed by 4 hex digits and a ';'"],"exampleFix":"// before\nXMLUtils.unmangleXmlString(\"tab\\\\000\", false); // escape cut off -> throws\n\n// after\nXMLUtils.unmangleXmlString(\"tab\\\\0009;\", false); // ok","handlingStrategy":"validation","validationCode":"static boolean escapesWellFormed(String s) {\n  for (int i = 0; i < s.length(); i++) {\n    if (s.charAt(i) == '\\\\') {\n      if (i + 5 >= s.length() || s.charAt(i + 5) != ';') return false;\n      i += 5;\n    }\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  XMLUtils.unmangleXmlString(s, false);\n} catch (XMLUtils.UnmanglingError e) {\n  // escape cut off mid-sequence; re-read the full source value\n}","preventionTips":["Split mangled strings only on boundaries outside \\\\hhhh; sequences","Detect partial reads (unexpected length / no closing tag) before unmangling","Re-copy mangled values from source rather than repairing by hand"],"tags":["xml","parsing","escape-sequences","hdfs","fsimage"],"backgroundTag":"escape-sequence-parse-error","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}