|
Quick Lists
|
|
Bug ID:
|
6547087
|
|
Votes
|
2
|
|
Synopsis
|
JPopupMenu.Separator getPreferredSize throws NullPointerException
|
|
Category
|
java:classes_swing
|
|
Reported Against
|
|
|
Release Fixed
|
7(b20),
6u4(b02) (Bug ID:2150912)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
6604739
,
5016492
|
|
Submit Date
|
17-APR-2007
|
|
Description
|
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
customer Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
In JDK6, JPopupMenu.Separator uses WindowsPopupMenuSeparatorUI that extends BasicPopupMenuSeparatorUI, which calls c.getFont().getHeight() somewhere down the line without checking for null (it would return half of font height).
JDK5 doesn't have a Windows LaF specific JPopupMenu.Separator UI--it uses BasicPopupMenuSeparatorUI, whose getPreferredSize always returns Dimension(0, 2).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set L&F to WindowsLookAndFeel, and call JPopupMenu.Separator.getPreferredSize()
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
null
java.awt.Dimension[width=0,height=2]
(under Java 5)
ACTUAL -
null
java.lang.NullPointerException
at sun.font.FontDesignMetrics$MetricsKey.init(FontDesignMetrics.java:199)
at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:267)
at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:910)
at javax.swing.JComponent.getFontMetrics(JComponent.java:1592)
at com.sun.java.swing.plaf.windows.WindowsPopupMenuSeparatorUI.getPreferredSize(WindowsPopupMenuSeparatorUI.java:41)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1627)
at PopupMenuNPE.main(PopupMenuNPE.java:13)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.JPopupMenu;
import javax.swing.UIManager;
public class PopupMenuNPE {
public static void main(String[] args) {
try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
JPopupMenu.Separator a = new JPopupMenu.Separator();
System.out.println(a.getFont());
System.out.println(a.getPreferredSize());
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Extends JPopupMenu.Separator and set its UI to BasicPopupMenuSeparatorUI:
private static final class JfeMenuSeparator extends JPopupMenu.Separator
{
private static final javax.swing.plaf.ComponentUI ui_s = new BasicPopupMenuSeparatorUI();
public JfeMenuSeparator()
{
this.setUI(ui_s);
}
}
Release Regression From : 5.0u10
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
Posted Date : 2007-04-17 21:38:12.0
|
|
Work Around
|
N/A
|
|
Evaluation
|
this bug is a regression introduced by the fix for 5016492 [XP L&F: Separator between menu items in native give more gap than java]
Posted Date : 2007-07-11 18:13:07.0
we can have getFont == null as a special case.
Posted Date : 2007-07-17 02:13:46.0
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |