This problem affects union patterns where one or more branches contain a predicate, where the pattern appears in an XSLT instruction - that is in the count or from attribute of xsl:number, or the group-starting-with or group-ending-with attribute of xsl:for-each-group.
If the predicate, either as written or as modified by the optimizer, contains a for/some/every expression, then no slot on the stack frame is allocated to the range variable, and evaluation of the pattern fails with an ArrayIndexOutOfBoundsException reporting an index of -999 (which always indicates a reference to a variable for which no slot has been allocated).
This is more likely to occur in 9.0 which rewrites expressions of the form @x=123 as "some $z in @x satisfies $z eq 123". Assuming that the attribute is untyped, then a workaround - which is good practice anyway - is to replace the "=" operator by "eq".
A patch is being placed in Subversion. Test case added, numb42