Project

Profile

Help

StAXSource and Saxon => 11 with indented XML issues (using Camel)

Added by Jonas N about 1 year ago

Hi! I'm testing Saxon through Camel, and in latest Camel 3.20.x release they updated Saxon-HE to version 11.4 (previous it used 9.9 or something like that).

Environment: Spring Boot 2.7.7, Camel 3.20.1 (Saxon-HE 11.4) and Red Hat Java 11.

After upgrading, I started to see alot of errors in different tests, which seems to be related to Saxon when the XML input is indented (pretty printed).

java.lang.ArrayIndexOutOfBoundsException: Index 8192 out of bounds for length 8192
    at net.sf.saxon.str.StringTool.compress(StringTool.java:267) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.str.CompressedWhitespace.compressWS(CompressedWhitespace.java:52) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.str.StringTool.compress(StringTool.java:277) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.pull.StaxBridge.getStringValue(StaxBridge.java:456) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.pull.PullPushTee.copyEvent(PullPushTee.java:116) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.pull.PullPushTee.next(PullPushTee.java:74) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.pull.PullConsumer.consume(PullConsumer.java:42) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.pull.PullPushCopier.copy(PullPushCopier.java:44) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.pull.PullSource.deliver(PullSource.java:95) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.pull.ActiveStAXSource.deliver(ActiveStAXSource.java:61) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.event.Sender.send(Sender.java:105) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.Controller.makeSourceTree(Controller.java:1337) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:341) ~[Saxon-HE-11.4.jar:na]
    at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:75) ~[Saxon-HE-11.4.jar:na]
    at org.apache.camel.component.xslt.XsltBuilder.process(XsltBuilder.java:123) ~[camel-xslt-3.20.1.jar:3.20.1]
    at org.apache.camel.support.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:93) ~[camel-support-3.20.1.jar:3.20.1]
    at org.apache.camel.component.xslt.XsltEndpoint.onExchange(XsltEndpoint.java:117) ~[camel-xslt-3.20.1.jar:3.20.1]

Depending on the XMLInputFactory in use, error message and behaviour is slightly different.

Using default com.sun.xml.internal.stream.XMLInputFactoryImpl I get "Index 8192 out of bounds for length 8192" and most indented files seems to fail if they are larger than around 4500 bytes. This seems pretty easy to reproduce.

Changing to com.ctc.wstx.stax.WstxInputFactory (Woodstox 6.4.0) I get "Index 4000 out of bounds for length 4000" instead (exact same error otherwise).

With Woodstox it's possible, but harder, to reproduce. I think it might depend on what position whitespace (tabs or spaces) appear in the file if it works or not, but I'm not sure about that.

I noticed that Camel by default is using StAXSource, which seems to be whats the root cause of the issue.

As default, Camel seems to be doing this before sending the payload to Saxon:

o.a.camel.component.xslt.XsltBuilder: Using javax.xml.transform.stax.StAXSource as source

Forcing Camel to disable StAXSource does "fix" the problem, Camel will log this instead and the indented XML file will go through.

o.a.camel.component.xslt.XsltBuilder: Using org.apache.camel.support.builder.xml.StAX2SAXSource as source

I also tried myself to switch between javax.xml.transform.Source and javax.xml.transform.stax.StAXSource, and using the same input XML StAXSource would fail when using Source didn't.

I tried different versions of Saxon-HE and anything below 11 seems fine, if I use Saxon-HE 10.8 I don't see any issues. But all versions after that (even Saxon-HE 12.0) seems to do do this.

Not sure exactly where this issue belongs, but it would be interesting to hear if anyone else have come across this or if you have any idea what could be causing it?


Replies (2)

RE: StAXSource and Saxon => 11 with indented XML issues (using Camel) - Added by Michael Kay about 1 year ago

Thanks for reporting it.

Logged here https://saxonica.plan.io/issues/5838

Please watch the issue to follow this up.

    (1-2/2)

    Please register to reply