BTW - if this error happens, is there anything we can do programatically to fix the situation?  We currently have to bounce the app servers.  It would be better if we could do something in our code, i.e., dump the cache, reset the processor, etc...
Any ideas?

From: Ackley, Paul []
Sent: Thursday, May 28, 2009 4:07 PM
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] ArrayIndexOutOfBoundsException in Saxon 8.6

Thanks Michael!
I have created a ticket with Oracle (since they now own WebLogic).  This is their JDK which is possibly causing this error.  BTW - We've used Saxon in the 32 bit JDK without incident....

From: Michael Kay []
Sent: Thursday, May 28, 2009 1:29 PM
To: 'Mailing list for the SAXON XSLT and XQuery processor'
Subject: Re: [saxon] ArrayIndexOutOfBoundsException in Saxon 8.6

The diagnostics show that at the time the crash occurs, the contents of the IntHashSet are indeed very strange. It appears to contain two "real" values (65537 and 131074), 15 unused slots (shown as "*"), and 15 slots containing the value -1. The size=2 is consistent with the number of "real" values, while the iterator is going to return all the -1 values as well, so the code in NamespaceIterator will allocate an array of size 2 and then try to put 17 values into it, which accounts for the AIOOB exception.
So, how did these -1 values get there, and what is the significance of the fact that they occupy alternate slots?
My suspicion would fall on the instruction used to initialize the array right at the start:
java.util.Arrays.fill(_values, ndv);
where _values is the array of 32 slots, and ndv is Integer.MIN_VALUE. It looks to me as if the implementation of this call might be filling the array 8 bytes (64 bits) at a time, and might be writing the value FFFFFFFF80000000 to these 64 bits rather than 8000000080000000.
Hopefully that will give the people who support the JVM something more concrete to look for; I don't think I can go any further than that at the Saxon level.
As a trial workaround, we could try using a value other than MIN_VALUE to represent unoccupied slots. For namespace codes, any negative number would do, and the obvious choice is -1. It's tricky though when it takes months for the bug to reveal itself!


Michael Kay

From: Ackley, Paul []
Sent: 28 May 2009 17:34
To: Ackley, Paul; Mailing list for the SAXON XSLTand XQuery processor
Subject: Re: [saxon] ArrayIndexOutOfBoundsException in Saxon 8.6

After a couple months of testing the new debugging build of Saxon this error has finally occurred.  The debugging information you put in the code printed the following to our logs:
186479642 [[ACTIVE] ExecuteThread: '16' for queue: 'weblogic.kernel.Default (self-tuning)'] INFO com.qwest.ecomm.xslt.XSLTObject  -
 TransformerFactory implementing class=class weblogic.xml.jaxp.RegistrySAXTransformerFactory
*** Internal error in NamespaceIterator ***
Contents of IntHashSet
*, *, 65537, -1, 131074, -1, *, -1, *, -1,
*, -1, *, -1, *, -1, *, -1, *, -1,
*, -1, *, -1, *, -1, *, -1, *, -1,
*, -1,
size: 2
ndv: -2147483648
nlo: 8
nhi: 268435456
nmax: 32
shift: 26
mask: 31
Result of iterator:
65537, -1, 131074, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1,
186479643 [[ACTIVE] ExecuteThread: '16' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR com.qwest.ecomm.xslt.XSLTObject
- Caught generic exception while creating a transformer object.
java.lang.ArrayIndexOutOfBoundsException: 2
        at net.sf.saxon.tree.ElementImpl.getInScopeNamespaceCodes(
        at net.sf.saxon.PreparedStylesheet.setStylesheetDocument(
        at net.sf.saxon.PreparedStylesheet.prepare(
        at net.sf.saxon.TransformerFactoryImpl.newTemplates(
        at weblogic.xml.jaxp.RegistryTransformerFactory.newTemplates(
        at com.qwest.ecomm.xslt.XSLTObject.getTemplates(
        at com.qwest.ecomm.xslt.XSLTObject.<init>(
        at Source)
        at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at weblogic.webservice.component.javaclass.JavaClassInvocationHandler.invoke(
        at weblogic.webservice.core.handler.InvokeHandler.handleRequest(
        at weblogic.webservice.core.HandlerChainImpl.handleRequest(
        at weblogic.webservice.core.DefaultOperation.process(
        at weblogic.webservice.server.Dispatcher.process(
        at weblogic.webservice.server.Dispatcher.doDispatch(
        at weblogic.webservice.server.Dispatcher.dispatch(
        at weblogic.webservice.server.WebServiceManager.dispatch(

Does this give you any indication of what is going wrong?
Paul Ackley

From: Ackley, Paul
Sent: Thursday, March 19, 2009 4:16 PM
To: Ackley, Paul; Mailing list for the SAXON XSLT and XQuery processor
Subject: RE: [saxon] ArrayIndexOutOfBoundsException in Saxon 8.6

Here is an interesting article on how the JRockit JVM (maybe Sun's as well?) does optimize the code on the fly:
The JVM first runs JIT compilation, so that the application can get running.  JRockit then monitor's threads and samples what could benefit from being optimized.  I guess my hypothesis is that the initial JIT compilation of the loop in NamespaceIterator.getInScopeNamespaceCodes() runs okay, but then after time the JVM decides to optimize this loop even more and possibly that's when we experience this issue?
Just a thought.

From: Ackley, Paul
Sent: Thursday, March 19, 2009 4:02 PM
To: 'Mailing list for the SAXON XSLT and XQuery processor'
Subject: RE: [saxon] ArrayIndexOutOfBoundsException in Saxon 8.6

The build of Saxon has been installed and the application has been running for 3 days without running into this "ArrayIndexOutOfBoundsException" exception.  I'll let you know if it happens and what the debugging output looks like.  Typically, by now the problem has occurred.  I'm wondering if the JVM does some optimization of the loop which iterates through the hash and if putting this try/catch in this code possibly caused the JVM to not do the optimization - but really this is just a very weak hypothesis on my part.  Just because it hasn't happened yet doesn't mean it wont.  Time will tell.
I'll keep you updated.
Thanks for all your help thus far.
Paul Ackley