Bug 23012 - swing: JFileChooser("/thisdoesnotexist") throws NullPointerException
Summary: swing: JFileChooser("/thisdoesnotexist") throws NullPointerException
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: unspecified
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-27 19:56 UTC by from-classpath
Modified: 2005-07-23 22:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description from-classpath 2005-06-27 19:56:14 UTC
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);
        }
}

Comment 1 from-classpath 2005-07-06 13:20:04 UTC
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
Comment 2 from-classpath 2005-07-08 15:07:52 UTC
Fixed as of July 8, 2005.