Project

Profile

Help

Bug #6624

open

NullPointerException with Saxon EE 12.5 when chaining stylesheets with streamed processing

Added by Martin Honnen 15 days ago. Updated 4 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Streaming
Sprint/Milestone:
Start date:
2025-01-06
Due date:
% Done:

0%

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

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

identity-transformation.xsl (601 Bytes) identity-transformation.xsl Martin Honnen, 2025-01-06 09:27
sample1.xml (59 Bytes) sample1.xml Martin Honnen, 2025-01-06 09:27
Actions #1

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.

Actions #2

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.

Actions #3

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)
Actions #4

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

Also available in: Atom PDF