Search code examples
javaxmlstax

STAX Parser fails with large XML


I have encountered a very weird situation. I have 2 XML's with me which I am trying to merge and form a single XML. I am using STAX Parser to acheive it.

It works perfectly with Small files but fails when the file size is more than 300 KB which I believe is not very huge.

Not posting the XML or code here as it is very big.

Please find the error below

java.lang.ArrayIndexOutOfBoundsException: -32769
    at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl$ElementStack.peek(Unknown Source)
    at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.closeStartTag(Unknown Source)
    at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeStartElement(Unknown Source)
    at com.sun.xml.internal.stream.writers.XMLEventWriterImpl.add(Unknown Source)

There is no issue with the XML. Line at which I am getting the error is

eventWriter.add(event);. Here eventWriter is an instance of XMLEventWriter and event is of XMLEvent

Let me know if anyone has faced the similar error.


Solution

  • I am able to resolve the above issue. It was nothing to do with STAX. There were some loop holes in the code which I have fixed now.