JDK-7117283 : NullpointerException when using TitleBorder.getTitleFont
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-12-02
  • Updated: 2012-03-30
  • Resolved: 2012-03-30
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
8Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Windows 7 sp1

EXTRA RELEVANT SYSTEM CONFIGURATION :
Java 7

A DESCRIPTION OF THE PROBLEM :
I'm migrating a swing application from Windows XP to Windows 7 and also from Java 6 to Java 7. The swing application sometimes makes the font bold to indicate that it is a mandatory value. The same piece of code works well in Windows XP and causes a NullpointerException in Windows 7.

REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this code on Windows XP and compare result with Windows 7.

	    public static void main(String[] args) {
	    	Font font = new TitledBorder("").getTitleFont();
	        Font test = getMandatoryFont(font);
	    }

	    public static Font getMandatoryFont(Font font) {
	        Font mandatory = font.deriveFont(Font.BOLD);
	        return mandatory;
	    }

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The font is changed to bold
ACTUAL -
In Windows XP (java7) the code works fine
In Windows 7 (java 7) there is a NullPointerException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
NullpointerException

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
	    public static void main(String[] args) {
	    	Font font = new TitledBorder("").getTitleFont();
	        Font test = getMandatoryFont(font);
	    }

	    public static Font getMandatoryFont(Font font) {
	        Font mandatory = font.deriveFont(Font.BOLD);
	        return mandatory;
	    }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Handle null in getMandatoryFont