Bug 24077

Summary: Cannot create JFileChooser due to NPE (getFontMetrics)
Product: classpath Reporter: Norman Hendrich <hendrich>
Component: swingAssignee: Lillian Angel <langel>
Status: RESOLVED FIXED    
Severity: normal CC: bug-classpath
Priority: P2    
Version: unspecified   
Target Milestone: 0.19   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-09-27 19:13:18

Description Norman Hendrich 2005-09-27 08:45:11 UTC
Swing is almost completely broken at the moment (due to changes introduced
by the recent repaint refactoring). There are NPEs all over the place.
Here is my favorite, stacktrace from jamvm 1.3.2 and Classpath CVS 2005.09.29 
on x86 linux:

jamvm niffler.JImageViewer ~/.niffler
java.lang.NullPointerException
   at gnu.java.awt.peer.gtk.GdkFontMetrics.<init> (GdkFontMetrics.java:69)
   at gnu.java.awt.peer.gtk.GtkToolkit.getFontMetrics (GtkToolkit.java:355)
   at javax.swing.plaf.basic.BasicComboBoxRenderer.getListCellRendererComponent 
(BasicComboBoxRenderer.java:109)
   at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize (BasicComboBoxUI.jav
a:849)
   at javax.swing.plaf.basic.BasicComboBoxUI$ListDataHandler.intervalAdded (Basi
cComboBoxUI.java:1083)
   at javax.swing.AbstractListModel.fireIntervalAdded (AbstractListModel.java:12
9)
   at javax.swing.DefaultComboBoxModel.addElement (DefaultComboBoxModel.java:124
)
   at javax.swing.JComboBox.addItem (JComboBox.java:598)
   at javax.swing.plaf.basic.BasicFileChooserUI.boxEntries (BasicFileChooserUI.j
ava:1093)
   at javax.swing.plaf.basic.BasicFileChooserUI.installComponents (BasicFileChoo
serUI.java:1174)
   at javax.swing.plaf.basic.BasicFileChooserUI.installUI (BasicFileChooserUI.ja
va:1044)
   at javax.swing.JComponent.setUI (JComponent.java:2368)
   at javax.swing.JFileChooser.updateUI (JFileChooser.java:1158)
   at javax.swing.JFileChooser.setup (JFileChooser.java:314)
   at javax.swing.JFileChooser.<init> (JFileChooser.java:241)
   at niffler.JImageViewer.checkCreateFileChooser (JImageViewer.java:2289)
Comment 1 Lillian Angel 2005-09-27 20:34:49 UTC
*** Bug 24078 has been marked as a duplicate of this bug. ***
Comment 2 Lillian Angel 2005-09-27 20:35:06 UTC
*** Bug 24081 has been marked as a duplicate of this bug. ***
Comment 3 Lillian Angel 2005-09-27 20:56:09 UTC
A UI delegate should install its default font on a JComponent only if the
existing font is null or implements UIResource.  

For some reason, many UI delegates are not setting the default font. It is
correct for Component.getFont to return null when no default font has been set.

I am looking into which UIs have not set their default fonts.
Comment 4 Lillian Angel 2005-09-28 13:56:16 UTC
Fixed
Comment 5 cvs-commit@developer.classpath.org 2005-09-28 14:09:03 UTC
Subject: Bug 24077

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Branch: 	
Changes by:	Lillian Angel <langel@savannah.gnu.org>	05/09/28 13:59:14

Modified files:
	.              : ChangeLog 
	gnu/java/awt/peer/gtk: GdkFontMetrics.java GdkGraphics.java 
	javax/swing    : JPopupMenu.java 

Log message:
	2005-09-28  Lillian Angel  <langel@redhat.com>
	
	Fixes Bug #24077
	* gnu/java/awt/peer/gtk/GdkFontMetrics.java
	(GdkFontMetrics): Added a check for the font
	being null. Fixed a NPE.
	* gnu/java/awt/peer/gtk/GdkGraphics.java
	(GdkGraphics): Added check if the font is null.
	If it is, the font should be set to the default.
	(setFont): If font parameter is null, this.font should not
	be changed.
	* javax/swing/JPopupMenu.java:
	Fixed API documentation to say 'JDialog' rather than
	'JWindow'.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/ChangeLog.diff?tr1=1.5010&tr2=1.5011&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/awt/peer/gtk/GdkFontMetrics.java.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java.diff?tr1=1.46&tr2=1.47&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/javax/swing/JPopupMenu.java.diff?tr1=1.24&tr2=1.25&r1=text&r2=text