Project

Profile

Help

Bug #4578

closed

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

Added by Vladimir Nesterovsky over 4 years ago. Updated about 4 years ago.

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

100%

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

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
Actions #1

Updated by Vladimir Nesterovsky over 4 years 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
Actions #2

Updated by Michael Kay over 4 years 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.

Actions #3

Updated by Michael Kay over 4 years ago

  • Fix Committed on Branch 10, 9.9 added
Actions #4

Updated by Michael Kay over 4 years ago

  • Status changed from New to Resolved
Actions #5

Updated by Vladimir Nesterovsky over 4 years 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

Actions #6

Updated by Michael Kay over 4 years 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.

Actions #7

Updated by O'Neil Delpratt about 4 years ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 10.2 added

Bug fix applied in the Saxon 10.2 maintenance release.

Actions #8

Updated by O'Neil Delpratt about 4 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 9.9.1.8 added

Bug fix applied on the Saxon 9.9.1.8 maintenance release.

Please register to edit this issue

Also available in: Atom PDF