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

Null pointer exception is now returned from TitledBorder::getTitleFont()

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version " 1.7.0_09 "
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
      Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      In Java 7 the methods TitledBorder::getTitleFont() and TitledBorder::getTitleColor() has changed and it does not check for a null value anymore as it was done on Java 6.

      In Java 6 the method was like this:
          public Font getTitleFont() {
              Font f = titleFont;
      if (f == null)
          f = UIManager.getFont( " TitledBorder.font " );
              return f;
          }

      But in Java 7 the method is:
          public Font getTitleFont() {
              return titleFont;
          }

      Therefore if code written relying on this, it will crashed with a NullPointerException


      REGRESSION. Last worked in version 7

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A default font should be returned as it happened on Java6
      ACTUAL -
      Null font is returned if one does not specify a font.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      TitledBorder tb = new TitledBorder( " test " );
      Font def = tb.getTitleFont();
      def = def.deriveFont(Font.BOLD);
      tb .setTitleFont(def);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You may inherit from TitledBorder and put Java6's code again.

      SUPPORT :
      YES

            malenkov Sergey Malenkov (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: