7034532: (fs) AssertionError when working directory is UNC

Rémi Forax forax at univ-mlv.fr
Fri Apr 8 09:01:25 PDT 2011


Thumb up

Rémi


On 04/08/2011 04:30 PM, Alan Bateman wrote:
>
> 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