-
Bug
-
Resolution: Fixed
-
P4
-
5.0
-
b73
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
EXTRA RELEVANT SYSTEM CONFIGURATION :
NTFS filesystem
A DESCRIPTION OF THE PROBLEM :
When obtaining a list of files on "C:/", the listFiles() method returns files which, when exists() is called, returns false.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This is noticeable on the hiberfil.sys file on the root of C:. If you don't have this file, you probably won't be able to reproduce the problem unless you find a file which behaves similarly.
Compile and run the provided sample program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should show "exists" next to every file in the list.
ACTUAL -
The file "C:\hiberfil.sys" says "DOES NOT EXIST", as File.exists() returned false for that file, despite it having been returned in File.listFiles()
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main (String args[]) {
File root = new File("C:\\");
System.out.println("Root is " + root);
File[] dir = root.listFiles();
for (int i = 0; i < dir.length; i++) {
System.out.print(" dir[" + i + "] = " + dir[i] + " ");
if (dir[i].exists()) {
System.out.println("exists");
} else {
System.out.println("DOES NOT EXIST!");
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
It's ugly, but there are two options.
Option one, have a way to return a File array which is already sanitised:
public static File[] listFilesFixed(File parent) {
File[] list = parent.listFiles();
List fixedList = new ArrayList();
for (int i = 0; i < list.length; i++) {
if (list[i].exists()) {
fixedList.add(list[i]);
}
}
return (File[]) fixedList.toArray(new File[fixedList.size()]);
}
Option two is to take the result of listFiles() with a shaker of salt, and check exists() on every single file in the list.
###@###.### 2004-11-08 21:08:40 GMT
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
EXTRA RELEVANT SYSTEM CONFIGURATION :
NTFS filesystem
A DESCRIPTION OF THE PROBLEM :
When obtaining a list of files on "C:/", the listFiles() method returns files which, when exists() is called, returns false.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This is noticeable on the hiberfil.sys file on the root of C:. If you don't have this file, you probably won't be able to reproduce the problem unless you find a file which behaves similarly.
Compile and run the provided sample program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should show "exists" next to every file in the list.
ACTUAL -
The file "C:\hiberfil.sys" says "DOES NOT EXIST", as File.exists() returned false for that file, despite it having been returned in File.listFiles()
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main (String args[]) {
File root = new File("C:\\");
System.out.println("Root is " + root);
File[] dir = root.listFiles();
for (int i = 0; i < dir.length; i++) {
System.out.print(" dir[" + i + "] = " + dir[i] + " ");
if (dir[i].exists()) {
System.out.println("exists");
} else {
System.out.println("DOES NOT EXIST!");
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
It's ugly, but there are two options.
Option one, have a way to return a File array which is already sanitised:
public static File[] listFilesFixed(File parent) {
File[] list = parent.listFiles();
List fixedList = new ArrayList();
for (int i = 0; i < list.length; i++) {
if (list[i].exists()) {
fixedList.add(list[i]);
}
}
return (File[]) fixedList.toArray(new File[fixedList.size()]);
}
Option two is to take the result of listFiles() with a shaker of salt, and check exists() on every single file in the list.
###@###.### 2004-11-08 21:08:40 GMT
- relates to
-
JDK-8133105 Fix getFinalAttributes() on Windows to handle more special cases
-
- Closed
-
-
JDK-7115487 TEST: java/io/File/WinSpecialFiles.java test failes on 1.4.2 (win only related)
-
- Resolved
-