JDK-4909881 : JFileChooser.setVisible(true) leads to NullPointerException under XP L&F
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-08-20
  • Updated: 2003-09-15
  • Resolved: 2003-09-15
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 08/20/2003


FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
JFileChooser.setVisible(true) leads to a NullPointerException under the
Windows XP Look & Feel. Applications that use JFileChooser outside of
its built-in dialog (as ours does) will fail.

This bug may break lots of existing code. It certainly breaks our
application for users of the Windows Look & Feel.

  Bug 4806285 looks identical, but was closed as "not a bug" without
explanation.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect nothing.
ACTUAL -
Get a stack dump.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
	at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
	at javax.swing.ImageIcon.<init>(ImageIcon.java:147)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI$ShortCutPanel.<init>(WindowsFileChooserUI.java:603)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(WindowsFileChooserUI.java:361)
	at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:130)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(WindowsFileChooserUI.java:176)
	at javax.swing.JComponent.setUI(JComponent.java:449)
	at javax.swing.JFileChooser.updateUI(JFileChooser.java:1701)
	at javax.swing.JFileChooser.setup(JFileChooser.java:345)
	at javax.swing.JFileChooser.<init>(JFileChooser.java:320)
	at javax.swing.JFileChooser.<init>(JFileChooser.java:273)
	at JFileChooserBug7.main(JFileChooserBug7.java:11)
Exception in thread "main"


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
  import javax.swing.*;

    public class JFileChooserBug7 {
       public static void main(String args[]) {
         // Uncomment the next line to work around the bug.
         //new JFileChooser();
       
         // Switch to Windows L&F.
         try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); }
             catch(Exception e) {}
      
         JFileChooser fc = new JFileChooser();
         fc.setVisible(true);
      }
   }

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Create a JFileChooser under the Metal Look & Feel before switching to
Windows Look & Feel. This seems to cure the problem.
(Incident Review ID: 193453) 
======================================================================

Comments
SUGGESTED FIX Since I cannot reproduce this bug yet, I am not sure if the following workaround will solve the problem: import javax.swing.*; public class bug4909881 { public static void main(String args[]) { SwingUtilities.invokeLater(new Runnable() { public void run() { // Switch to Windows L&F. try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch(Exception e) { } JFileChooser fc = new JFileChooser(); fc.setVisible(true); } }); } } ###@###.### 2003-08-20
20-08-2003

EVALUATION Note that the stack trace in the example shows that the NPE happens in the constructor for JFileChooser, not in the call to setVisible() that follows. I have not been able to reproduce this on Windows XP yet, but it looks like a duplicate of 4711700. ###@###.### 2003-08-20
20-08-2003