JDK-4390321 : JFileChooser.setSelectedFile(File) method throws NPE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2000-11-17
  • Updated: 2004-08-18
  • Resolved: 2004-04-12
Related Reports
Duplicate :  
Description

Name: nkR10003			Date: 11/17/2000


JFileChooser.setSelectedFile(File) sometimes throws NullPointerException

Example below demonstrates this problem:
------------------example--------------------
//test.java
import javax.swing.*;
import java.io.*;
public class test {
    public static void main(String[] args) {
        File wdir = new File("/etc");
        for (int i=0; i<1000; i++) {
            try {
                JFileChooser fileChooser = new JFileChooser(wdir);
                File pswd = new File(wdir, "passwd");
                fileChooser.setSelectedFile(pswd);
                if (!fileChooser.getSelectedFile().equals(pswd)) {
                    System.out.println("Method setSelectedFile() works wrong");
                    System.out.println("Test failed");
                    System.exit(0);
                }
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("Test failed");
                System.exit(0);
            }
        }
        
        System.out.println("Test passed OK");
        System.exit(0);
    }
}
----------------output:----------------------
java.lang.NullPointerException
        at javax.swing.JLabel.setIcon(JLabel.java:377)
        at javax.swing.plaf.metal.MetalFileChooserUI$FileRenderer.getListCellRendererComponent(MetalFileChooserUI.java:637)
        at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:772)
        at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:722)
        at javax.swing.plaf.basic.BasicListUI.getCellBounds(BasicListUI.java:598)
        at javax.swing.JList.getCellBounds(JList.java:845)
        at javax.swing.JList.ensureIndexIsVisible(JList.java:758)
        at javax.swing.plaf.metal.MetalFileChooserUI.setFileSelected(MetalFileChooserUI.java:709)
        at javax.swing.plaf.metal.MetalFileChooserUI.doSelectedFileChanged(MetalFileChooserUI.java:734)
        at javax.swing.plaf.metal.MetalFileChooserUI.access$800(MetalFileChooserUI.java:31)
        at javax.swing.plaf.metal.MetalFileChooserUI$8.propertyChange(MetalFileChooserUI.java:847)
        at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:162)
        at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:130)
        at javax.swing.JComponent.firePropertyChange(JComponent.java:3438)
        at javax.swing.JFileChooser.setSelectedFile(JFileChooser.java:417)
        at test.main(test.java:10)
Test failed
---------------------------------------------
To reproduce this failure run the test example from this report on 
a multiprocessor machine.
Also, you can reproduce this by running the JCK test (see Justification 
field (*)) in JavaTest in single JVM configuration on any machine.

======================================================================

Comments
EVALUATION The file loading thread is is not robust enough for this kind of treatment. Need to make it thread safe. leif.samuelsson@Eng 2001-05-18 Name: keR10081 Date: 04/02/2002 Not reproducible since 1.4.0-b80 and would be closed as such ###@###.### ====================================================================== Name: apR10229 Date: 02/28/2003 This bug still reproducable on jdk1.5.0(b02). Need to be reopened. ====================================================================== Name: apR10229 Date: 02/28/2003 More detailed overview: reproducible on: 1.5.0(b02)-solaris, 1.4.2(b16)-linux, 1.4.2(b16)-solaris. I used 4-processor solaris-sparc and uniprocessor linux-intel. ====================================================================== ###@###.### 2003-03-05 (SPB JCK rotator, local email ###@###.###) Reproducible on sqeel (Solaris 5.8) with display to novo35 (Solaris 5.7) under jdk 1.5.0-beta-b02 (/java/re/jdk/1.5.0/latest/binaries/solaris-sparc/bin/java). Reopened. Name: acR10002 Date: 04/01/2004 I can reproduce it with jdk1.5.0 b45 on 4-head E450 server running Solaris 8: ->uname -a SunOS archer 5.8 Generic_108528-24 sun4u sparc SUNW,Ultra-4 Now it is failing with the different stack trace though: ------ java.lang.NullPointerException at test.main(test.java:12) Test failed ------ It seems getSelectedFile() returns null instead of pswd. ====================================================================== Name: keR10081 Date: 04/12/2004 This bug is no longer reproducible after fix for 4997165. Closing out as a duplicate. ###@###.### ======================================================================
13-09-2004