Project

Profile

Help

Support #3620

closed

NullPointerException at net.sf.saxon.event.XMLEmitter.close()

Added by Tom Boyks almost 7 years ago. Updated almost 7 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2018-01-12
Due date:
% Done:

0%

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

Description

Hello,

my java-application works fine if I start it inside the IDE (eclipse), but if I export it as runnable jar and start this then I get the follwing Stack Trace:

java.lang.NullPointerException
	at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
	at java.io.PrintStream.flush(PrintStream.java:338)
	at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:297)
	at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
	at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
	at net.sf.saxon.event.XMLEmitter.close(XMLEmitter.java:252)
	at net.sf.saxon.event.MessageEmitter.close(MessageEmitter.java:19)
	at net.sf.saxon.event.TreeReceiver.close(TreeReceiver.java:66)
	at net.sf.saxon.instruct.Message.processLeavingTail(Message.java:161)
	at net.sf.saxon.instruct.Template.expand(Template.java:98)
	at net.sf.saxon.instruct.CallTemplate.process(CallTemplate.java:189)
	at net.sf.saxon.instruct.CallTemplate.processLeavingTail(CallTemplate.java:214)
	at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:332)
	at net.sf.saxon.instruct.Template.expand(Template.java:98)
	at net.sf.saxon.instruct.Template.processLeavingTail(Template.java:82)
	at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:297)
	at net.sf.saxon.instruct.ApplyTemplates.apply(ApplyTemplates.java:169)
	at net.sf.saxon.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:133)
	at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:332)
	at net.sf.saxon.instruct.Instruction.process(Instruction.java:91)
	at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:164)
	at net.sf.saxon.instruct.Template.expand(Template.java:98)
	at net.sf.saxon.instruct.Template.processLeavingTail(Template.java:82)
	at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:297)
	at net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTemplates.java:329)
	at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:291)
	at net.sf.saxon.Controller.transformDocument(Controller.java:1513)
	at net.sf.saxon.Controller.transform(Controller.java:1346)

I tried it with different versions of saxon from maven (saxon version 9 an 8.7, Saxon-B version 9 and Saxon-HE 9.8.0-7) and got always the same effect.

My last workaround fixed the problem: I wrote an own XMLEmitter class:

public class MySaxonEmitter extends net.sf.saxon.event.XMLEmitter {
	@Override
	public void close() throws net.sf.saxon.trans.XPathException {
		try {
			System.out.println("MySaxonEmitter.close() called");
			OutputStream os = getOutputStream();
			if( null != os )
				super.close();
		} catch(Exception e) {
			if( e instanceof NullPointerException )
				e.printStackTrace(); // and ignore
			else
				throw e;
		}
	}
}

and changed the configuration of the TransformerFactory:

((net.sf.saxon.TransformerFactoryImpl)factory).getConfiguration().setMessageEmitterClass("MySaxonEmitter");

I think it's a bug in the XMLEmitter closing a not existing Stream?

Please register to edit this issue

Also available in: Atom PDF