Posted by vpatryshev
on February 20, 2005 at 10:29 AM PST
This drags from 1997... see http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4045688
String rootname = "D:\\tmp";<br />
String filename = "testfiles.txt";<br />
String rootfilename = rootname + File.separator + filename;<br />
String expected = "this is a test";<br />
writeToFile(expected, rootfilename);<br />
System.setProperty("user.dir", rootname);<br />
File file = new File(filename);<br />
assertEquals(rootfilename, file.getAbsolutePath());<br />
File rootfile = file.getAbsoluteFile();<br />
Is not it funny that the first two asserts pass, and the third one fails?
Someone said this:
"If you need to simulate chdir, it is trivial to do:
File file = new File(filename).getAbsoluteFile();" - is not it funny that changing "user.dir" leads to this kind of discrepancy? They say chdir() is a hack. It is an operation used by millions in thousands of programs. Using a surrogate "user.dir" instead is, I think, a worse hack.