-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0, 1.2.2
-
beta
-
generic, x86, sparc
-
generic, solaris_2.5, windows_nt
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)
======================================================================
- relates to
-
JDK-4906607 Can't select a file through symlink using a JFileChooser
- Resolved