fop-pdf-images PreloaderPDF NullPointerException

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

fop-pdf-images PreloaderPDF NullPointerException

Matt Kynaston
Hi,

I am embedding fop-1.1 and fop-pdf-images-2.1.0 in a tomcat servlet and I'm experiencing a NullPointerException in PreloaderPDF.loadPDF(..). The servlet is pretty much exactly the example servlet from the fop source, tweaked to handle posting FO documents.

The problem seems similar to the one discussed down towards the bottom of http://apache-fop.1065347.n5.nabble.com/Fop-1-1-fop-pdf-images-PDFBox-1-8-3-4-td39965.html. This suggests the problem is with the FopFactory being shared between threads.

However, my problem only surfaces after the server has been running for a while - it works during testing one day and next morning throws the error consistently. I haven't managed to create a set of steps to reproduce the problem on demand.

I'm no expert, so sorry if I'm being a bit dense... but the solution would be to create a new FopFactory for every request? That seems to defeat the purpose of the factory a bit. Is there any other workaround?

Environment: I'm seeing this both on OSX, Java 1.7.0_25-b15 / Tomcat 7.0.54 and CentOS6, Java 1.6.0_30 / Tomcat 6.0.24. 

Stack trace:
java.lang.NullPointerException
	org.apache.fop.render.pdf.pdfbox.PreloaderPDF.loadPDF(PreloaderPDF.java:117)
	org.apache.fop.render.pdf.pdfbox.PreloaderPDF.preloadImage(PreloaderPDF.java:83)
	org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:175)
	org.apache.xmlgraphics.image.loader.cache.ImageCache.needImageInfo(ImageCache.java:128)
	org.apache.xmlgraphics.image.loader.ImageManager.getImageInfo(ImageManager.java:122)
	org.apache.fop.fo.flow.ExternalGraphic.bind(ExternalGraphic.java:81)
	org.apache.fop.fo.FObj.processNode(FObj.java:124)
	org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:280)
	org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:175)
	org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1020)
	com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
	com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
	com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:353)
	com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2717)
	com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
	com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
	com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
	com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
	com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
	com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
	com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
	org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:432)
	com.claritum.fop.Servlet.render(Servlet.java:315)
	com.claritum.fop.Servlet.renderFOString(Servlet.java:254)
	com.claritum.fop.Servlet.doPost(Servlet.java:149)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Many thanks for any hints you can give.

Matt



Reply | Threaded
Open this post in threaded view
|

Re: fop-pdf-images PreloaderPDF NullPointerException

Matt Kynaston
Argh... my stoopid mistake.

The servlet is a maven project, and when I bumped the fop-pdf-images version I bumped the pdfbox dependency all the way up to 1.8.5. It took digging through the source to discover that PDDocument.close() now sets everything to null - the cause of the NPE.

Rebuilt with version 1.3.1 and am testing.

BTW, having a POM file in with the binary distro would be very handy for idiots like me ;)

Matt



On 26 June 2014 13:36, Matt Kynaston <[hidden email]> wrote:
Hi,

I am embedding fop-1.1 and fop-pdf-images-2.1.0 in a tomcat servlet and I'm experiencing a NullPointerException in PreloaderPDF.loadPDF(..). The servlet is pretty much exactly the example servlet from the fop source, tweaked to handle posting FO documents.

The problem seems similar to the one discussed down towards the bottom of http://apache-fop.1065347.n5.nabble.com/Fop-1-1-fop-pdf-images-PDFBox-1-8-3-4-td39965.html. This suggests the problem is with the FopFactory being shared between threads.

However, my problem only surfaces after the server has been running for a while - it works during testing one day and next morning throws the error consistently. I haven't managed to create a set of steps to reproduce the problem on demand.

I'm no expert, so sorry if I'm being a bit dense... but the solution would be to create a new FopFactory for every request? That seems to defeat the purpose of the factory a bit. Is there any other workaround?

Environment: I'm seeing this both on OSX, Java 1.7.0_25-b15 / Tomcat 7.0.54 and CentOS6, Java 1.6.0_30 / Tomcat 6.0.24. 

Stack trace:
java.lang.NullPointerException
	org.apache.fop.render.pdf.pdfbox.PreloaderPDF.loadPDF(PreloaderPDF.java:117)
	org.apache.fop.render.pdf.pdfbox.PreloaderPDF.preloadImage(PreloaderPDF.java:83)
	org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:175)
	org.apache.xmlgraphics.image.loader.cache.ImageCache.needImageInfo(ImageCache.java:128)
	org.apache.xmlgraphics.image.loader.ImageManager.getImageInfo(ImageManager.java:122)
	org.apache.fop.fo.flow.ExternalGraphic.bind(ExternalGraphic.java:81)
	org.apache.fop.fo.FObj.processNode(FObj.java:124)
	org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:280)
	org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:175)
	org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1020)
	com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
	com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
	com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:353)
	com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2717)
	com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
	com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
	com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
	com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
	com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
	com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
	com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
	org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:432)
	com.claritum.fop.Servlet.render(Servlet.java:315)
	com.claritum.fop.Servlet.renderFOString(Servlet.java:254)
	com.claritum.fop.Servlet.doPost(Servlet.java:149)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Many thanks for any hints you can give.

Matt