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

SunGraphics2D constructor doesn't check if the font is null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.4.0
    • client-libs
    • None
    • 2d
    • beta2
    • generic
    • generic

      The constructor of SunGraphics2D doesn't check if passed font is null
      and calls checkFontInfo where the font is being accessed, which
      could lead to NPE.

      Here is a test case to reproduce the problem:
      import java.awt.*;

      public class Test extends Frame {
          public Test() {
              pack();
              setFont(null);
              Component c = new Component() {};
              c.setFont(null);
              add(c);
              Image im = c.createImage(10, 10);
              Graphics g = im.getGraphics();
          }
          public static void main(String argv[]) {
              new Test();
          }
      }

      The exception being thrown (on merlin beta_refresh b68):
      Exception in thread "main" java.lang.NullPointerException
              at sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:578)
              at sun.java2d.SunGraphics2D.<init>(SunGraphics2D.java:229)
              at sun.awt.image.OffScreenImage.createGraphics(OffScreenImage.java:81)
              at sun.awt.image.OffScreenImage.initBackground(OffScreenImage.java:102)
              at sun.awt.image.OffScreenImage.<init>(OffScreenImage.java:70)
              at sun.awt.image.AcceleratedOffScreenImage.<init>(AcceleratedOffScreenImage.java:68)
              at sun.awt.motif.X11OffScreenImage.<init>(X11OffScreenImage.java:50)
              at sun.awt.motif.X11OffScreenImage.<init>(X11OffScreenImage.java:44)
              at sun.awt.motif.MComponentPeer.createImage(MComponentPeer.java:390)
              at java.awt.Component.createImage(Component.java:2573)
              at java.awt.Component.createImage(Component.java:2570)
              at Test.<init>(Test.java:10)
              at Test.main(Test.java:14)

      dmitri.trembovetski@eng 2001-06-19

            tdv Dmitri Trembovetski (Inactive)
            tdv Dmitri Trembovetski (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: