Search code examples
javamultithreadingnullpointerexceptionjasper-reportspdf-generation

Getting NullPointerException whit JasperReports into a Multi-Thread application


I'm getting this error when i try to use JasperReports in a multi-thread way.

java.lang.NullPointerException
 at java.awt.color.ICC_Profile.activateDeferredProfile(ICC_Profile.java:1086) ~[?:1.7.0_80]
 at java.awt.color.ICC_Profile$1.activate(ICC_Profile.java:742) ~[?:1.7.0_80]
 at sun.java2d.cmm.ProfileDeferralMgr.activateProfiles(ProfileDeferralMgr.java:95) ~[?:1.7.0_80]
 at java.awt.color.ICC_Profile.getInstance(ICC_Profile.java:775) ~[?:1.7.0_80]
 at com.lowagie.text.Jpeg.processParameters(Unknown Source) ~[redoute-vendororderlifecycle-batch-deliverynotecrt-96.0.jar:96.0.0]
 at com.lowagie.text.Jpeg.<init>(Unknown Source) ~[redoute-vendororderlifecycle-batch-deliverynotecrt-96.0.jar:96.0.0]
 at com.lowagie.text.Image.getInstance(Unknown Source) ~[redoute-vendororderlifecycle-batch-deliverynotecrt-96.0.jar:96.0.0]
 at net.sf.jasperreports.engine.export.JRPdfExporter$InternalImageProcessor.processImageRetainShape(JRPdfExporter.java:1742)

This is a bug in Java since 1.6

Loading ICC color profiles from multiple threads sometimes triggers a null pointer exception inside the JRE's ICC_Profile class.

At this time i resolve it by calling JasperReports Export to PDF function into a Syncronized function but it's like a bottleneck in a multi-thread application.

@fabiofdsantos say on GitHub this:

"Since jasperreports is using Lowagie (deprecated since 2012), a possible workaround is to call Image.getInstance(renderer.getData(jasperReportsContext)); synchronized."

But I have no idea how to do it whit JasperReports and in the same way he use a syncronized method at the end, but maybe is a better solution than mine.


Solution

  • I figure out this issue by reemplacing all JPEG image into my project that were used by jasper files. I used PNG image instead of JPEG. Even i haven´t needed use a syncronized method.