Project

Profile

Help

Bug #5585

closed

SaxonCS reports missing name attribute on xsl:accumulator but then gives System.ArgumentNullException

Added by Martin Honnen over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Diagnostics
Sprint/Milestone:
Start date:
2022-06-29
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
11, trunk
Fix Committed on Branch:
11, trunk
Fixed in Maintenance Release:
Platforms:
.NET

Description

Due do a typo I had e.g. xsl:accumulator nme="..." in my XSLT 3 code and found that Saxon EE 11.3 Java reports two messages

Error at xsl:accumulator on line 7 column 77 of sheet1-acc-no-name.xsl:
  XTSE0010  Element must have an @name attribute
Error in xsl:accumulator/@nme on line 7 column 77 of sheet1-acc-no-name.xsl:
  XTSE0090  Attribute @nme is not allowed on element <xsl:accumulator>
Errors were reported during stylesheet compilation

while SaxonCS reports the first message but then gives a System.ArgumentNullException (building the accumulator value?):

Error at xsl:accumulator on line 7 column 6 of sheet1-acc-no-name.xsl:
  XTSE0010  Element must have an @name attribute
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at Saxon.Impl.Helpers.MapUtils.Get[K,V](IDictionary`2 map, K key)
   at Saxon.Hej.expr.accum.AccumulatorRegistry.getAccumulator(StructuredQName name)
   at Saxon.Hej.style.XSLAccumulator.index(ComponentDeclaration decl, PrincipalStylesheetModule top)
   at Saxon.Hej.style.PrincipalStylesheetModule.buildIndexes()
   at Saxon.Hej.style.PrincipalStylesheetModule.preprocess(Compilation compilation)
   at Saxon.Hej.style.Compilation.compilePackage(Source source)
   at Saxon.Hej.style.StylesheetModule.loadStylesheet(Source styleSource, Compilation compilation)
   at Saxon.Hej.style.Compilation.compileSingletonPackage(Configuration config, CompilerInfo compilerInfo, Source source)
   at Saxon.Hej.s9api.XsltCompiler.compile(Source source)
   at Saxon.Hej.Transform.doTransform(String[] args)
Fatal error during transformation: ArgumentNullException: Value cannot be null. (Parameter 'key')
Exiting with code 2

Example XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">
    
    <xsl:accumulator nme="foo-collector" as="xs:string?" initial-value="()">
        <xsl:accumulator-rule match="items/foo/text()" select="string()"/>
    </xsl:accumulator>
    
    <xsl:mode on-no-match="shallow-skip" use-accumulators="#all"/>
    
    <xsl:template match="data/item/name">
        <xsl:next-match/>
        <xsl:comment select="accumulator-before('foo-collector')"/>
    </xsl:template>
    
</xsl:stylesheet>

Example XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <items>
        <foo>foo1</foo>
        <cats>
            <cat>cat1</cat>
            <cat>cat2</cat>
        </cats>
    </items>
    <data>
        <item>
            <name>item 1</name>
            <foo>foo1</foo>
            <cat>cat1</cat>
        </item>
        <item>
            <name>item 2</name>
            <foo>foo2</foo>
            <cat>cat1</cat>
        </item>
    </data>
</root>
Actions #1

Updated by Michael Kay over 2 years ago

The reason this is crashing on SaxonCS but not on SaxonJ is that in Java, we are using a map implementation for the AccumulatorRegistry that allows a call on get(null), whereas in C#, we are using a map implementation where Get(Null) causes an exception. In other words, it's pure luck that the code doesn't fail in SaxonJ.

We should adopt the usual recovery strategy where a name is missing or invalid of substituting a system-generated name.

Actions #2

Updated by Michael Kay over 2 years ago

  • Status changed from New to Resolved
  • Applies to branch trunk added
  • Fix Committed on Branch 11, trunk added

The patch is in the Java XSLAccumulator code even though the problem only manifests in SaxonCS.

Actions #3

Updated by Debbie Lockett over 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 11.4 added

Bug fix applied in the Saxon 11.4 maintenance release.

Please register to edit this issue

Also available in: Atom PDF