JDK-6428968 : NullPointerException in WindowsTableHeaderUI with alternative Windows XP themes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-05-22
  • Updated: 2010-04-02
  • Resolved: 2006-08-18
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 6
6 b96Fixed
Description
FULL PRODUCT VERSION :
java version "1.6.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta-b59g)
Java HotSpot(TM) Client VM (build 1.6.0-beta-b59g, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Must have Windows Plus! themes installed. (Or other theming software.)

A DESCRIPTION OF THE PROBLEM :
Running an Swing application on Microsoft Windows XP (and using the XP look and feel), with an alternate "theme" installed, produces an exception when displaying a JTable.

  See also these various reports of the problem using Java applications:

http://forum.java.sun.com/thread.jspa?threadID=667836&tstart=0
http://idendev.com/SCRIPTS/WA-motorola.EXE?A2=ind0507&L=sdklist&T=0&P=8587
http://tamino.forums.softwareag.com/viewtopic.php?p=16756&
http://jalbum.net/forum/thread.jspa?threadID=1475&messageID=8836

http://www.google.com/search?q=NullPointerException+emptyborder


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. You must get a Windows XP system with Microsoft Plus! installed. Switch to one of the custom themes. http://www.microsoft.com/windows/plus/PlusHome.asp
2. Run the SwingSet2 demo
3. Change Look and Feel to "Windows Style Look and Feel"
4. Click on the JTable demo

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected table header to render as usual.
ACTUAL -
Stacktrace originating in WindowsTableHeaderUI.XPDefaultRenderer. It seems that in this line:

	    setBorder(new EmptyBorder(skin.getContentMargin()));

skin.getContentMargin() is returning null, and EmptyBorder doesn't like that.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at javax.swing.border.EmptyBorder.<init>(Unknown Source)
at
com.sun.java.swing.plaf.windows.WindowsTableHeaderUI$XPDefaultRenderer.ge=
tTableCellRendererComponent(Unknown
Source)
at javax.swing.plaf.basic.BasicTableHeaderUI.getHeaderRenderer(Unknown
Source)
at javax.swing.plaf.basic.BasicTableHeaderUI.getHeaderHeight(Unknown
Source)
at javax.swing.plaf.basic.BasicTableHeaderUI.createHeaderSize(Unknown
Source)
at javax.swing.plaf.basic.BasicTableHeaderUI.getPreferredSize(Unknown
Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at javax.swing.ViewportLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at javax.swing.ScrollPaneLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
N/A - SwingSet demo provides adequate example
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
User workarounds:
1. Change from XP custom look and feel to standard XP or Windows Classic L&F
2. Change application properties to "Run this program in compatibility mode for Windows 2000."

Code workarounds:
No way to workaround without modifying Swing code. But one of these things could be corrected:

1. ThemeReader.getThemeMargins(..) guarantees to return non-null
2. Skin.getContentMargin() guarantees to return non-null
3. XPDefaultRenderer's call to getContentMargin() should handle null and pass in some legit Insets to EmptyBorder.

Comments
EVALUATION The solution for this bug is to modify getContentMargin() to take a fallback value that will be used in case the theme value is null. This ensures we never get NPEs and lets the component calling XPStyle.getContentMargin() be in charge of what happens when the value is null.
10-07-2006

EVALUATION I cannot find any themes that exhibit this error. If I completely remove the SIZINGMARGINS key from the table header parts then I get a different error than the one in the description (out of memory errors caused by the insets being huge, clearly filled in with random memory). This reflects a bug in the native code that is not checking for the proper return value, but that is a new and separate bug (6437673). In either case, we need to properly handle a null value by returning empty insets.
13-06-2006

EVALUATION The explanation in the description is correct. This should be fixed by modifying the Skin.getContentMargins since there might be valid reasons for ThemeReader to return null. Since this throws NPEs that could potentially crash a program this should be fixed for Mustang.
08-06-2006