{"record":{"id":"91469d49c46a666e","repo":"apache/hadoop","slug":"unterminated-code-point-escape-expected-semicolon","errorCode":null,"errorMessage":"unterminated code point escape: expected semicolon at end.","messagePattern":"unterminated code point escape: expected semicolon at end\\.","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":205,"sourceCode":"          } else if (e.equals(\"&apos;\")) {\n            bld.append(\"\\'\");\n          } else if (e.equals(\"&amp;\")) {\n            bld.append(\"&\");\n          } else if (e.equals(\"&lt;\")) {\n            bld.append(\"<\");\n          } else if (e.equals(\"&gt;\")) {\n            bld.append(\">\");\n          } else {\n            throw new UnmanglingError(\"Unknown entity ref \" + e);\n          }\n          entityRef = null;\n        }\n      } else  if ((slashPosition >= 0) && (slashPosition < NUM_SLASH_POSITIONS)) {\n        escapedCp += ch;\n        ++slashPosition;\n      } else if (slashPosition == NUM_SLASH_POSITIONS) {\n        if (ch != ';') {\n          throw new UnmanglingError(\"unterminated code point escape: \" +\n              \"expected semicolon at end.\");\n        }\n        try {\n          bld.appendCodePoint(Integer.parseInt(escapedCp, 16));\n        } catch (NumberFormatException e) {\n          throw new UnmanglingError(\"error parsing unmangling escape code\", e);\n        }\n        escapedCp = \"\";\n        slashPosition = -1;\n      } else if (ch == '\\\\') {\n        slashPosition = 0;\n      } else {\n        boolean startingEntityRef = false;\n        if (decodeEntityRefs) {\n          startingEntityRef = (ch == '&');\n        }\n        if (startingEntityRef) {\n          entityRef = new StringBuilder();","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/XMLUtils.java#L187-L223","documentation":"In the mangled format an escaped code point is a backslash followed by exactly NUM_SLASH_POSITIONS (4) characters and a terminating semicolon (\\hhhh;). While scanning, unmangleXmlString counts positions after the backslash; once 4 characters are consumed it demands that the next character be ';'. Anything else throws UnmanglingError(\"unterminated code point escape: expected semicolon at end.\").","triggerScenarios":"unmangleXmlString encounters a backslash + 4 characters followed by a non-semicolon, e.g. \"a\\0009 b\" instead of \"a\\0009; b\". Because mangleXmlString always escapes a literal backslash as \\005c;, well-formed mangled strings never hit this — the input was hand-edited, truncated, or never produced by mangleXmlString.","commonSituations":"Manually repairing fsimage XML values; string truncation at a fixed buffer or column boundary; concatenating mangled fragments incorrectly; retyping escape sequences with typos.","solutions":["Restore the semicolon: every backslash escape must be exactly backslash + 4 hex digits + ';'","Re-mangle the original string with XMLUtils.mangleXmlString instead of hand-crafting escapes","Regenerate the fsimage XML with `hdfs oiv` rather than editing tool output by hand"],"exampleFix":"// before\nString bad = \"a\\\\0009 b\"; // 4 hex digits then space\nXMLUtils.unmangleXmlString(bad, false); // throws\n\n// after\nString good = \"a\\\\0009; b\";\nXMLUtils.unmangleXmlString(good, 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()) return false;              // truncated\n      for (int j = 1; j <= 4; j++) {\n        if (Character.digit(s.charAt(i + j), 16) < 0) return false;\n      }\n      if (s.charAt(i + 5) != ';') return false;            // missing semicolon\n      i += 5;\n    }\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  XMLUtils.unmangleXmlString(s, false);\n} catch (XMLUtils.UnmanglingError e) {\n  // malformed escape; quarantine the record and keep processing\n}","preventionTips":["Never hand-edit escape sequences; re-mangle from the original string","Validate \\\\hhhh; structure before unmangling","Transport mangled strings whole — avoid truncation or column wrapping"],"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-22T20:17:22.307Z"}