Support #3620
closedNullPointerException at net.sf.saxon.event.XMLEmitter.close()
Added by Tom Boyks almost 7 years ago. Updated almost 7 years ago.
0%
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?
Updated by Michael Kay almost 7 years ago
- Subject changed from NullPointerException at at net.sf.saxon.event.XMLEmitter.close() to NullPointerException at net.sf.saxon.event.XMLEmitter.close()
- Category set to Internals
- Assignee set to Michael Kay
- Priority changed from Low to Normal
Updated by Michael Kay almost 7 years ago
Judging from the class names and line numbers in the stack trace, you have somehow managed to pick up a very old version of Saxon. Perhaps it's even possible that bits of two different versions of Saxon have been loaded, which is always a recipe for disaster.
Try displaying the result of the static method net.sf.saxon.Version.getProductVersion()
to see if this gives you any clues.
Updated by Michael Kay almost 7 years ago
- Status changed from New to AwaitingInfo
Updated by Tom Boyks almost 7 years ago
Ok, these are the outputs using different saxon versions (all from maven, repository central or enonic), running with "C:\Program Files (x86)\Java\jdk1.7.0_80\jre\bin\java.exe". First line is the output of
System.out.println("saxon-Version = " + net.sf.saxon.Version.getProductVersion());
saxon: 8.7
saxon-Version = 8.7
java.lang.NullPointerException
at net.sf.saxon.Controller.transform(Controller.java:1319)
...
saxon: 9.0
saxon-Version = 9.0.0.2
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:262)
at net.sf.saxon.event.MessageEmitter.endDocument(MessageEmitter.java:18)
at net.sf.saxon.event.TreeReceiver.endDocument(TreeReceiver.java:107)
at net.sf.saxon.event.ProxyReceiver.endDocument(ProxyReceiver.java:106)
at net.sf.saxon.instruct.Message.processLeavingTail(Message.java:219)
at net.sf.saxon.instruct.Template.expand(Template.java:192)
at net.sf.saxon.instruct.CallTemplate.process(CallTemplate.java:255)
at net.sf.saxon.instruct.CallTemplate.processLeavingTail(CallTemplate.java:279)
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:399)
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343)
at net.sf.saxon.instruct.ApplyTemplates.apply(ApplyTemplates.java:208)
at net.sf.saxon.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:172)
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:399)
at net.sf.saxon.instruct.Instruction.process(Instruction.java:94)
at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298)
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343)
at net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTemplates.java:376)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:331)
at net.sf.saxon.Controller.transformDocument(Controller.java:1735)
at net.sf.saxon.Controller.transform(Controller.java:1559)
...
saxon: 9.1.0.8
saxon-Version = 9.1.0.8
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:261)
at net.sf.saxon.event.MessageEmitter.endDocument(MessageEmitter.java:18)
at net.sf.saxon.event.TreeReceiver.endDocument(TreeReceiver.java:122)
at net.sf.saxon.event.ProxyReceiver.endDocument(ProxyReceiver.java:106)
at net.sf.saxon.instruct.Message.processLeavingTail(Message.java:219)
at net.sf.saxon.instruct.Template.expand(Template.java:220)
at net.sf.saxon.instruct.CallTemplate.process(CallTemplate.java:257)
at net.sf.saxon.instruct.CallTemplate.processLeavingTail(CallTemplate.java:281)
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:556)
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:203)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:345)
at net.sf.saxon.instruct.ApplyTemplates.apply(ApplyTemplates.java:210)
at net.sf.saxon.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:174)
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:556)
at net.sf.saxon.instruct.Instruction.process(Instruction.java:93)
at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:296)
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:203)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:345)
at net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTemplates.java:378)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:333)
at net.sf.saxon.Controller.transformDocument(Controller.java:1807)
at net.sf.saxon.Controller.transform(Controller.java:1621)
saxon-B: 9.0
saxon-Version = 9.0.0.8
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:262)
at net.sf.saxon.event.MessageEmitter.endDocument(MessageEmitter.java:18)
at net.sf.saxon.event.TreeReceiver.endDocument(TreeReceiver.java:107)
at net.sf.saxon.event.ProxyReceiver.endDocument(ProxyReceiver.java:106)
at net.sf.saxon.instruct.Message.processLeavingTail(Message.java:219)
at net.sf.saxon.instruct.Template.expand(Template.java:192)
at net.sf.saxon.instruct.CallTemplate.process(CallTemplate.java:255)
at net.sf.saxon.instruct.CallTemplate.processLeavingTail(CallTemplate.java:279)
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:409)
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343)
at net.sf.saxon.instruct.ApplyTemplates.apply(ApplyTemplates.java:208)
at net.sf.saxon.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:172)
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:409)
at net.sf.saxon.instruct.Instruction.process(Instruction.java:94)
at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298)
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343)
at net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTemplates.java:376)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:331)
at net.sf.saxon.Controller.transformDocument(Controller.java:1736)
at net.sf.saxon.Controller.transform(Controller.java:1560)
...
This is the content of my MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: . plip2_lib/junit.jar plip2_lib/org.hamcrest.core_1.3.0.v2
01303031735.jar plip2_lib/commons-csv-1.5.jar plip2_lib/iplpreview-2.
0.jar plip2_lib/ojdbc6-11.1.0.7.0-Production.jar plip2_lib/quicktable
-3.0.jar plip2_lib/jniwrapper-3.8.3.jar plip2_lib/winpack-3.8.3.jar p
lip2_lib/comfyj-2.9.jar plip2_lib/slf4j-log4j12-1.5.8.jar plip2_lib/s
lf4j-api-1.5.8.jar plip2_lib/aspose-cells-7.0.0.jar plip2_lib/validat
ion-1.1.1.jar plip2_lib/log4j-1.2.17.jar plip2_lib/jgoodies-forms-1.9
.0.jar plip2_lib/jgoodies-common-1.8.1.jar plip2_lib/jxl-2.6.12.jar p
lip2_lib/xml-apis-ext-1.3.04.jar plip2_lib/xercesImpl-2.11.0.jar plip
2_lib/xml-apis-1.4.01.jar plip2_lib/jgoodies-binding-2.13.0.jar plip2
_lib/commons-configuration-1.10.jar plip2_lib/commons-lang-2.6.jar pl
ip2_lib/commons-logging-1.1.1.jar plip2_lib/xom-1.2.5.jar plip2_lib/x
alan-2.7.0.jar plip2_lib/poi-ooxml-3.17.jar plip2_lib/poi-3.17.jar pl
ip2_lib/commons-codec-1.10.jar plip2_lib/commons-collections4-4.1.jar
plip2_lib/poi-ooxml-schemas-3.17.jar plip2_lib/xmlbeans-2.6.0.jar pl
ip2_lib/stax-api-1.0.1.jar plip2_lib/curvesapi-1.04.jar plip2_lib/gro
ovy-all-2.4.13.jar plip2_lib/jcalendar-1.4.jar plip2_lib/looks-2.2.2.
jar plip2_lib/itext-2.1.7.jar plip2_lib/bcmail-jdk14-138.jar plip2_li
b/bcprov-jdk14-138.jar plip2_lib/bctsp-jdk14-1.38.jar plip2_lib/bcpro
v-jdk14-1.38.jar plip2_lib/bcmail-jdk14-1.38.jar plip2_lib/fop-pdf-im
ages-2.2.jar plip2_lib/fop-2.2.jar plip2_lib/xmlgraphics-commons-2.2.
jar plip2_lib/batik-svg-dom-1.9.jar plip2_lib/batik-css-1.9.jar plip2
_lib/batik-dom-1.9.jar plip2_lib/batik-parser-1.9.jar plip2_lib/batik
-util-1.9.jar plip2_lib/batik-constants-1.9.jar plip2_lib/batik-i18n-
1.9.jar plip2_lib/batik-bridge-1.9.jar plip2_lib/batik-anim-1.9.jar p
lip2_lib/batik-script-1.9.jar plip2_lib/batik-xml-1.9.jar plip2_lib/b
atik-awt-util-1.9.jar plip2_lib/batik-gvt-1.9.jar plip2_lib/batik-tra
nscoder-1.9.jar plip2_lib/batik-svggen-1.9.jar plip2_lib/batik-extens
ion-1.9.jar plip2_lib/batik-ext-1.9.jar plip2_lib/commons-io-1.3.1.ja
r plip2_lib/avalon-framework-api-4.3.1.jar plip2_lib/avalon-framework
-impl-4.3.1.jar plip2_lib/pdfbox-2.0.4.jar plip2_lib/fontbox-2.0.4.ja
r plip2_lib/saxon-9.1.0.8.jar plip2_lib/saxon-dom-9.0.jar
Main-Class: plip2.main.Main
Need you further informations?
Updated by Michael Kay almost 7 years ago
There are known bugs in this area, that were fixed many years ago. See for example
https://saxonica.plan.io/issues/149
https://saxonica.plan.io/issues/2243
Please move forward to a more recent release. We are no longer investigating or fixing bugs in these old releases. Saxon 8.7 was shipped in 2006!
Updated by Tom Boyks almost 7 years ago
This is the output of saxon-HE (Version 9.8.0-7):
Warning at xsl:stylesheet on line 1 column 269 of cmmpreview.xsl:
Unrecognized version 1.1: treated as 1.0
Warning at xsl:stylesheet on line 1 column 360
Unrecognized version 1.1: treated as 1.0
saxon-Version = 9.8.0.7
java.lang.NullPointerException
at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
at java.io.PrintStream.flush(PrintStream.java:338)
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:105)
at net.sf.saxon.serialize.MessageEmitter.close(MessageEmitter.java:61)
at net.sf.saxon.Controller.transform(Controller.java:2001)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:596)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:73)
I think here is the problem that the outputstream used in UTF8Writer.flush() could be null?
Updated by Michael Kay almost 7 years ago
- Status changed from AwaitingInfo to In Progress
OK, if it happens with 9.8 then that's more interesting.
But what exactly is your Java application doing? We need to reproduce the bug before we can fix it.
Updated by Tom Boyks almost 7 years ago
This is difficult. I could not reproduce the problem with an other smaller program and same logic. The error only occurs if I call the "big fat" swing application directly. It not occurs if I start the application inside the IDE (eclipse).
In the main class the system property for the transformer impl. is defined:
System.setProperty("javax.xml.transform.TransformerFactory","net.sf.saxon.TransformerFactoryImpl");
The responsible class reads xml into a DOMObject, transforms this with xsl into a DOMResult and later converts this with apache fop into a PDF:
org.w3c.dom.Document document = builder.parse(new ByteArrayInputStream(...));
Source xmlSource = new DOMSource(document);
TransformerFactory factory = TransformerFactory.newInstance();
// this is my workaround
if (factory instanceof net.sf.saxon.TransformerFactoryImpl && null != saxonMessageEmitter)
((net.sf.saxon.TransformerFactoryImpl) factory).getConfiguration().setMessageEmitterClass(saxonMessageEmitter);
DOMResult result=new DOMResult();
Source xslSource=new StreamSource(new ByteArrayInputStream(...));
Templates template = factory.newTemplates(xslSource);
Transformer xformer = template.newTransformer();
xformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
// here the NullPointerException occurs
xformer.transform(xmlSource, result);
...
The workaround Emitter class for saxon-HE is:
import java.io.OutputStream;
//import net.sf.saxon.event.MessageEmitter; // for saxon-9.0
import net.sf.saxon.serialize.MessageEmitter; // for saxon-HE
import net.sf.saxon.trans.XPathException;
public class MySaxonEmitter extends MessageEmitter {
@Override
public void close() throws 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;
}
}
@Override
public void endDocument() throws XPathException {
try {
System.out.println("MySaxonEmitter.endDocument() called");
super.endDocument();
} catch(Exception e) {
if( e instanceof NullPointerException )
e.printStackTrace(); // and ignore
else
throw e;
}
}
}
This is the output inside IDE:
Warning at xsl:stylesheet on line 1 column 269 of cmmpreview.xsl:
Unrecognized version 1.1: treated as 1.0
Warning at xsl:stylesheet on line 1 column 360
Unrecognized version 1.1: treated as 1.0
MySaxonEmitter.endDocument() called
DEBUG:ENTER:figure:::w7ab1a
MySaxonEmitter.endDocument() called
DEBUG:EXIT:figure:::w7ab1a
MySaxonEmitter.close() called
MySaxonEmitter.close() called
And this is the output if the program works standalone:
Warning at xsl:stylesheet on line 1 column 269 of cmmpreview.xsl:
Unrecognized version 1.1: treated as 1.0
Warning at xsl:stylesheet on line 1 column 360
Unrecognized version 1.1: treated as 1.0
MySaxonEmitter.endDocument() called
DEBUG:ENTER:figure:::w7ab1a
java.lang.NullPointerException
at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
at java.io.PrintStream.flush(PrintStream.java:338)
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:105)
at net.sf.saxon.serialize.MessageEmitter.endDocument(MessageEmitter.java:49)
at plip2.exports.ipl.copy.MySaxonEmitter.endDocument(MySaxonEmitter.java:29)
at net.sf.saxon.event.TreeReceiver.endDocument(TreeReceiver.java:163)
at net.sf.saxon.event.ProxyReceiver.endDocument(ProxyReceiver.java:116)
at net.sf.saxon.expr.instruct.Message.processLeavingTail(Message.java:215)
at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:262)
at net.sf.saxon.expr.instruct.CallTemplate.process(CallTemplate.java:353)
at net.sf.saxon.expr.instruct.CallTemplate.processLeavingTail(CallTemplate.java:411)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:687)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:347)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:295)
at net.sf.saxon.expr.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:252)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:687)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:151)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:337)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:284)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:347)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
at net.sf.saxon.trans.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:69)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:478)
at net.sf.saxon.Controller.transformDocument(Controller.java:2402)
at net.sf.saxon.Controller.transform(Controller.java:1970)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:596)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:73)
...
MySaxonEmitter.endDocument() called
DEBUG:EXIT:figure:::w7ab1a
java.lang.NullPointerException
at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
at java.io.PrintStream.flush(PrintStream.java:338)
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:105)
at net.sf.saxon.serialize.MessageEmitter.endDocument(MessageEmitter.java:49)
at plip2.exports.ipl.copy.MySaxonEmitter.endDocument(MySaxonEmitter.java:29)
at net.sf.saxon.event.TreeReceiver.endDocument(TreeReceiver.java:163)
at net.sf.saxon.event.ProxyReceiver.endDocument(ProxyReceiver.java:116)
at net.sf.saxon.expr.instruct.Message.processLeavingTail(Message.java:215)
at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:262)
at net.sf.saxon.expr.instruct.CallTemplate$CallTemplatePackage.processLeavingTail(CallTemplate.java:518)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:432)
at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:295)
at net.sf.saxon.expr.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:252)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:687)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:151)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:337)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:284)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:347)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:502)
at net.sf.saxon.trans.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:69)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:478)
at net.sf.saxon.Controller.transformDocument(Controller.java:2402)
at net.sf.saxon.Controller.transform(Controller.java:1970)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:596)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:73)
...
MySaxonEmitter.close() called
java.lang.NullPointerException
at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
at java.io.PrintStream.flush(PrintStream.java:338)
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:105)
at net.sf.saxon.serialize.MessageEmitter.close(MessageEmitter.java:61)
at plip2.exports.ipl.copy.MySaxonEmitter.close(MySaxonEmitter.java:16)
at net.sf.saxon.Controller.closeMessageEmitter(Controller.java:2796)
at net.sf.saxon.Controller.transformDocument(Controller.java:2426)
at net.sf.saxon.Controller.transform(Controller.java:1970)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:596)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:73)
...
MySaxonEmitter.close() called
java.lang.NullPointerException
at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
at java.io.PrintStream.flush(PrintStream.java:338)
at net.sf.saxon.serialize.UTF8Writer.flush(UTF8Writer.java:105)
at net.sf.saxon.serialize.MessageEmitter.close(MessageEmitter.java:61)
at plip2.exports.ipl.copy.MySaxonEmitter.close(MySaxonEmitter.java:16)
at net.sf.saxon.Controller.transform(Controller.java:2001)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:596)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:73)
...
The program will always started with jre 1.7 ("C:\Program Files (x86)\Java\jdk1.7.0_80\jre\bin\java.exe"). For classpath see above. Using the workaround always the expected PDF is produced.
Updated by Michael Kay almost 7 years ago
- Tracker changed from Bug to Support
- Status changed from In Progress to Resolved
This one is tough because without a repro we can't see exactly why it's failing, and more particularly, we can't be sure that any change fixes the problem.
I have reproduced the NPE with the following code (where IDENTITY_STYLESHEET is a stylesheet that outputs no messages):
SAXTransformerFactory tFactory = new ProfessionalTransformerFactory();
Source src = new StreamSource(new StringReader("<test/>"));
Templates templates = tFactory.newTemplates(new StreamSource(new StringReader(IDENTITY_STYLESHEET)));
Transformer transformer = templates.newTransformer();
MessageEmitter mw = new MessageEmitter();
mw.setWriter(new PrintWriter(new FilterOutputStream(null))); // "null" is clearly inappropriate here, but causes no failure
((TransformerImpl) transformer).getUnderlyingXsltTransformer().getUnderlyingController().setMessageEmitter(mw);
transformer.transform(src, new StreamResult(System.out));
Now, this code is clearly incorrect: creating a FilterOutputStream with no underlying stream for it to filter makes no sense.
If I change the stylesheet so it actually outputs a message, the attempt to write to the PrintWriter appears to succeed (the content being written is simply buffered) and the NPE again occurs when the buffer contents are flushed during the close() call.
I don't think it would be appropriate for Saxon to catch the NullPointerException because the NPE indicates something is wrong, something that will cause the message not to be written. We shouldn't mask this error.
So, in the absence of evidence to the contrary, my conclusion is that this is a user error in the way that the Writer for messages was set up, and that Saxon is behaving correctly. Therefore I'm reclassifying the issue from Bug to Support and closing it as Resolved.
Please feel free to re-open if further evidence emerges.
Updated by Tom Boyks almost 7 years ago
Ok, I understand my workaround is not a really good workaround. But without the workaround I get the NPE nethertheless (see Note-6 in this Call). In this case I did'nt use an own MessageEmitter and therefore not an own Writer.
Updated by Michael Kay almost 7 years ago
Sorry, but there's nothing more we can do unless you can produce a repro.
Updated by Michael Kay almost 7 years ago
Capturing some more of my notes from the analysis in case they are needed again:
(a) if no messages are output by the stylesheet, then at the end of the transformation messageEmitter.close() is called. In the case of the standard (default) message listener, this tests whether there is a Writer. If there is, it calls writer.close(), if not, it does nothing. It is clear that in the stack trace provided, there is a non-null writer, so writer.close() is called, and the writer is throwing an NPE when this happens.
(b) if one or more messages is output, then Controller.openMessageEmitter() initializes the message emitter with a Result destination obtained using getConfiguration().getLogger().asStreamResult(). By default this is a StreamResult wrapping a writer to System.err. Perhaps in the failure case, getLogger() is returning something non-standard as the destination. The message is written to this destination, and on completion of the transformation, messageEmitter.close() is called as before.
Please register to edit this issue