FULL PRODUCT VERSION :
All Java versions
ADDITIONAL OS VERSION INFORMATION :
All NT-derived Windows versions
A DESCRIPTION OF THE PROBLEM :
Java_java_io_WinNTFileSystem_list in WinNTFileSystem_md.c always removes trailing spaces from directory name.
This behavior is incorrect when the \\?\ prefix is used to bypass Win32 name restrictions.
This is problematic for a number of reasons but crucially it is inconsistent with other File methods which do respect the \\?\ prefix.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test program below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
\\?\C:\cygwin\home\aerofstest\foo true [Ljava.lang.String;...
\\?\C:\cygwin\home\aerofstest\foo \bar true [Ljava.lang.String;...
ACTUAL -
\\?\C:\cygwin\home\aerofstest\foo true null
\\?\C:\cygwin\home\aerofstest\foo \bar true [Ljava.lang.String;...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
public class Test {
public static void main(String[] args) {
File p = new File("\\\\?\\" + new File("foo ").getAbsolutePath());
File c = new File(p, "bar");
File f = new File(c, "baz");
p.mkdir();
c.mkdir();
f.mkdir();
System.out.println(p.getAbsolutePath() + " " + p.exists() + " " + p.list());
System.out.println(c.getAbsolutePath() + " " + c.exists() + " " + c.list());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Proposed fix:
--- a/openjdk/jdk/src/windows/native/java/io/WinNTFileSystem_md.c
+++ b/openjdk/jdk/src/windows/native/java/io/WinNTFileSystem_md.c
@@ -630,8 +630,16 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
/* Remove trailing space chars from directory name */
len = (int)wcslen(search_path);
- while (search_path[len-1] == ' ') {
- len--;
+ /* don't strip trailing whitespaces if \\?\ notation used */
+ if ( ! (len > 4 && search_path[0] == L'\\' &&
+ search_path[1] == L'\\' &&
+ search_path[2] == L'?' &&
+ search_path[3] == L'\\')
+ ) {
+ while (search_path[len-1] == ' ') {
+ len--;
+ }
}
search_path[len] = 0;
NB: as fileToNTPath can add the \\?\ prefix to long paths, backward compatibility requirements may require the check to happen earlier in the method.
All Java versions
ADDITIONAL OS VERSION INFORMATION :
All NT-derived Windows versions
A DESCRIPTION OF THE PROBLEM :
Java_java_io_WinNTFileSystem_list in WinNTFileSystem_md.c always removes trailing spaces from directory name.
This behavior is incorrect when the \\?\ prefix is used to bypass Win32 name restrictions.
This is problematic for a number of reasons but crucially it is inconsistent with other File methods which do respect the \\?\ prefix.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test program below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
\\?\C:\cygwin\home\aerofstest\foo true [Ljava.lang.String;...
\\?\C:\cygwin\home\aerofstest\foo \bar true [Ljava.lang.String;...
ACTUAL -
\\?\C:\cygwin\home\aerofstest\foo true null
\\?\C:\cygwin\home\aerofstest\foo \bar true [Ljava.lang.String;...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
public class Test {
public static void main(String[] args) {
File p = new File("\\\\?\\" + new File("foo ").getAbsolutePath());
File c = new File(p, "bar");
File f = new File(c, "baz");
p.mkdir();
c.mkdir();
f.mkdir();
System.out.println(p.getAbsolutePath() + " " + p.exists() + " " + p.list());
System.out.println(c.getAbsolutePath() + " " + c.exists() + " " + c.list());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Proposed fix:
--- a/openjdk/jdk/src/windows/native/java/io/WinNTFileSystem_md.c
+++ b/openjdk/jdk/src/windows/native/java/io/WinNTFileSystem_md.c
@@ -630,8 +630,16 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
/* Remove trailing space chars from directory name */
len = (int)wcslen(search_path);
- while (search_path[len-1] == ' ') {
- len--;
+ /* don't strip trailing whitespaces if \\?\ notation used */
+ if ( ! (len > 4 && search_path[0] == L'\\' &&
+ search_path[1] == L'\\' &&
+ search_path[2] == L'?' &&
+ search_path[3] == L'\\')
+ ) {
+ while (search_path[len-1] == ' ') {
+ len--;
+ }
}
search_path[len] = 0;
NB: as fileToNTPath can add the \\?\ prefix to long paths, backward compatibility requirements may require the check to happen earlier in the method.