[#3005] - IOException: Problem reading font data.

Bug report
Project: Severity:
Component: Reproducibility:
Assigned to:

JDK 6_45 contains an unresolved problem. Sometimes (on some, not all servers, confirmed at Windows systems) when calling java.awt.Font.createFont(int, InputStream) (inputStream = i.e. file "net/sf/jasperreports/fonts/dejavu/DejaVuSans.ttf") the font is not properly loaded with exception

java.io.IOException: Problem reading font data.
at java.awt.Font.createFont(Font.java:924)

i.e. net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>(SimpleFontFace.java:100) throws JRRuntimeException: java.io.IOException: Problem reading font data.

Possible solution (not tested yet, but adviced at http://www.martianstorm.com/wordpress/?p=103): Save the input stream in temporary file on disk and use method java.awt.Font.createFont(int, File fontFile) instead.

lukas.mojzis's picture
Joined: Jun 20 2013 - 4:04am
Last seen: 6 years 10 months ago


  • Assigned:nobody»

I used the solution described above. In net.sf.jasperreports.engine.fonts.SimpleFontFace.SimpleFontFace(JasperReportsContext, String) i replaced Font.createFont with this snippet of code:

File tempFile = new File(System.getProperty("java.io.tmpdir") + "/" + RandomStringUtils.randomAlphanumeric(15) + ".tmp");
FileUtils.copyInputStreamToFile(is, tempFile);
font = Font.createFont(Font.TRUETYPE_FONT, tempFile);

It is important to note that you should not delete the temporary file, because on linux system it is used later when reading glyphs from font. Maybe a shutdown hook to delete tmp file will be a good thing to do, but one can live with an undeleted file in temp dir.

  • Assigned:» anonymous

We've also seen an error that looks very much like this one:

Three different implementations (for various internal organizations) of an application running on:
* Java 7 (J2SE 1.7.0_40-b43)
* RedHat Enterprise Linux (One system running RHEL 6.4, two systems RHEL 5.9)
* RESTful (using RESTEasy) Java application running in Apache Tomcat (6.0.33), with application code calling JasperReports Library version 5.0.1 (note earlier than 5.1 as per this bug report) of the JasperReports Library. (We likely will be upgrading to 5.2 at some point, while pointing out that we haven't yet found any change notes or other tracked issues between 5.0.1 and 5.2 specifically mentioning this bug.)

* At intermittent intervals during production operations, typically some weeks apart across these three systems (although sometimes encountered in clusters more frequently) we encounter this Exception:
org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser will occur
* The cause is nearly always:

Caused by: java.io.IOException: Problem reading font data.
at java.awt.Font.createFont0(Font.java:999)
at java.awt.Font.createFont(Font.java:876)
at net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>(SimpleFontFace.java:100)

Prior to the log statement for the Exception above, another error or Exception is typically logged, always with this cause:

java.io.IOException: Problem reading font data.
at net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>

Other notes of potential relevance:

Running different reports may trigger this issue, from time to time.

This occurs on systems where that same report has been invoked successfully many times before, and, after our application has been restarted, can once again be invoked many times thereafter, without incident.

We've verified with log statements that, when this Exception occurs, the Java temporary directory (Tomcat's 'temp' directory) exists and is writeable by the application process's user.

In general, the reports that trigger this error are all solely using Java logical fonts, such as Serif, SansSerif, Monospaced, rather than TrueType fonts specified via the font extension mechanism.

The relevant JasperReports Library code for which lukas.mojzis (and the original poster of the cited blog post) appears to have provided a suggested workaround is listed here (for v5.0.1):


@ lukas.mojzis
Could you please tell how you replaced SimpleFontFace.class with your code snippet?



In 5.6.0 line 174. Replaced

font = Font.createFont(Font.TRUETYPE_FONT, is);


File tempFile = createTempFile("JASPER_BUGFIX", randomAlphanumeric(8) + ".tmp");
org.apache.commons.io.FileUtils.copyInputStreamToFile(is, tempFile);
font = Font.createFont(Font.TRUETYPE_FONT, tempFile);

createTempFile - creates temporary file somewhere

  • Priority:Normal» Immediate
  • Assigned:nobody»

We are facing this error in production environment. But not able to replicate it in our test environment. This report has been executed previously many times and recently we started facing this problem sometimes and it get resolved after restarting the server.
Is there any Jasper setting to set this tempfile location, instead of modifying SimpleFontFace.java.
Kindly help me, as this is production incident.
Error log is -
Caused by: java.io.IOException: Problem reading font data.
at java.awt.Font.createFont0(Font.java:999)
at java.awt.Font.createFont(Font.java:876)
at net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>(SimpleFontFace.java:100)
... 30 more

I have attached full log
<strong><<<<<< This comment was blocked and unpublished because <a href="http://www.projecthoneypot.org/">Project Honeypot</a> indicates it came from a suspicious IP address.</strong>

Plain text icon log.txt3.37 KB
  • Reproducibility:Sometimes» Always
  • Resolution:Open» Fixed

I am facing the same issue and root cause in my case is temp folder is removed from tomcat directory
solution is when i created temp folder in tomcat then this issue is resolved.