JDK-4869950 : NPE if JFileChooser.setCurrentDirectory() called twice with non-canonical file
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2,1.4.2_04,5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2003-05-27
  • Updated: 2004-07-22
  • Resolved: 2004-06-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2_06 06Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Name: rmT116609			Date: 05/27/2003


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

FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
JFileChooser.setCurrentDirectory() will produce a NullPointerException if
called twice with a non-canonical file. This happens in the "LoadFilesThread".

FileSystemView really needs to be made bulletproof to prevent this kind of
thing. Many of the methods of FileSystemView are quite flaky, and require a
canonical file and/or an existing file, although this is not documented.
JFileChooser and other users of FileSystemView should not be required to
work around this voodoo.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect nothing.
ACTUAL -
Get what is apparently a debugging dump of a
FileNotFoundException, followed by a (thrown) NullPointerException.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
FileSystemView.getShellFolder: f=C:\Windows\.\System
java.io.FileNotFoundException: Could not find file C:\Windows\.\System
	at sun.awt.shell.Win32ShellFolder2.parseDisplayName(Win32ShellFolder2.java:574)
	at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Win32ShellFolderManager2.java:40)
	at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Win32ShellFolderManager2.java:36)
	at sun.awt.shell.ShellFolder.getShellFolder(ShellFolder.java:236)
	at javax.swing.filechooser.FileSystemView.getShellFolder(FileSystemView.java:486)
	at javax.swing.filechooser.FileSystemView.getFiles(FileSystemView.java:409)
	at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(BasicDirectoryModel.java:194)
java.lang.NullPointerException
	at javax.swing.filechooser.FileSystemView.getFiles(FileSystemView.java:412)
	at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(BasicDirectoryModel.java:194)



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
   import javax.swing.*;
   import java.io.File;

    public class JFileChooserBug3 {
       public static void main(String args[]) {
         JFileChooser fc = new JFileChooser();
         File f = new File("C:\\Windows\\.\\System");
         fc.setCurrentDirectory(f);
         fc.setCurrentDirectory(f);
      }
   }

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

Release Regression From : 1.4.1_02
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 186439) 
======================================================================

BEA has reported the same issue. Here is the description:

Problem:

If you try to import a libarary with ".." in the path you get the NPE shown 

below.  

 


 

===

NPE

===

java.lang.NullPointerException

        at javax.swing.filechooser.FileSystemView.getFiles(FileSystemView.java:419)

        at 

com.bea.ide.swing.FileSystemViewWrapper.getFiles(FileSystemViewWrapper.java:66)

        at 

javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(BasicDirectoryModel.java:194)

 

-----------------------------------------------------------------------------------------------

 

I believe it's the same issue as bug parade 4869950

http://developer.java.sun.com/developer/bugParade/bugs/4869950.html

 

here is my repro:

 

import java.awt.*;

import java.awt.event.*;

import java.io.File;

import javax.swing.*;

 

public class Test2

{

    static public void main(String[] args)

    {

        final JFrame m = new JFrame("main");

        JButton b1 = new JButton("open file dialog");

        m.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        m.setContentPane(b1);

        m.setSize(200,150);

        m.setVisible(true);

 

        b1.addActionListener(new ActionListener()

        {

            public void actionPerformed(ActionEvent e)

            {

                JFileChooser fc = new JFileChooser();

                File f = new File("c:\\Documents And Settings\\..");

                fc.setCurrentDirectory(f);

                fc.setCurrentDirectory(f);

                fc.showOpenDialog(m);

            }

        });

 

    }

 

} 

 

to see the other call stack, you can type in c:\documents and 

settings\..\foo.txt (or some file that exists at your root.  and hit open.  

this will throw the GetFiles() NPE

 

java.lang.NullPointerException

        at javax.swing.filechooser.FileSystemView.getFiles(FileSystemView.java:419)

        at 

javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(BasicDirectoryModel.java:194)

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4.2_06 generic tiger-rc FIXED IN: 1.4.2_06 tiger-rc INTEGRATED IN: 1.4.2_06 tiger-b57 tiger-rc VERIFIED IN: 1.4.2_06
24-09-2004

SUGGESTED FIX --- Win32ShellFolderManager2.java Thu May 6 13:08:36 2004 *************** *** 38,40 **** static Win32ShellFolder2 createShellFolder(Win32ShellFolder2 parent, File file) throws FileNotFoundException { ! long pIDL = parent.parseDisplayName(file.getAbsolutePath()); if (pIDL == 0) { --- 38,45 ---- static Win32ShellFolder2 createShellFolder(Win32ShellFolder2 parent, File file) throws FileNotFoundException { ! long pIDL = 0; ! try { ! pIDL = parent.parseDisplayName(file.getCanonicalPath()); ! } catch (IOException ex) { ! pIDL = 0; ! } if (pIDL == 0) { ###@###.### 2004-05-17
17-05-2004

EVALUATION Reproducible as described - passes with 1.4.1, throws an NPE w/ 1.4.2. I suspect that 4712307 could be responsible. ###@###.### 2003-05-28 The ShellFolder object should be created based on the canonical path instead of the absolute path. ###@###.### 2004-05-17
28-05-2003