{"record":{"id":"ad2e33fbb088c682","repo":"hibernate/hibernate-orm","slug":"xml-not-properly-formed","errorCode":null,"errorMessage":"XML not properly formed: ","messagePattern":"XML not properly formed: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/XmlHelper.java","lineNumber":425,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase '/':\n\t\t\t\t\tif ( tagName == null ) {\n\t\t\t\t\t\t// A shorthand tag encodes null\n\t\t\t\t\t\tvalues.add( null );\n\t\t\t\t\t\t// skip the closing angle bracket\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\ttagNameStart = -1;\n\t\t\t\t\t\tassert string.charAt( i ) == '>';\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// This must be a char in the content\n\t\t\t\t\t\tassert contentStart != -1;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalArgumentException( \"XML not properly formed: \" + string.substring( start ) );\n\t}\n\n\tprivate static int fromString(\n\t\t\tEmbeddableMappingType embeddableMappingType,\n\t\t\tString string,\n\t\t\tboolean returnEmbeddable,\n\t\t\tWrapperOptions options,\n\t\t\tObject[] values,\n\t\t\tint start) throws SQLException {\n\t\tint tagNameStart = -1;\n\t\tint contentStart = -1;\n\t\tString tagName = null;\n\t\tfor ( int i = start; i < string.length(); i++ ) {\n\t\t\tfinal char c = string.charAt( i );\n\t\t\tswitch ( c ) {\n\t\t\t\tcase '<':\n\t\t\t\t\tif ( tagNameStart == -1 ) {\n\t\t\t\t\t\tif ( string.charAt( i + 1 ) == '/' ) {","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/XmlHelper.java#L407-L443","documentation":"Tail of XmlHelper's generic fromString parser: the scan loop reached the end of the string while still inside an element, meaning the closing tag was never found. The stored XML aggregate content is truncated or unterminated.","triggerScenarios":"Reading an XML aggregate whose content ends before the closing tag: column truncation (VARCHAR too short), partial writes after a crash, or manual edits that removed tags.","commonSituations":"Column length changed or too small for large aggregates; non-atomic updates by scripts; data truncation during ETL between databases.","solutions":["Identify affected rows with a SQL audit (content not ending in the expected closing tag).","Repair or null the truncated rows, then re-write them through Hibernate.","Enlarge the column type (e.g. CLOB/XML type) so writes never truncate again."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return session.find(Person.class, id);\n} catch (IllegalArgumentException ex) {\n    if (ex.getMessage() != null && ex.getMessage().startsWith(\"XML not properly formed\")) {\n        // truncated row: log PK and raw column value for repair\n        logTruncated(id, ex.getMessage());\n        return null;\n    }\n    throw ex;\n}","preventionTips":["Use unbounded column types (CLOB / native XML) for aggregate columns.","Audit for rows not ending in the expected closing tag after bulk loads.","Write aggregates atomically through Hibernate transactions, not scripts."],"tags":["hibernate","xml","xml-aggregate","truncated-data"],"backgroundTag":"malformed-xml-data","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}