Bug #6624
openNullPointerException with Saxon EE 12.5 when chaining stylesheets with streamed processing
0%
Description
Code like
package org.example;
import net.sf.saxon.s9api.*;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
public class Main {
public static void main(String[] args) throws SaxonApiException {
Processor processor = new Processor(true);
XsltCompiler xsltCompiler = processor.newXsltCompiler();
XsltExecutable xsltExecutable1 = xsltCompiler.compile(new File("identity-transformation.xsl"));
Xslt30Transformer xslt30Transformer1 = xsltExecutable1.load30();
XsltExecutable xsltExecutable2 = xsltCompiler.compile(new File("identity-transformation.xsl"));
Xslt30Transformer xslt30Transformer2 = xsltExecutable2.load30();
xslt30Transformer1.applyTemplates(
new StreamSource(new File("sample1.xml")),
xslt30Transformer2.asDocumentDestination(xslt30Transformer2.newSerializer(new File("result1.xml")))
);
}
}
throws a NullPointerException with Saxon Java EE 12.5 and streaming:
Exception in thread "main" java.lang.NullPointerException
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:118)
at net.sf.saxon.serialize.XMLEmitter.close(XMLEmitter.java:396)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.SequenceNormalizer.close(SequenceNormalizer.java:160)
at net.sf.saxon.serialize.UncommittedSerializer.close(UncommittedSerializer.java:70)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.CloseNotifier.close(CloseNotifier.java:36)
at net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:735)
at net.sf.saxon.trans.XsltController$1.close(XsltController.java:1055)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.SequenceNormalizer.close(SequenceNormalizer.java:160)
at net.sf.saxon.s9api.Xslt30Transformer$1.close(Xslt30Transformer.java:695)
at net.sf.saxon.s9api.DestinationHelper.closeAndNotify(DestinationHelper.java:49)
at net.sf.saxon.s9api.AbstractDestination.closeAndNotify(AbstractDestination.java:72)
at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:307)
at org.example.Main.main(Main.java:23)
The result file is created, however.
Files
Updated by Michael Kay 4 days ago
I haven't been able to reproduce this (so far).
Related: https://stackoverflow.com/questions/79093208/do-i-need-to-flush-an-outputstream-before-closing-it
The NPE is because we are flushing a stream that has (apparently) already been closed. We could probably turn that into a NO_OP, or perhaps an IOException.
Updated by Martin Honnen 4 days ago
I can easily reproduce it still on Windows with the 12.5 EE release:
PS C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\streamed-chaining> & 'C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot\bin\java.exe' -cp 'C:\Program Files\Saxonica\SaxonEE12-5J\saxon-ee-12.5.jar;.' NullPointerExceptionChainedStreaming
Exception in thread "main" java.lang.NullPointerException
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:118)
at net.sf.saxon.serialize.XMLEmitter.close(XMLEmitter.java:396)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.SequenceNormalizer.close(SequenceNormalizer.java:160)
at net.sf.saxon.serialize.UncommittedSerializer.close(UncommittedSerializer.java:70)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.CloseNotifier.close(CloseNotifier.java:36)
at net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:735)
at net.sf.saxon.trans.XsltController$1.close(XsltController.java:1055)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.SequenceNormalizer.close(SequenceNormalizer.java:160)
at net.sf.saxon.s9api.Xslt30Transformer$1.close(Xslt30Transformer.java:695)
at net.sf.saxon.s9api.DestinationHelper.closeAndNotify(DestinationHelper.java:49)
at net.sf.saxon.s9api.AbstractDestination.closeAndNotify(AbstractDestination.java:72)
at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:307)
at NullPointerExceptionChainedStreaming.main(NullPointerExceptionChainedStreaming.java:21)
I haven't tried other platforms so far.
Updated by Martin Honnen 4 days ago
On the same Windows machine, but run with Java 11 from WSL Linux I also get the exception:
java -cp '/mnt/c/Program Files/Saxonica/SaxonEE12-5J/saxon-ee-12.5.jar:.' NullPointerExceptionChainedStreaming
Exception in thread "main" java.lang.NullPointerException
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:118)
at net.sf.saxon.serialize.XMLEmitter.close(XMLEmitter.java:396)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.SequenceNormalizer.close(SequenceNormalizer.java:160)
at net.sf.saxon.serialize.UncommittedSerializer.close(UncommittedSerializer.java:70)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.CloseNotifier.close(CloseNotifier.java:36)
at net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:735)
at net.sf.saxon.trans.XsltController$1.close(XsltController.java:1055)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.SequenceNormalizer.close(SequenceNormalizer.java:160)
at net.sf.saxon.s9api.Xslt30Transformer$1.close(Xslt30Transformer.java:695)
at net.sf.saxon.s9api.DestinationHelper.closeAndNotify(DestinationHelper.java:49)
at net.sf.saxon.s9api.AbstractDestination.closeAndNotify(AbstractDestination.java:72)
at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:307)
at NullPointerExceptionChainedStreaming.main(NullPointerExceptionChainedStreaming.java:21)
Updated by Martin Honnen 4 days ago
I get the exception as well with the Saxon EE 12.5 release on an M3 Mac so I guess, Mike, you have not been trying to reproduce it with the latest release but with some development version.
martin@MacBook-Pro-von-Martin streamed-chaining % java -cp ~/Saxonica/SaxonEE12-5J/saxon-ee-12.5.jar:. NullPointerExceptionChainedStreaming
Exception in thread "main" java.lang.NullPointerException
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:118)
at net.sf.saxon.serialize.XMLEmitter.close(XMLEmitter.java:396)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.SequenceNormalizer.close(SequenceNormalizer.java:160)
at net.sf.saxon.serialize.UncommittedSerializer.close(UncommittedSerializer.java:70)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.CloseNotifier.close(CloseNotifier.java:36)
at net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:735)
at net.sf.saxon.trans.XsltController$1.close(XsltController.java:1055)
at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:104)
at net.sf.saxon.event.SequenceNormalizer.close(SequenceNormalizer.java:160)
at net.sf.saxon.s9api.Xslt30Transformer$1.close(Xslt30Transformer.java:695)
at net.sf.saxon.s9api.DestinationHelper.closeAndNotify(DestinationHelper.java:49)
at net.sf.saxon.s9api.AbstractDestination.closeAndNotify(AbstractDestination.java:72)
at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:307)
at NullPointerExceptionChainedStreaming.main(NullPointerExceptionChainedStreaming.java:21)
Please register to edit this issue