RFR: 8343342: java/io/File/GetXSpace.java fails on Windows with CD-ROM drive

Brian Burkhalter bpb at openjdk.org
Thu Nov 28 00:44:39 UTC 2024


On Thu, 28 Nov 2024 00:03:32 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> If there were also a simpler way to handle the empty drive case, that would be good.

Actually this simple patch appears to fix the problem with a CD drive attached whether it is empty or contains a CD:

--- a/test/jdk/java/io/File/GetXSpace.java
+++ b/test/jdk/java/io/File/GetXSpace.java
@@ -152,8 +152,10 @@ private static void diskFree() throws IOException {
         File[] roots = File.listRoots();
         long[] space = new long[4];
         for (File root : roots) {
-            String path = root.toString();
-            al.add(path);
+            if (root.canRead()) {
+                String path = root.toString();
+                al.add(path);
+            }
         }
 
         return al;
diff --git a/test/jdk/java/io/File/libGetXSpace.c b/test/jdk/java/io/File/libGetXSpace.c
index a4e36bd2431..0435e62ca74 100644
--- a/test/jdk/java/io/File/libGetXSpace.c
+++ b/test/jdk/java/io/File/libGetXSpace.c
@@ -78,8 +78,9 @@ Java_GetXSpace_getSpace0
     }
 
     LPCWSTR path = (LPCWSTR)strchars;
+    UINT driveType = GetDriveTypeW(path);
 
-    if (pfnGetDiskSpaceInformation != NULL) {
+    if (pfnGetDiskSpaceInformation != NULL && driveType != DRIVE_CDROM) {
         // use GetDiskSpaceInformationW
         DISK_SPACE_INFORMATION diskSpaceInfo;
         BOOL hres = pfnGetDiskSpaceInformation(path, &diskSpaceInfo);

-------------

PR Comment: https://git.openjdk.org/jdk/pull/21799#issuecomment-2505052993


More information about the core-libs-dev mailing list