JDK-4199911 : JFileChooser.setCurrentDirectory(file) sets dir to canonical path
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0,1.2.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_2.5,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1998-12-25
  • Updated: 2000-09-27
  • Resolved: 2000-09-27
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.0 betaFixed
Related Reports
Relates :  
Description

Name: mgC56079			Date: 12/25/98


The specification says JFileChooser.setCurrentDirectory(file) sets current dir to 
a file or to a user's home if file is null. 
However, for Metal LAF it sets current dir to the _canonical_ path of the given file or to the 
_canonical_ path of the user's home if file is null.

In particular this means that symbolic links on a Unix machine will be expanded
and the getCurrentDirectory method will return file object which is not equal to
the one passed to setCurrentDirectory.

Either this should be documented in the javadoc or implementation should be changed.

This problem causes the failure of the following simple test
if the user's home is a symlink to some other directory:

========== FileTest.java ===========
import java.io.*;
import javax.swing.*;

public class FileTest {

    public static void main(String[] s) { 
        File f=new File(System.getProperty("user.home"));
        JFileChooser ch=new JFileChooser();
        System.out.println("User's home:" + f);
        System.out.println("Current dir:" +ch.getCurrentDirectory());
        if (f.equals(ch.getCurrentDirectory()))
            System.out.println("passed");
        else
            System.out.println("failed");
    }

}
=== sample run (I made a symbolik link from /net/mars/export2/gor to /home/gor)===
(###@###.###)/home/gor/bugs: java -Duser.home=/net/mars/export2/gor FileTest
User's home:/net/mars/export2/gor
Current dir:/home/gor
failed

This is a message from the licensee with more details
(/spock4/users/corwinlw is evidently a symbolic link to /engr2/users/corwinlw):

> From ###@###.###  Thu Dec 24 00:55:18 1998
> From: ###@###.### (Jay VanSant)
> Subject: JCK test failure on swing.JFileChooser.CtorTests
> To: ###@###.###
> Date: Wed, 23 Dec 1998 13:50:45 -0800 (PST)
> Cc: ###@###.### (Javadev Group Mailing List),
>         ###@###.### (Jay VanSant), ###@###.### (Marc San Soucie),
>         ###@###.### (Misty Pesek),
>         ###@###.### (Corwin Light-Williams),
>         ###@###.### (D. Jason Penney)
> 
> We are seeing a failure in both our VM and in the
> FCS "V" JDK1.2 VM when running the JCK test
>  "javasoft.sqe.tests.api.javax.swing.JFileChooser.CtorTests".
> 
> Since the released JDK1.2 VM fails this test, shouldn't this test 
> be in the "excludes" list?
> 
> If we are running this with an incorrect configuration, please
> suggest how we might fix it.
> 
> Here's email showing the test being run with text from the
> results.  
> #--------------------------------------------------------------------
> bash$ type java
> java is hashed (/spock4/users/corwinlw/jdk/jdk1.2/bin/java)
> bash$ java -version
> java version "1.2"
> Classic VM (build JDK-1.2-V, green threads, sunwjit)
> bash$ java javasoft.sqe.tests.api.javax.swing.JFileChooser.CtorTests -TestCaseID ALL -TestURL file:///spock4/users/cor
> winlw/api/JCK-runtime-api-12a/tests/api/javax_swing/JFileChooser/manual.html#Ctor -TestWorkDirURL file:///spock4/users
> /corwinlw/jck/api/work/api/javax_swing/JFileChooser/
> ====== JFileChooser2001 ====== constructor JFileChooser()
> Object:javax.swing.JFileChooser[,0,0,0x0,invalid,layout=javax.swing.BoxLayout,alignmentX=null,alignmentY=null,border=,
> flags=0,maximumSize=,minimumSize=,preferredSize=,approveButtonText=,currentDirectory=/engr2/users/corwinlw,dialogTitle
> =,dialogType=OPEN_DIALOG,fileSelectionMode=FILES_ONLY,returnValue=ERROR_OPTION,selectedFile=,useFileHiding=true]
> JFileChooser2001: Failed. Failed to create JFileChooser object
> ====== JFileChooser2002 ====== constructor JFileChooser(File)
> Object:javax.swing.JFileChooser[,0,0,0x0,invalid,layout=javax.swing.BoxLayout,alignmentX=null,alignmentY=null,border=,
> flags=0,maximumSize=,minimumSize=,preferredSize=,approveButtonText=,currentDirectory=/engr2/users/corwinlw,dialogTitle
> =,dialogType=OPEN_DIALOG,fileSelectionMode=FILES_ONLY,returnValue=ERROR_OPTION,selectedFile=,useFileHiding=true]
> Current directory: /engr2/users/corwinlw
> JFileChooser2002: Failed. Failed to create JFileChooser object
> ====== JFileChooser2003 ====== constructor JFileChooser(String)
> Object:javax.swing.JFileChooser[,0,0,0x0,invalid,layout=javax.swing.BoxLayout,alignmentX=null,alignmentY=null,border=,
> flags=0,maximumSize=,minimumSize=,preferredSize=,approveButtonText=,currentDirectory=/engr2/users/corwinlw,dialogTitle
> =,dialogType=OPEN_DIALOG,fileSelectionMode=FILES_ONLY,returnValue=ERROR_OPTION,selectedFile=,useFileHiding=true]
> Current directory: /engr2/users/corwinlw
> JFileChooser2003: Failed. Failed to create JFileChooser object
> STATUS:Failed. tests: 3; failed: 3; first test case failure: JFileChooser2001
> 

Please note that this problem is specific to Metal LAF.
The same piece code works correctly with Motif LAF:
========= FileTest1.java ========= 
import java.io.*;
import javax.swing.*;

public class FileTest1 {

    public static void main(String[] s) throws Exception { 
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // ! CHANGE LAF
        File f=new File(System.getProperty("user.home"));
        JFileChooser ch=new JFileChooser();
        System.out.println("User's home:" + f);
        System.out.println("Current dir:" +ch.getCurrentDirectory());
        if (f.equals(ch.getCurrentDirectory()))
            System.out.println("passed");
        else
            System.out.println("failed");
    }

}
========= sample run ========= 
java -Duser.home=/net/mars/export2/gor FileTest1
User's home:/net/mars/export2/gor
Current dir:/net/mars/export2/gor
passed


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

Name: ks88420			Date: 08/23/2000


java version "1.2.2"
Classic VM (build JDK-1.2.2-001, native threads, symcjit)

Make a JFileChooser in a GUI that opens in the current directory:

JFileChooser fc = new JFileChooser(".");
int retval = fc.showOpenDialog(this); //assume this is a JFrame
if (retval == JFileChooser.APPROVE_OPTION) {
File dir = fc.getCurrentDirectory();
System.out.println("Dir is: " + dir.getName());
}

If we are in d:\users\mary,and select a file in that directory,
this only prints out:
Dir is: mary
It should print    :
Dir is: d:\users\mary
or
Dir is: \users\mary

How are you supposed to get the complete pathname of the file
otherwise?
(Review ID: 107653)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

WORK AROUND Name: mgC56079 Date: 09/22/99 To pass this particular JCK test the user needs to ensure the home directory is not a symbolic link to the actual location. There is no easy workaround for the bug itself (a possible one is to use LAF other than Metal (may not be appropriate for JCK certification)). ======================================================================
11-06-2004

EVALUATION Name: keC97670 Date: 02/10/2000 not reproducible on latest builds ====================================================================== Name: keC97670 Date: 02/10/2000 THE BUG IS REALLY REPRODUCIBLE. THE PREVIOUS EVALUATION WAS OCCASIONALLY INCORRECT. ====================================================================== Fixed with the new JFileChooser code for merlin. Please note that the last test case in the bug description is incorrect. File.getName() returns the name of the directory. Use File.getPath() to get the complete path to the directory. leif.samuelsson@Eng 2000-09-25
25-09-2000