Bug #2173

NullPointerException after inlining variables

Added by Michael Kay over 5 years ago. Updated about 4 years ago.

Start date:
Due date:
% Done:


Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:


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.

Related issues

Related to Saxon - Bug #2218: ByteCode generation failure during compilation in 9.6 Closed 2014-11-11 Actions


#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.

#2 Updated by O'Neil Delpratt over 5 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in version set to

Bug fix applied to the maintenance release Saxon

#3 Updated by O'Neil Delpratt about 4 years ago

  • Sprint/Milestone set to
  • Applies to branch 9.6 added
  • Fix Committed on Branch 9.6 added
  • Fixed in Maintenance Release added

Please register to edit this issue

Also available in: Atom PDF