7034532: (fs) AssertionError when working directory is UNC
Alan Bateman
Alan.Bateman at oracle.com
Fri Apr 8 07:30:58 PDT 2011
Someone testing jdk7 in NetBeans reported the following stack trace when
attempting to run their JUnit tests:
Exception in thread "main" java.lang.AssertionError: Default directory
must be absolute/non-UNC
at sun.nio.fs.WindowsFileSystem.<init>(WindowsFileSystem.java:60)
at
sun.nio.fs.WindowsFileSystemProvider.<init>(WindowsFileSystemProvider.java:52)
at
sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:36)
:
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
The bug is that the code assumes that the process working directory
cannot be an UNC. You can't "cd" to a UNC but you can launch a process
with a UNC path as the working directory and that seems to be the case here.
The fix is trivial and just allows the default directory to be a UNC:
diff --git a/src/windows/classes/sun/nio/fs/WindowsFileSystem.java
b/src/windows/classes/sun/nio/fs/WindowsFileSystem.java
--- a/src/windows/classes/sun/nio/fs/WindowsFileSystem.java
+++ b/src/windows/classes/sun/nio/fs/WindowsFileSystem.java
@@ -56,8 +56,9 @@ class WindowsFileSystem
// parse default directory and check it is absolute
WindowsPathParser.Result result = WindowsPathParser.parse(dir);
- if (result.type() != WindowsPathType.ABSOLUTE)
- throw new AssertionError("Default directory must be
absolute/non-UNC");
+ if ((result.type() != WindowsPathType.ABSOLUTE) &&
+ (result.type() != WindowsPathType.UNC))
+ throw new AssertionError("Default directory is not an
absolute path");
this.defaultDirectory = result.path();
this.defaultRoot = result.root();
I don't propose to include a regression test for this.
Thanks,
-Alan.
More information about the nio-dev
mailing list