Project

Profile

Help

Bug #4121

closed

UnsupportedOperationException when writing to DOMResult

Added by Gunther Rademacher over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
JAXP Java API
Sprint/Milestone:
-
Start date:
2019-01-29
Due date:
% Done:

100%

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

Description

A transformer with a DOMResult may fail with an UnsupportedOperationException.

The attached test works OK with Saxon-HE 9.8, but fails with 9.9.0.1 and 9.9.1.1.

The actual exception is:

java.lang.UnsupportedOperationException
	at net.sf.saxon.event.Receiver.append(Receiver.java:232)
	at net.sf.saxon.event.RegularSequenceChecker.append(RegularSequenceChecker.java:153)
	at net.sf.saxon.event.ProxyReceiver.append(ProxyReceiver.java:234)
	at net.sf.saxon.event.ComplexContentOutputter.append(ComplexContentOutputter.java:611)
	at net.sf.saxon.expr.Expression.lambda$process$0(Expression.java:941)
	at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:128)
	at net.sf.saxon.expr.Expression.process(Expression.java:941)
	at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:354)
	at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:519)
	at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:733)
	at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:347)
	at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:338)
	at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:71)
	at TestResults.testDomResult(TestResults.java:68)

Files

TestResults.java (2.74 KB) TestResults.java Gunther Rademacher, 2019-01-29 23:48
Actions #1

Updated by Michael Kay over 3 years ago

  • Status changed from New to In Progress
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal

There were substantial changes in 9.9 to the interface between the Transformer and the Destination, prompted by the need to implement "sequence normalization" on the destination side (the main driver here was the introduction of the JSON and Adaptive output methods). The destination is now expected to handle any "regular sequence" which may include composed nodes as well as decomposed events, and it seems that the DomDestination is not doing this; it should insert a SequenceNormalizer into the pipeline but this is not happening, and as a result if composed nodes are sent across the interface they are rejected.

Incidentally it seems that we do have a RegularSequenceChecker in the pipeline in 9.9.1.1 as issued. The idea was that this would only be included when needed for debugging, but it probably does no harm. Its sole function is to verify that the protocol between transformer and destination is being properly adhered to.

Actions #2

Updated by Michael Kay over 3 years ago

In DOMDestination.getReceiver(), changing

return domWriter;

to

return params.makeSequenceNormalizer(domWriter);

makes the test pass. Need to regression test. JUnit test case added as DomTest.testBug4121().

Actions #3

Updated by Michael Kay over 3 years ago

  • Category set to JAXP Java API
  • Status changed from In Progress to Resolved
  • Applies to branch trunk added
  • Fix Committed on Branch 9.9, trunk added
Actions #4

Updated by Gunther Rademacher over 3 years ago

Thank you for fixing this so quickly! It works fine now.

Actions #5

Updated by Emanuel Wlaschitz over 3 years ago

Just to let you know, we ran into the same issue on Saxon-HE 9.9.1.1N (.NET), with a very similar stack trace. With the snippet posted above, we can work around this using

public class TextWriterDestination2 : TextWriterDestination
{
    public TextWriterDestination2(XmlWriter writer) : base(writer)
    {
    }

    public override Receiver getReceiver(PipelineConfiguration pipe, SerializationProperties value2)
    {
        return value2.makeSequenceNormalizer(base.getReceiver(pipe, value2));
    }
}

instead of using the built-in TextWriterDestination when serializing into a XmlWriter (such as one returned by XDocument.CreateWriter())

Actions #6

Updated by Michael Kay over 3 years ago

I've raised the new problem as bug #4166.

Actions #7

Updated by O'Neil Delpratt over 3 years ago

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

Bug issue fixed in the Saxon 9.9.1.2 maintenance release.

Please register to edit this issue

Also available in: Atom PDF