#290 ArrayIndexOutOfBounds in setLocalVariable

v8.2
closed
5
2012-10-08
2005-01-07
Michael Kay
No

The following exception can occur in XSLT processing:

java.lang.ArrayIndexOutOfBoundsException: -999
at
net.sf.saxon.expr.XPathContextMajor.setLocalVariable(XPathContextMajor.java:212)
at
net.sf.saxon.expr.LetExpression.process(LetExpression.java:123)
at
net.sf.saxon.instruct.Template.expand(Template.java:100)

This occurs when an xsl:for-each instruction appears as
the first thing inside xsl:template, and the for-each
includes a subexpression that can be evaluated outside
the loop. The optimizer is failing to allocate space
for the new variable it has created.

Source fix:In XSLTemplate.java, at line 293, change

try {
Expression exp2 =
exp.analyze(staticContext, contextItemType);
if (exp != exp2) {
compiledTemplate.setBody(exp2);
}
} catch (XPathException e) {
compileError(e);
}

to

try {
Expression exp2 =
exp.analyze(staticContext, contextItemType);
if (exp != exp2) {
compiledTemplate.setBody(exp2);
exp = exp2;
}
} catch (XPathException e) {
compileError(e);
}

Discussion