United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-7022041 : TitleBorder Null Pointer Exception

Details
Type:
Bug
Submit Date:
2011-02-24
Status:
Resolved
Updated Date:
2013-09-16
Project Name:
JDK
Resolved Date:
2012-07-25
Component:
client-libs
OS:
linux,windows_xp,windows_7
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Duplicate:
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

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
                                     
2012-08-14
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.
                                     
2012-04-27
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));
            }
        });
    }
}
                                     
2011-04-19
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.
                                     
2011-04-19
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.
                                     
2011-04-19



Hardware and Software, Engineered to Work Together