JDK-6192278 : 1.4.2: File.getCanonicalPath() fails for removeable drive if no media is present (win)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.2_06
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-11-08
  • Updated: 2014-02-27
  • Resolved: 2011-08-18
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
In JDK 1.4.2_06, it is no longer possible to use FileSystemView.getSystemDisplayName() on Windows for a removable drive when there is no media present in the drive.  This worked as recently as JDK 1.4.2_05.  FileSystemView.getSystemIcon() fails as well.

The crux of the problem seems to be that File.getCanonicalPath() fails on a removable drive root when there is no media.  FileSystemView.getSystemDisplayName() now relies on File.getCanonicalPath(), where previously it did not.  File.getCanonicalPath() should never fail on any drive root path, for any reason, since the canonical path is always the root path itself.

The problem is not reproducible with J2SE 5.0.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached program on a Windows system using both JDK 1.4.2_05 and JDK 1.4.2_06 and compare the results.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This is the output on my machine when run under JDK 1.4.2_05:

java runtime = 1.4.2_04-b05

root: A:display name = 3�� Floppy (A:)

root: C:display name = System Volume (C:)

root: D:display name = Data Volume (D:)

root: E:display name = ADE Volume (E:)

root: F:display name = CD Drive (F:)
ACTUAL -
This is the output on my machine under JDK 1.4.2_06:

java runtime = 1.4.2_06-b03

root: A:FileSystemView.getShellFolder: f=A:java.io.FileNotFoundException: File A:\ not found
        at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Win32ShellFo
lderManager2.java:48)
        at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Win32ShellFo
lderManager2.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.getSystemDisplayName(FileSyste
mView.java:144)
        at SystemDisplayNameTest.main(SystemDisplayNameTest.java:20)
Exception getting display name
java.lang.NullPointerException
        at javax.swing.filechooser.FileSystemView.getSystemDisplayName(FileSyste
mView.java:144)
        at SystemDisplayNameTest.main(SystemDisplayNameTest.java:20)

root: C:display name = System Volume (C:)

root: D:display name = Data Volume (D:)

root: E:display name = ADE Volume (E:)

root: F:FileSystemView.getShellFolder: f=F:java.io.FileNotFoundException: File F:\ not found
        at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Win32ShellFo
lderManager2.java:48)
        at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Win32ShellFo
lderManager2.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.getSystemDisplayName(FileSyste
mView.java:144)
        at SystemDisplayNameTest.main(SystemDisplayNameTest.java:20)
Exception getting display name
java.lang.NullPointerException
        at javax.swing.filechooser.FileSystemView.getSystemDisplayName(FileSyste
mView.java:144)
        at SystemDisplayNameTest.main(SystemDisplayNameTest.java:20)
[E:\ade\jeras_jdev\jdev\src]

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.IOException;
import javax.swing.filechooser.FileSystemView;

public class SystemDisplayNameTest
{
  public static void main(String[] args)
  {
    System.out.println("java runtime = " + System.getProperty("java.runtime.version"));
    System.out.println();

    final FileSystemView fsv = FileSystemView.getFileSystemView();
    final File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++)
    {
      final File root = fsv.createFileObject(roots[i].getPath());
      System.out.println("root: " + root);
      try
      {
        System.out.println("display name = " + fsv.getSystemDisplayName(root));
      }
      catch (Exception ex)
      {
        System.err.println("Exception getting display name");
        ex.printStackTrace();
      }
      System.out.println();
    }
  }
}

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

CUSTOMER SUBMITTED WORKAROUND :
None.  One must avoid calling FileSystem.getSystemDisplayName() on a removable drive root, for example by using FileSystemView.isFloppyDrive() and/or File.exists().
###@###.### 2004-11-08 19:41:03 GMT

Comments
EVALUATION Not fixing in 1.4.2 without escalation. This is not applicable for 5.0 or later. Closing as will not fix.
18-08-2011

EVALUATION In 1.4.2 getCanonicalPath throws an IOException "The device is not ready" when media is not present. This issue does not exist in 5.0 or Mustang. The issue that the submitter is observing is that Swing's FileSystemView was changed in 1.4.2_06 to use getCanonicalPath(). The bugID for this change was 4869950. If it throws IOException then FNF is thrown. So this is a regression that should be examined by the sustaining team.
12-10-2005