{"record":{"id":"7153677de807e04d","repo":"apache/maven","slug":"text-must-be-immediately-followed-by-end-element-a","errorCode":null,"errorMessage":"TEXT must be immediately followed by END_ELEMENT and not {}","messagePattern":"TEXT must be immediately followed by END_ELEMENT and not (.+?)","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader-stax.vm","lineNumber":701,"sourceCode":"            } else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {\n                String val = null;\n                if (strict) {\n                    throw new XMLStreamException(\"Entities are not supported in strict mode\", parser.getLocation(), null);\n                } else if (addDefaultEntities) {\n                    val = DefaultEntitiesHolder.DEFAULT_ENTITIES.get(parser.getLocalName());\n                }\n                if (val != null) {\n                    result.append(val);\n                } else {\n                    result.append(\"&\").append(parser.getLocalName()).append(\";\");\n                }\n            } else if (eventType != XMLStreamReader.COMMENT) {\n                break;\n            }\n            eventType = parser.next();\n        }\n        if (eventType != XMLStreamReader.END_ELEMENT) {\n            throw new XMLStreamException(\n                \"TEXT must be immediately followed by END_ELEMENT and not \" + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);\n        }\n        return result.toString();\n    }\n\n#if ( $locationTracking )\n    private XmlNode buildXmlNode(XMLStreamReader parser, InputSource inputSrc) throws XMLStreamException {\n        return XmlService.read(parser,\n                addLocationInformation\n                        ? p -> InputLocation.of(p.getLocation().getLineNumber(), p.getLocation().getColumnNumber(), inputSrc)\n                        : null);\n    }\n#else\n    private XmlNode buildXmlNode(XMLStreamReader parser) throws XMLStreamException {\n        return XmlService.read(parser);\n    }\n#end\n","sourceCodeStart":683,"sourceCodeEnd":719,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader-stax.vm#L683-L719","documentation":"nextText accumulates text events (CHARACTERS, CDATA, resolved entities; comments skipped) and requires the element to close immediately after the text. Any other event - practically a nested START_ELEMENT - is mixed content, which a flat string field cannot represent, so the reader throws with the offending event code appended.","triggerScenarios":"A text-only model field contains markup: <description>see <code>foo</code> here</description>, or any child element plus text inside a field the model defines as a simple string.","commonSituations":"HTML snippets pasted into description/name fields; templating systems injecting tags into element bodies.","solutions":["Remove the nested markup, or put the entire rich-text run into a CDATA section so it stays one text node.","If structured children are required there, the model must define them - a model change, not a caller-side fix.","Reject such documents at intake with a targeted message."],"exampleFix":"<!-- before -->\n<description>see <code>foo</code> here</description>\n\n<!-- after -->\n<description><![CDATA[see <code>foo</code> here]]></description>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Model model = reader.read(in, true);\n} catch (XMLStreamException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"TEXT must be immediately followed\")) {\n        // mixed content in a text field: report location, ask producer to escape/CDATA the text\n    }\n    throw e;\n}","preventionTips":["Keep markup out of text fields; wrap rich text in CDATA.","Escape tag-like content when generating XML.","Validate with XSD - most schemas reject mixed content in these fields."],"tags":["xml","stax","mixed-content","parsing"],"backgroundTag":"xml-mixed-content","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}