Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4909881

JFileChooser.setVisible(true) leads to NullPointerException under XP L&F

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • client-libs



      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)
      ======================================================================

            leifs Leif Samuelsson (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: