Project

Profile

Help

Bug #4578

NullPointerException when array:fold-left|right $zero argument is an empty sequence

Added by Vladimir Nesterovsky about 1 month ago. Updated about 1 month ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
XPath conformance
Sprint/Milestone:
-
Start date:
2020-06-07
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
10, 9.9
Fix Committed on Branch:
10, 9.9
Fixed in Maintenance Release:

Description

Following xslt gives an error:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:array="http://www.w3.org/2005/xpath-functions/array"
  exclude-result-prefixes="xs array">

  <xsl:template match="/">
    <xsl:sequence select="
      array:fold-left
      (
        [8, 9], 
        (), 
        function($first as item(), $second as item()) 
        {  
          min(($first, $second))
        }
      )"/>
  </xsl:template>

</xsl:stylesheet>
java.lang.NullPointerException
        at net.sf.saxon.functions.hof.CoercedFunction.call(CoercedFunction.java:151)
        at net.sf.saxon.functions.SystemFunction.dynamicCall(SystemFunction.java:454)
        at net.sf.saxon.ma.arrays.ArrayFunctionSet$ArrayFoldLeft.call(ArrayFunctionSet.java:269)
        at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:543)
        at net.sf.saxon.expr.Expression.process(Expression.java:949)
        at net.sf.saxon.expr.SystemFunctionCall.process(SystemFunctionCall.java:476)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:376)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:555)
        at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:659)
        at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:360)
        at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:285)
        at net.sf.saxon.Transform.processFile(Transform.java:1313)
        at net.sf.saxon.Transform.doTransform(Transform.java:853)
        at net.sf.saxon.Transform.main(Transform.java:82)
java.lang.RuntimeException: Internal error evaluating template rule  at line 7 in module file:/C:/projects/git/xslt-graph/tests/saxon-10.1-internal-error.xslt
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
        at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:555)
        at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:659)
        at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:360)
        at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:285)
        at net.sf.saxon.Transform.processFile(Transform.java:1313)
        at net.sf.saxon.Transform.doTransform(Transform.java:853)
        at net.sf.saxon.Transform.main(Transform.java:82)
Caused by: java.lang.NullPointerException
        at net.sf.saxon.functions.hof.CoercedFunction.call(CoercedFunction.java:151)
        at net.sf.saxon.functions.SystemFunction.dynamicCall(SystemFunction.java:454)
        at net.sf.saxon.ma.arrays.ArrayFunctionSet$ArrayFoldLeft.call(ArrayFunctionSet.java:269)
        at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:543)
        at net.sf.saxon.expr.Expression.process(Expression.java:949)
        at net.sf.saxon.expr.SystemFunctionCall.process(SystemFunctionCall.java:476)
        at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:376)
        ... 7 more

History

#1 Updated by Vladimir Nesterovsky about 1 month ago

This produces NPE but with different message:

    <xsl:sequence select="
      array:fold-left
      (
        [8, 9], 
        (), 
        function($first, $second) { min(($first, $second)) }
      )"/>
Exception in thread "main" java.lang.AssertionError: 
Internal error: no value for variable $first at line 17 of file:/C:/projects/git/xslt-graph/tests/saxon-10.1-internal-error.xslt

#2 Updated by Michael Kay about 1 month ago

  • Subject changed from saxon-10.1-internal-error.xslt to NullPointerException when array:fold-left|right $zero argument is an empty sequence
  • Category set to XPath conformance
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal
  • Applies to branch 9.9 added

Saxon throws a NullPointerException if the second argument ($zero) of array:fold-left or array:fold-right is an empty sequence.

Further, if the value of the $zero argument is a sequence containing two or more items, all but the first items are ignored.

Added test cases to the relevant test sets in QT3.

#3 Updated by Michael Kay about 1 month ago

  • Fix Committed on Branch 10, 9.9 added

#4 Updated by Michael Kay about 1 month ago

  • Status changed from New to Resolved

#5 Updated by Vladimir Nesterovsky about 1 month ago

If I correctly understand, the problem was to some extent related to eager evaluation of $zero parameter in array:fold-left(), and to some expectations about its cardinality.

This recalls me the case with fold-left() function (not array:fold-left()) where we experienced x4 performance differences depending on structure of $zero parameter.

See https://saxonica.plan.io/boards/3/topics/7888

#6 Updated by Michael Kay about 1 month ago

The bug was embarrassingly stupid. The implementation provides a standard call() interface

public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException {

and for the $zero argument it was using the standard coding pattern for singleton arguments:

Sequence zero = (Sequence)(arguments[1].head());

instead of

Sequence zero = arguments[1];

The real culprit was that all the QT3 test cases for this function used a singleton item as the value of $zero.

Thanks for reminder about message 7888, but I'm afraid it hasn't been possible to find time to investigate this, given that there's no suggestion of a product bug, only a minor optimization opportunity.

Please register to edit this issue

Also available in: Atom PDF