Jump to content
  • IOException: Problem reading font data.


    lukas.mojzis
    CategoryBug report
    PriorityImmediate
    ReproducibilityAlways
    ResolutionFixed
    SeverityCritical
    StatusNew
    Versionv5.1.0

    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.(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.

     



    User Feedback

    Recommended Comments

    Changed Assigned User from - to @User_306070


    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.
    Link to comment
    Share on other sites

    Changed Assigned User from @User_306070 to @anonymous


    We've also seen an error that looks very much like this one:Scenario: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.)Issue:* 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.(SimpleFontFace.java:100)Prior to the log statement for the Exception above, another error or Exception is typically logged, always with this cause: net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: Problem reading font data. at net.sf.jasperreports.engine.fonts.SimpleFontFace.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):http://grepcode.com/file/repo1.maven.org/maven2/net.sf.jasperreports/jasperreports/5.0.1/net/sf/jasperreports/engine/fonts/SimpleFontFace.java?av=f#84
    Link to comment
    Share on other sites

    In 5.6.0 line 174. Replaced

     

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

     

    with

     

    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

     

    Link to comment
    Share on other sites

    Changed Priority from Normal to Immediate

    Changed Assigned User from @teodord to -


    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.(SimpleFontFace.java:100) ... 30 moreI have attached full log <<<<<< This comment was blocked and unpublished because Project Honeypot indicates it came from a suspicious IP address.
    Link to comment
    Share on other sites

    Changed Reproducibility from Sometimes to Always

    Changed Resolution from Open to 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.
    Link to comment
    Share on other sites


×
×
  • Create New...