NullPointerException after inlining variables
In a problem reported by Hans-Juergen Rennau on saxon-help list, followed up by private email, there were two occurrences of a problem that resulted from inlining of local variables:
The first two are very similar. They occur when inlining a variable declared in a FLWOR expression, for example $merge on line 51 of namesReporter.mod.xq. The inlining happens when a variable is declared and is only used once (and not in a loop): the effect is to eliminate the let clause from the FLWOR expression, and replace the variable reference by the expression to which it is bound. Before doing this, the expression is copied (the cases where this is necessary are rather obscure, but they do arise). The copy() operation is implemented separately for each expression, and it is intended to retain location information. But your query exposed two cases where location information was not being copied: the ItemChecker expression and a Switch expression (neither appear literally in the code, but are created by earlier optimizations). The location information includes a pointer to the containing function, and in the absence of this, a subsequent operation on the expression tree was failing.
#1 Updated by Michael Kay over 5 years ago
- Status changed from New to Resolved
For 9.6, I have patched the copy() method of the two expressions where the problem occured: ItemChecker and Switch.
For 9.7, I have reviewed all implementations of the copy() method (over 140 of them) and have added a call to copyLocationInfo() to those where it was missing. This is belt-and-braces; it won't usually be necessary, because the way copyLocationInfo() works, information is passed beween parents and children on the tree so the code is generally fairly robust. However, we'll keep this under review, it may be prudent to change all implementations of copy() on the 9.6 branch as well.
Closing for now.
Please register to edit this issue