Project

Profile

Help

Bug #6449

closed

System.AggregateException in SaxonCS (12.4) when using collection function to pull a collection catalog file over HTTP(S)

Added by Martin Honnen 6 months ago. Updated 6 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
External resources
Sprint/Milestone:
-
Start date:
2024-06-10
Due date:
% Done:

100%

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

Description

I have an example XSLT 3 stylesheet

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all"
  expand-text="yes">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template name="xsl:initial-template">
    <result>
      <xsl:copy-of select="collection('https://martin-honnen.github.io/xslt/2023/collection-example1.xml')"/>
      <xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
    </result>
  </xsl:template>

</xsl:stylesheet>

which works fine in Saxon HE 12.4 and SaxonC HE 12.4.2 from the command line (-it) but throws an error (System.AggregateException) for SaxonCS 12.4:

PS C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\collection-test1> & 'C:\Program Files\Saxonica\SaxonCS-12.4\SaxonCS.exe' transform -it -xsl:.\collection-catalog-test2.xsl
System.AggregateException: One or more errors occurred. (https://martin-honnen.github.io/xslt/2023/collection-file1.xml)
 ---> System.Exception: https://martin-honnen.github.io/xslt/2023/collection-file1.xml
   at Saxon.Impl.Helpers.UriUtils.ToURL(Uri uri)
   at Saxon.Hej.resource.AbstractResourceCollection.getInputDetails(String resourceURI)
   at Saxon.Hej.resource.CatalogCollection.<>c__DisplayClass4_0.<getResources>b__0(String input)
   at Saxon.Impl.Overrides.MappingEnumerator`2.get_Current()
   at Saxon.Hej.functions.CollectionFn.CollectionIterator.next()
   at Saxon.Impl.Parallel.MultithreadedItemMappingIterator.InputAsEnumerable(SequenceIterator iter)+MoveNext()
   at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerable.GrabChunk_Single(KeyValuePair`2[] destArray, Int32 requestedChunkSize, Int32& actualNumElementsGrabbed)
   at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerator.GrabNextChunk(Int32 requestedChunkSize)
   at System.Collections.Concurrent.Partitioner.DynamicPartitionEnumerator_Abstract`2.MoveNext()
   at System.Linq.Parallel.PartitionerQueryOperator`1.OrderablePartitionerEnumerator.MoveNext(TElement& currentElement, Int32& currentKey)
   at System.Linq.Parallel.SelectQueryOperator`2.SelectQueryOperatorEnumerator`1.MoveNext(TOutput& currentElement, TKey& currentKey)
   at System.Linq.Parallel.OrderPreservingPipeliningSpoolingTask`2.SpoolingWork()
   at System.Linq.Parallel.SpoolingTaskBase.Work()
   at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
   at System.Linq.Parallel.QueryTask.<>c.<.cctor>b__10_0(Object o)
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   --- End of inner exception stack trace ---
   at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
   at System.Linq.Parallel.OrderPreservingPipeliningMergeHelper`2.OrderedPipeliningMergeEnumerator.ThrowIfInTearDown()
   at System.Linq.Parallel.OrderPreservingPipeliningMergeHelper`2.OrderedPipeliningMergeEnumerator.MoveNext()
   at System.Linq.Parallel.QueryOpeningEnumerator`1.MoveNext()
   at Saxon.Impl.Parallel.MultithreadedItemMappingIterator.next()
   at Saxon.Hej.value.SequenceExtent.from(SequenceIterator iter)
   at Saxon.Hej.om.SequenceTool.toGroundedValue(SequenceIterator iterator)
   at Saxon.Hej.functions.CollectionFn.call(XPathContext context, Sequence[] arguments)
   at Saxon.Hej.expr.SystemFunctionCall.SystemFunctionCallElaborator.<>c__DisplayClass1_0.<elaborateForPull>b__1(XPathContext context)
   at Saxon.Hej.expr.instruct.CopyOf.CopyOfElaborator.<>c__DisplayClass2_4.<elaborateForPush>b__3(Outputter output, XPathContext context)
   at Saxon.Hej.expr.instruct.Block.BlockElaborator.<>c__DisplayClass3_1.<elaborateForPush>b__1(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.FixedElement.FixedElementElaborator.<>c__DisplayClass0_0.<elaborateForPush>b__0(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.NamedTemplate.expand(Outputter output, XPathContext context)
   at Saxon.Hej.trans.XsltController.callTemplate(StructuredQName initialTemplateName, Receiver out)
   at Saxon.Hej.s9api.Xslt30Transformer.callTemplate(QName templateName, Destination destination)
   at Saxon.Hej.Transform.processFile(Source source, XsltExecutable sheet, File outputFile, CommandLineOptions options)
   at Saxon.Hej.Transform.doTransform(String[] args)
Fatal error during transformation: AggregateException: One or more errors occurred. (https://martin-honnen.github.io/xslt/2023/collection-file1.xml)
Exiting with code 2

Example output with SaxonC is e.g

<?xml version="1.0" encoding="UTF-8"?>
<result>
   <example>example 1</example>
   <example>example 2</example>
   <!--Run with SAXON HE 12.4.2 at 2024-06-10T21:51:18.3941897+02:00-->
</result>

I have for the time being used "category: command line" as it is there where I see it but I guess it is an error in the collection handling of SaxonCS.

Actions #1

Updated by Martin Honnen 6 months ago

I see the same error if I use a local collection catalog file but let it pull the files over HTTP(S) e.g. with a local catalog file

<collection xml:base="https://martin-honnen.github.io/xslt/2023/" stable="true">
  <doc href="collection-file1.xml"/>
  <doc href="collection-file2.xml"/>
</collection>

and the XSLT code

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all"
  expand-text="yes">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template name="xsl:initial-template">
    <result>
      <xsl:copy-of select="collection('collection-example1.xml')"/>
      <xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
    </result>
  </xsl:template>

</xsl:stylesheet>

SaxonCS (tested with 12.4) also fails with e.g.

PS C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\collection-test1> & 'C:\Program Files\Saxonica\SaxonCS-12.4\SaxonCS.exe' transform -it -xsl:.\collection-catalog-test3.xsl
System.AggregateException: One or more errors occurred. (https://martin-honnen.github.io/xslt/2023/collection-file1.xml)
 ---> System.Exception: https://martin-honnen.github.io/xslt/2023/collection-file1.xml
   at Saxon.Impl.Helpers.UriUtils.ToURL(Uri uri)
   at Saxon.Hej.resource.AbstractResourceCollection.getInputDetails(String resourceURI)
   at Saxon.Hej.resource.CatalogCollection.<>c__DisplayClass4_0.<getResources>b__0(String input)
   at Saxon.Impl.Overrides.MappingEnumerator`2.get_Current()
   at Saxon.Hej.functions.CollectionFn.CollectionIterator.next()
   at Saxon.Impl.Parallel.MultithreadedItemMappingIterator.InputAsEnumerable(SequenceIterator iter)+MoveNext()
   at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerable.GrabChunk_Single(KeyValuePair`2[] destArray, Int32 requestedChunkSize, Int32& actualNumElementsGrabbed)
   at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerator.GrabNextChunk(Int32 requestedChunkSize)
   at System.Collections.Concurrent.Partitioner.DynamicPartitionEnumerator_Abstract`2.MoveNext()
   at System.Linq.Parallel.PartitionerQueryOperator`1.OrderablePartitionerEnumerator.MoveNext(TElement& currentElement, Int32& currentKey)
   at System.Linq.Parallel.SelectQueryOperator`2.SelectQueryOperatorEnumerator`1.MoveNext(TOutput& currentElement, TKey& currentKey)
   at System.Linq.Parallel.OrderPreservingPipeliningSpoolingTask`2.SpoolingWork()
   at System.Linq.Parallel.SpoolingTaskBase.Work()
   at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
   at System.Linq.Parallel.QueryTask.<>c.<.cctor>b__10_0(Object o)
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   --- End of inner exception stack trace ---
   at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
   at System.Linq.Parallel.OrderPreservingPipeliningMergeHelper`2.OrderedPipeliningMergeEnumerator.ThrowIfInTearDown()
   at System.Linq.Parallel.OrderPreservingPipeliningMergeHelper`2.OrderedPipeliningMergeEnumerator.MoveNext()
   at System.Linq.Parallel.QueryOpeningEnumerator`1.MoveNext()
   at Saxon.Impl.Parallel.MultithreadedItemMappingIterator.next()
   at Saxon.Hej.value.SequenceExtent.from(SequenceIterator iter)
   at Saxon.Hej.om.SequenceTool.toGroundedValue(SequenceIterator iterator)
   at Saxon.Hej.functions.CollectionFn.call(XPathContext context, Sequence[] arguments)
   at Saxon.Hej.expr.SystemFunctionCall.SystemFunctionCallElaborator.<>c__DisplayClass1_0.<elaborateForPull>b__1(XPathContext context)
   at Saxon.Hej.expr.instruct.CopyOf.CopyOfElaborator.<>c__DisplayClass2_4.<elaborateForPush>b__3(Outputter output, XPathContext context)
   at Saxon.Hej.expr.instruct.Block.BlockElaborator.<>c__DisplayClass3_1.<elaborateForPush>b__1(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.FixedElement.FixedElementElaborator.<>c__DisplayClass0_0.<elaborateForPush>b__0(Outputter out, XPathContext context)
   at Saxon.Hej.expr.instruct.NamedTemplate.expand(Outputter output, XPathContext context)
   at Saxon.Hej.trans.XsltController.callTemplate(StructuredQName initialTemplateName, Receiver out)
   at Saxon.Hej.s9api.Xslt30Transformer.callTemplate(QName templateName, Destination destination)
   at Saxon.Hej.Transform.processFile(Source source, XsltExecutable sheet, File outputFile, CommandLineOptions options)
   at Saxon.Hej.Transform.doTransform(String[] args)
Fatal error during transformation: AggregateException: One or more errors occurred. (https://martin-honnen.github.io/xslt/2023/collection-file1.xml)
Exiting with code 2

Saxon Java and Saxon C do handle this test case without errors.

Actions #2

Updated by Martin Honnen 6 months ago

Oddly https://saxonica.plan.io/projects/saxonmirrorhe/repository/he/revisions/he_mirror_saxon_12_4/entry/src/main/saxon-cs/engine/Saxon/Impl/Helpers/UriUtils.cs#L48 shows a code using throw:

        public static Saxon.Ejava.net.URL ToURL(System.Uri uri) {
            throw new(uri.ToString());
        }
Actions #3

Updated by Michael Kay 6 months ago

Thanks for reporting it. Indeed, there is an effectively unimplemented method UriUtils.ToURL() which is used as part of the collection resolver machinery.

I don't know why the method doesn't simply do return new URL(uri) - I guess there was a reason at the time.

Actions #4

Updated by Michael Kay 6 months ago

When I fix this, I get a NotImplementedException on URLConnection.getContentEncoding().

I've implemented that (in HttpURLConnection) and this test case is now passing. I guess there's a need for a lot more testing in this area but one test is better than none and we want to get this fix into Saxon 12.5.

Actions #5

Updated by Michael Kay 6 months ago

  • Category changed from Command Line to External resources
  • Status changed from New to Resolved
  • Assignee set to Michael Kay
  • Applies to branch trunk added
  • Fix Committed on Branch 12, trunk added
Actions #6

Updated by O'Neil Delpratt 6 months ago

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

Bug fix applied in the Saxon 12.5 Maintenance release.

Please register to edit this issue

Also available in: Atom PDF