Name: bsC130419 Date: 07/23/2001
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)
When I manipulate System property "user.dir", File's getAbsoluteFile() may no
longer refer to the same file as original. Here is an example:
----------
import java.io.File;
import java.io.IOException;
public class FileAbsPathBug {
public static void main( String[] args) throws IOException {
// Create test file in c:/temp
File test= new File( "c:/temp/test.txt");
if( !test.exists()) {
test.createNewFile();
}
// Set c:/temp as my base directory for resolving relative paths
System.setProperty( "user.dir", "c:/temp/");
// Make a relative path for the c:/temp/test.txt file we've just creared
File f= new File( "test.txt");
System.err.println(
f.getAbsolutePath() +
(f.exists() ? " exists" : " does not exist" )
);
System.err.println(
f.getAbsolutePath() +
(f.getAbsoluteFile().exists() ? " exists" : " does not exist" )
);
}
}
----------
Running this results in the following printout:
c:\temp\test.txt does not exist
c:\temp\test.txt exists
I suspect that this problem happens because File internally resolves existence
using FileSystem's getBooleanAttributes(this) & FileSystem.BA_EXISTS.
FileSystem.getBooleanAttribute is a native method, which is likely to not know
about "user.dir".
One fix to this would be always passing an absolute path to native methods of
FileSystem.
(Review ID: 128603)
======================================================================