Steps to reproduce: 1. Compile and run the attached testcase. Expected results: 1. filechooser's "Open" dialog shows user's home directory. Actual results: 1. No window is shown and program throws the following exception: java.lang.NullPointerException at javax.swing.filechooser.FileSystemView.getFiles (FileSystemView.java:143) at javax.swing.plaf.basic.BasicDirectoryModel.validateFileCache (BasicDirectoryModel.java:292) at javax.swing.plaf.basic.BasicFileChooserUI.rescanCurrentDirectory (BasicFileChooserUI.java:1639) at javax.swing.plaf.basic.BasicFileChooserUI$12.propertyChange (BasicFileChooserUI.java:1583) at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange (SwingPropertyChangeSupport.java:223) at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange (SwingPropertyChangeSupport.java:196) at javax.swing.JComponent.firePropertyChange (JComponent.java:721) at javax.swing.JFileChooser.setCurrentDirectory (JFileChooser.java:405) at javax.swing.JFileChooser.<init> (JFileChooser.java:243) at testcase.<init> (testcase.java:8) at testcase.main (testcase.java:5) Testcase: import javax.swing.*; import java.awt.*; public class testcase extends JFrame { public static void main(String[] args) { new testcase(); } public testcase() { new JFileChooser("/thisdoesnotexist").showOpenDialog(this); } }
This is the bugfix: change in javax.swing.filechooser.FileSystemView the following method: public File createFileObject(String path) { return new File(path); } to this one: public File createFileObject(String path) { File temp = new File(path); if(temp.isDirectory()) return temp; return null; } The patch is under 10 lines, so you can take it. And its trivial
Fixed as of July 8, 2005.