#1178 position variable incorrectly removed in ForClause

v9.4
open
oneil
5
2014-05-28
2011-12-23
oneil
No

A fix has been applied to the class ForClause. We check that all terms in a WhereClause is not depending on the position variables in a ForClause before removing the variable; This fixes the following bug reported by Gunther Rademacher:

An exception as stated in the subject line was thrown while
running some pre-existing XQuery code on Saxon-HE 9.4.0.1J and on Saxon-EE 9.4.0.1J.

The shortest repro that I (Gunther Rademacher) could come up with is this:

  declare function local:f($a, $b) as node()*
  {
    let $c := $a[1]
    return
      if (empty($a)) then
        $b
      else if ($c/self::y) then
        for $e at $i in $c/*
        where $i > 1 and $i < count($c/*)
        return $e
      else
        local:f($a[position() > 1], ($b, $c))
  };

  local:f(<x/>, ())

While reducing the original code, at one point I also saw a

  java.lang.ArrayIndexOutOfBoundsException: 
  Local variable has not been allocated a stack frame slot

Discussion

  • Michael Kay
    Michael Kay
    2012-01-23

    Fixed in 9.4.0.2

     
  • Michael Kay
    Michael Kay
    2012-01-25

    Reopened: the previous fix (incorporated in 9.4.0.2) was incomplete. Before replacing a test on the positional variable in a where clause by a positional predicate, we need to check that there are no other references to the positional variable anywhere in the FLWOR expression. The previous fix was only checking for other references elsewhere in the where clause. A revised fix is being committed.