JDK-7022041 : TitleBorder Null Pointer Exception
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux,windows_xp,windows_7
  • CPU: x86
  • Submitted: 2011-02-24
  • Updated: 2013-09-16
  • Resolved: 2012-07-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b49Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b130)
Java HotSpot(TM) Client VM (build 21.0-b02, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP Proffesional 2002 Service pack 3

A DESCRIPTION OF THE PROBLEM :
The following code snipped compiles and run perfectly under JDK 1.6.24
Under JDK 1.7.0-ea it issues a Null Pointer Exception at setTitleFont line


TitledBorder title;
BorderFactory.createTitledBorder(BorderFactory.createRaisedBevelBorder(), "test");
title.setTitleJustification(TitledBorder.LEFT);
title.setTitleFont(title.getTitleFont().deriveFont(Font.BOLD));



REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
By the moment, not found any.

Comments
EVALUATION http://hg.openjdk.java.net/hsx/hotspot-comp/jdk/rev/4d750ca79fb7
14-08-2012

EVALUATION Javadoc for TitledBorder says: * If the border, font, or color property values are not * specified in the constuctor or by invoking the appropriate * set methods, the property values will be defined by the current * look and feel, using the following property names in the * Defaults Table: * <ul> * <li>&quot;TitledBorder.border&quot; * <li>&quot;TitledBorder.font&quot; * <li>&quot;TitledBorder.titleColor&quot; * </ul> Therefore we should initialize that properties as described.
27-04-2012

EVALUATION It is not a bug, because the method does not declare that it always returns non-null value. It depends on used L&F. Before the 4129681 fix some L&Fs returned non-null value, but such behaviour contradicts the JavaBeans specification and a titled border could not be correctly stored using the long-term persistence as specified.
19-04-2011

WORK AROUND User could use the following workaround: Font font = UIManager.getDefaults().getFont("TitledBorder.font"); But he should check that the font is not null.
19-04-2011

EVALUATION Here is the test which shows that title.getFont() returns null import javax.swing.*; import javax.swing.border.TitledBorder; import java.awt.Font; public class b7022041 extends JFrame { public static void main(String... args) throws Exception { SwingUtilities.invokeLater(new Runnable() { public void run() { TitledBorder title = BorderFactory.createTitledBorder(BorderFactory.createRaisedBevelBorder(), "test"); title.setTitleJustification(TitledBorder.LEFT); Font font = title.getTitleFont(); System.out.println("font = " + font); title.setTitleFont(font.deriveFont(Font.BOLD)); } }); } }
19-04-2011