Project

Profile

Help

Possible bug in Saxon-HE (net.sf.saxon.str.StringTool): IndexOutOfBoundsException (Please confirm)

Added by Bert Speckels about 1 year ago

Hi there

I am new here and want to check if my current problem is a bug. Maybe I should post a bug directly but I am unsure...

We are using Apache Camel XSLT Saxon component. The currently used version of Saxon HE is "Saxon-HE-11.4".

Our XSLT processing produces an IndexOutOfBounds exception (see callstack below) As far as I can see, there is an error in the StringTool method "compress":

01    public static UnicodeString compress(char[] in, int offset, int len, boolean compressWS) { // (1) len is an amount of characters!
02        //final int inlen = in.length;
03         if (len == 0) {
04           return EmptyUnicodeString.getInstance();
05        }
06        int max = 255;
07        int end = offset + len; // (2) end is a position!
08        boolean allWhite = compressWS;
09        int surrogates = 0;
10        // Find the maximum code value, and test whether all-white or surrogate
11        for (int i=offset; i < end; i++) {

20        }
21        if (allWhite) {
22            return CompressedWhitespace.compressWS(in, offset, end); // (3) end is used as an amount of charaters (->len)
23        }

55  } 

As far as I understand:

  • in line 01: "in" is the text, "offset" a position in the text and "len" the amount of characters from that position (defining a substring of the text)
  • in line 07: "end" is defined as the end position of that substring inside "in" (offset + len)
  • in line 22: "end" is used here instead of "len" but compressWS expects an amount of characters (len) not a position (end) ... see below
public static UnicodeString compressWS(char[] in, int start, int len) {
   ...
   return StringTool.compress(in, start, len, false);
}

I think that in line 22 "len" must be used instead of "end"

Here is the callstack:

java.lang.ArrayIndexOutOfBoundsException: Index 4000 out of bounds for length 4000
	at net.sf.saxon.str.StringTool.compress(StringTool.java:267)
	at net.sf.saxon.str.CompressedWhitespace.compressWS(CompressedWhitespace.java:52)
	at net.sf.saxon.str.StringTool.compress(StringTool.java:277)
	at net.sf.saxon.pull.StaxBridge.getStringValue(StaxBridge.java:456)
	at net.sf.saxon.pull.PullPushTee.copyEvent(PullPushTee.java:116)
	at net.sf.saxon.pull.PullPushTee.next(PullPushTee.java:74)
	at net.sf.saxon.pull.PullConsumer.consume(PullConsumer.java:42)
	at net.sf.saxon.pull.PullPushCopier.copy(PullPushCopier.java:44)
	at net.sf.saxon.pull.PullSource.deliver(PullSource.java:95)
	at net.sf.saxon.pull.ActiveStAXSource.deliver(ActiveStAXSource.java:61)
	at net.sf.saxon.event.Sender.send(Sender.java:105)
	at net.sf.saxon.Controller.makeSourceTree(Controller.java:1337)
	at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:341)
	at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:75)
	at org.apache.camel.component.xslt.XsltBuilder.process(XsltBuilder.java:123)

Replies (4)

Please register to reply

RE: Possible bug in Saxon-HE (net.sf.saxon.str.StringTool): IndexOutOfBoundsException (Please confirm) - Added by Bert Speckels about 1 year ago

I can answer my own question: If only I had checked the implementation in Saxon HE 11.5 beforehand.

It seems that this has been fixed in Saxon HE 11.5:

 if (allWhite) {
            return CompressedWhitespace.compressWS(in, offset, len);
  }

RE: Possible bug in Saxon-HE (net.sf.saxon.str.StringTool): IndexOutOfBoundsException (Please confirm) - Added by Bert Speckels about 1 year ago

It was my fault:

I filter in the bug tracker for "ArrayIndexOutOfBounds" but didn't remove the status filter (only "open" issued).

Thanx for your quick reply. I will force Camel to use version 11.5 :-)

    (1-4/4)

    Please register to reply