{"record":{"id":"ff53190a827eeb73","repo":"apache/maven","slug":"parser-must-be-on-start-element-to-read-next-text-ff5319","errorCode":null,"errorMessage":"parser must be on START_ELEMENT to read next text","messagePattern":"parser must be on START_ELEMENT to read next text","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader.vm","lineNumber":1082,"sourceCode":"            int next = parser.next();\n            switch (next) {\n                case XMLStreamReader.SPACE:\n                case XMLStreamReader.COMMENT:\n                case XMLStreamReader.PROCESSING_INSTRUCTION:\n                case XMLStreamReader.CDATA:\n                case XMLStreamReader.CHARACTERS:\n                    continue;\n                case XMLStreamReader.START_ELEMENT:\n                case XMLStreamReader.END_ELEMENT:\n                    return next;\n            }\n        }\n    } //-- int nextTag(XMLStreamReader)\n\n    private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {\n        int eventType = parser.getEventType();\n        if (eventType != XMLStreamReader.START_ELEMENT) {\n            throw new XMLStreamException(\"parser must be on START_ELEMENT to read next text\", parser.getLocation(), null);\n        }\n        eventType = parser.next();\n        StringBuilder result = new StringBuilder();\n        while (true) {\n            if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {\n                result.append(parser.getText());\n            } 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 = DEFAULT_ENTITIES.get(parser.getLocalName());\n                }\n                if (val != null) {\n                    result.append(val);\n                } else {\n                    result.append(\"&\").append(parser.getLocalName()).append(\";\");\n                }","sourceCodeStart":1064,"sourceCodeEnd":1100,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader.vm#L1064-L1100","documentation":"Internal guard in the Modello-generated reader's nextText helper (template src/mdo/reader.vm): reading an element's text body requires the StAX cursor to be positioned on START_ELEMENT. If the caller (or a previous parse step) advanced the cursor past the start tag, the reader throws javax.xml.stream.XMLStreamException immediately. End-user visible occurrences almost always mean malformed XML structure such as nested or mixed content where text was not expected.","triggerScenarios":"A model XML document contains nested elements or stray text where the model expects a simple text node, desynchronizing the reader's cursor state; or client code drives the generated reader after manually advancing the same XMLStreamReader instance.","commonSituations":"POM/metadata documents with injected child elements into fields that are scalar in the model version being used; files transformed by naive string/XML tooling that moved tags around; version mismatch where a newer format nests elements the older reader treats as text.","solutions":["Validate the document against the model's XML schema to find misplaced or nested elements at the reported location.","Fix or remove the misplaced child/text content so the element is a simple text node.","Regenerate the file with tooling matching the model version.","Ensure custom code is not sharing/reusing the XMLStreamReader instance across the generated reader and manual next() calls."],"exampleFix":"<!-- before: nested element where model expects text -->\n<name>commons-<vendor>apache</vendor>-lang</name>\n<!-- after -->\n<name>commons-apache-lang</name>","handlingStrategy":"validation","validationCode":"// schema- or structure-validate: scalar elements must have text-only content\nif (elem.getChildren().size() > 0 && modelFieldIsScalar(elem.getName())) throw new IllegalArgumentException(\"nested content in scalar field: \" + elem.getName());","typeGuard":null,"tryCatchPattern":"try {\n    reader.read(in, true);\n} catch (XMLStreamException e) {\n    if (e.getMessage().contains(\"START_ELEMENT to read next text\")) { /* document structure mismatch: regenerate file */ }\n}","preventionTips":["Never share one XMLStreamReader between custom traversal and generated readers.","Keep writer and reader model versions in lockstep.","XSD-validate documents before parsing."],"tags":["xml","stax","modello","parser-state","mixed-content"],"backgroundTag":"illegal-parser-state","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}