Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8041489

java.awt.Font.createFont0(...) hides cause when handling exceptions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 7u45, 9
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux developer-virtual-machine 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      java.awt.Font, lines 988-999 contains:
              } catch (Throwable t) {
                  (...)
                  throw new IOException("Problem reading font data.");
              }

      throw new IOException(...) omits the root cause. The line should have been:
                  throw new IOException("Problem reading font data.", t);

      We discovered this when we used jasper reports to generate pdf reports. We got this stacktrace in our logs:
      Caused by: java.io.IOException: Problem reading font data.
      at java.awt.Font.createFont0(Font.java:999) ~[na:1.7.0_45]
      at java.awt.Font.createFont(Font.java:876) ~[na:1.7.0_45]
      at net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>(SimpleFontFace.java:101) ~[jasperreports-4.7.0.jar:4.7.0]

      This hid the fact that the underlying exception was a FileNotFound exception wrapped inside an internal jasper exception. After patching java.awt.Font, it was trivial to see that the directory we should write the pdf file to was missing. Before patching java.awt.Font we really had no clue.

      The correct behaviour should be to always wrap the root cause.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      java.io.IOException: Problem reading font data.
      at java.awt.Font.createFont0(Font.java:1003)
      at java.awt.Font.createFont(Font.java:880)
      at AwtFontTest.createFont(AwtFontTest.java:16)
      at AwtFontTest.main(AwtFontTest.java:9)
      Caused by: java.lang.NullPointerException: Something really bad and secret happened
      at AwtFontTest$MyInputStream.read(AwtFontTest.java:26)
      at java.awt.Font.createFont0(Font.java:939)
      ... 3 more

      ACTUAL -
      java.io.IOException: Problem reading font data.
      at java.awt.Font.createFont0(Font.java:999)
      at java.awt.Font.createFont(Font.java:876)
      at AwtFontTest.createFont(AwtFontTest.java:16)
      at AwtFontTest.main(AwtFontTest.java:9)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Font;
      import java.io.ByteArrayInputStream;

      public class AwtFontTest {

      public static void main(String[] args) {
      try {
      createFont();
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      private static void createFont() throws Exception {
      Font.createFont(Font.TRUETYPE_FONT, new MyInputStream(new byte[0]));
      }

      private static class MyInputStream extends ByteArrayInputStream {

      public MyInputStream(byte[] buf) {
      super(buf);
      }

      public int read(byte[] buf) {
      throw new NullPointerException("Something really bad and secret happened");
      }
      }
      }

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                prr Philip Race
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: