I'm seeing an intermittent problem with Saxon that's causing some real headache for my users; I'm hoping someone could have a look and offer any insights as to what might be going wrong.  The stack trace is given below; as you can see our code calls Transformer.transform(), but it goes wrong at some point.  The exception is intermittent, I can not reliably reproduce it by running this code with the exact same input data.  However, when it does happen, there are indications that it will keep happening on the same data, until the process is restarted (though this isn't 100% certain).  I can't tell from the source code what might have gone wrong, it looks to me there's no way that that line in MemoClosure$ProgressiveIterator could access a null pointer (nor the following line...).  But I don't really know this code at all.

Hoping someone could shed some light on this.

Regards,
Jan

(This is happening with Saxon 9.0.0.3, Java 1.6.0_17 on 64-bit Linux)

Caused by: java.lang.NullPointerException 
at net.sf.saxon.value.MemoClosure.access$000(MemoClosure.java:48) 
at net.sf.saxon.value.MemoClosure$ProgressiveIterator.next(MemoClosure.java:322) 
at net.sf.saxon.functions.Aggregate.count(Aggregate.java:286) 
at net.sf.saxon.functions.Aggregate.evaluateItem(Aggregate.java:97) 
at net.sf.saxon.expr.ValueComparison.effectiveBooleanValue(ValueComparison.java:552) 
at net.sf.saxon.instruct.Choose.evaluateItem(Choose.java:654) 
at net.sf.saxon.expr.ExpressionTool.evaluate(ExpressionTool.java:295) 
at net.sf.saxon.instruct.UserFunction.call(UserFunction.java:318) 
at net.sf.saxon.expr.UserFunctionCall.callFunction(UserFunctionCall.java:389) 
at net.sf.saxon.expr.UserFunctionCall.iterate(UserFunctionCall.java:368) 
at net.sf.saxon.expr.Expression.effectiveBooleanValue(Expression.java:421) 
at net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:618) 
at net.sf.saxon.instruct.Instruction.process(Instruction.java:94) 
at net.sf.saxon.instruct.ForEach.processLeavingTail(ForEach.java:300) 
at net.sf.saxon.instruct.Template.expand(Template.java:192) 
at net.sf.saxon.instruct.CallTemplate.process(CallTemplate.java:255) 
at net.sf.saxon.instruct.CallTemplate.processLeavingTail(CallTemplate.java:279) 
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:399) 
at net.sf.saxon.instruct.Instruction.process(Instruction.java:94) 
at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298) 
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175) 
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343) 
at net.sf.saxon.Controller.transformDocument(Controller.java:1735) 
at net.sf.saxon.Controller.transform(Controller.java:1559) 
<...>