I'm currently facing a strange issue, which does not happen frequently. My application unmarshals a XML file using STaX with JAXB and Java-Streams (XMLStreamReader
) with several millions rows and import these objects to a database on startup if XML has been changed. So far this is working correctly, except on some devices (approximately 5% of over 1000 devices). On these devices I got a javax.xml.stream.XMLStreamException
. Sometimes a restart helps and the XML could be successfully processed. The XML itself has always the same content on all devices, so XML and XSD are both valid.
The exception also not always occur on same place. E.g:
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2650616,17] Message: Element type "XX" must be followed by either attribute specifications, ">" or "/>".
Later:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3272359,14] Message: Element type "XY" must be followed by either attribute specifications, ">" or "/>".]
The whole application is running in a microservice architecture, but there are no dependencies to other services. On startup there happens a lot as each microservice initializes his own state. For me it seems, that there might be some memory issues as it's not reproducible and the microservices on the devices don't differ in their versions.
Before optimizing unmarshalling process I would like to be able to reproduce the issue first to ensure, that any improvements are working. When I try to reduce Xmx and Xms I'll might get OutOfMemoryException
but never XMLStreamException
.
Right now I'm asking myself,
- When and why may
XMLStreamException
occur and how can I reproduce this behaviour? - Why this may happen not frequently, as all devices should be the same?
- Should I switch to SAX which is more memory-efficient?
Thanks for all help in advance.