I'm running a process on a test environment that takes more than 10 hours to run and generates PDF documents using Jasper Reports v3.7.5.
Quite frequently the process finishes successfully but in some cases the process fails throwing this exception:
20/05/2017 02:45:23.503 ERROR [process-pool-2-thread-20] net.sf.jasperreports.extensions.DefaultExtensionsRegistry - Error instantiating extensions registry for simple.font.families
net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: Problem reading font data.
at net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>(SimpleFontFace.java:77)
at net.sf.jasperreports.engine.fonts.SimpleFontFamily.createFontFace(SimpleFontFamily.java:316)
at net.sf.jasperreports.engine.fonts.SimpleFontFamily.setNormal(SimpleFontFamily.java:85)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamily(SimpleFontExtensionHelper.java:233)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamilies(SimpleFontExtensionHelper.java:204)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:173)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:142)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory.createRegistry(SimpleFontExtensionsRegistryFactory.java:63)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instantiateRegistry(DefaultExtensionsRegistry.java:238)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:213)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:162)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRegistries(DefaultExtensionsRegistry.java:132)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:104)
at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:76)
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:182)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:77)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:87)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:57)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:78)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:605)
...
Caused by: java.io.IOException: Problem reading font data.
at java.awt.Font.createFont0(Font.java:1000)
at java.awt.Font.createFont(Font.java:877)
at net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>(SimpleFontFace.java:69)
... 120 common frames omitted
Soon after, on the same thread, the following error is logged. I'm not sure if it is related, though:
20/05/2017 02:45:23.605 ERROR [process-pool-2-thread-20] my.package.MyClass.NoClassDefFoundError - AbstractReportCreationService.createAndPersistReport(...) threw an error: Could not initialize class sun.awt.X11GraphicsEnvironment
I have tried running this process on Solaris 5.10 and 5.11, using the same Java 1.8.0 version. It occurs randomly on both. I have been trying to reproduce the error in order to find the underlying cause, but to no avail so far.
I've read similar issues reported in StackOverflow and Jaspersoft Community forums. Most of these posts mention possibly permission issues preventing the process from reading from or writing to the java temp directory (java.io.tmpdir = /var/tmp/
). See for example:
The method JasperFillManager.fillReport () throws java.io.Exception
I've checked file permissions and these are correct. When the process runs successfully it creates temporary font files called something like +~JF9070759829719582131.tmp
or similar random names. Even when the process has failed it has left some of these temporary font files in the /var/tmp/
directory, so permissions doesn't seem to be the issue. On top of that, permissions are not changed between successful and failed runs.
On this post to Jaspersoft Community forum:
http://community.jaspersoft.com/questions/543492/javaioioexception-problem-reading-font-data
a proposed solution is to start Tomcat with option
-Djava.awt.headless=true
The process I'm running uses plain Java, not Tomcat, but I'm willing to try the headless mode. Since the problem occurs randomly and takes so long to run, it is going to be hard to prove that this possible solution actually resolves the issue. I'm worried about deploying this to the production environment and getting the same issue there randomly. Can anyone explain why running in headless mode might fix the issue, or what other possible solution should I try, please?