Project

Profile

Help

Maintenance: Planio will be observing a scheduled maintenance window this Tuesday, November 5, 2024 from 03:00 UTC until 06:30 UTC to perform urgent network maintenance in our primary data center. Your Planio account will be unavailable during this maintenance window.

Bug #6340

closed

using `saxon:capture="yes"` in an accumlator rule with streamable="yes" can throw java.util.EmptyStackException

Added by Matt Patterson 9 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2024-02-06
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, Java

Description

I managed to create a use of <xsl:accumulator> that causes exceptions if streaming is enabled and not otherwise.

It seems to be triggered when the accumulator rules selects a text node: if the accumulator rule is changed to use the pattern tag instead of tag/text() the exception does not occur.

Stylesheet was executed with java -cp /opt/saxon/current/saxon-ee-12.4.jar:/Users/matt/.saxon:'/opt/saxon/current/lib/*' com.saxonica.Transform -xsl:bug.xsl -s:input.xml

With the /opt/saxon/current directory containing the contents of the 12.4 .zip downloaded from https://downloads.saxonica.com/SaxonJ/EE/12/SaxonEE12-4J.zip

java.util.EmptyStackException
	at java.base/java.util.Stack.peek(Stack.java:101)
	at java.base/java.util.Stack.pop(Stack.java:83)
	at com.saxonica.ee.stream.watch.AccumulatorWatch.applyRule(AccumulatorWatch.java:194)
	at com.saxonica.ee.stream.watch.AccumulatorWatch.processItem(AccumulatorWatch.java:264)
	at com.saxonica.ee.stream.watch.MultiAccumulatorWatch.processItem(MultiAccumulatorWatch.java:95)
	at com.saxonica.ee.stream.watch.WatchManager.characters(WatchManager.java:464)
	at com.saxonica.ee.stream.ContentDetector.characters(ContentDetector.java:58)
	at net.sf.saxon.event.ReceivingContentHandler.flush(ReceivingContentHandler.java:701)
	at net.sf.saxon.event.ReceivingContentHandler.endElement(ReceivingContentHandler.java:576)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:618)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1728)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2899)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:542)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:889)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:637)
	at net.sf.saxon.resource.ActiveSAXSource.deliver(ActiveSAXSource.java:192)
	at net.sf.saxon.resource.ActiveStreamSource.deliver(ActiveStreamSource.java:73)
	at net.sf.saxon.event.Sender.send(Sender.java:104)
	at net.sf.saxon.trans.XsltController.applyStreamingTemplates(XsltController.java:969)
	at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:422)
	at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:306)
	at net.sf.saxon.Transform.processFile(Transform.java:1389)
	at net.sf.saxon.Transform.doTransform(Transform.java:879)
	at net.sf.saxon.Transform.main(Transform.java:83)
Fatal error during transformation: java.util.EmptyStackException:  (no message)

A simple repro XSL and input XML are attached.


Files

bug.xsl (1.24 KB) bug.xsl Matt Patterson, 2024-02-06 15:11
input.xml (215 Bytes) input.xml Matt Patterson, 2024-02-06 15:11
Actions #1

Updated by Michael Kay 9 months ago

  • Status changed from New to In Progress
  • Assignee set to Michael Kay
  • Fix Committed on Branch 9.8 added

Problem reproduced.

saxon:capture="yes" on a text node doesn't make much sense, because there's no sub-tree to capture. But of course we shouldn't crash - we should probably ignore it with a warning.

What actually happens is that on a start-element event, if we see that there's a capturing rule for the element, we record information about it on a stack of active captures. When we get to the end-element event, we pull off the captured subtree. What's happening in this case is that we're executing the end-element code without having executed the corresponding start-element code, so we're trying to pop the stack when nothing was pushed onto it.

Actions #2

Updated by Michael Kay 9 months ago

  • Status changed from In Progress to Resolved
  • Applies to branch 12, trunk added
  • Platforms .NET added

I'm changing the code so that capture="yes" is ignored unless the node in question is an element node.

For document nodes, capturing the content is pointless because it destroys the whole point of streaming.

For leaf nodes (text nodes etc) capturing the content is pointless because the content is all accessible anyway.

Actions #3

Updated by O'Neil Delpratt 4 months ago

  • % Done changed from 0 to 100
  • Fix Committed on Branch 12, trunk added
  • Fix Committed on Branch deleted (9.8)
Actions #4

Updated by O'Neil Delpratt 4 months ago

  • Status changed from Resolved to Closed
  • 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