Skip to content

Commit 677572b

Browse files
author
Brian Burkhalter
committed
8372377: Test java/io/File/GetXSpace.java failed: The system cannot find the path specified
Reviewed-by: alanb, jpai
1 parent ec65734 commit 677572b

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

test/jdk/java/io/File/GetXSpace.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,6 @@
4444
import java.util.regex.Matcher;
4545
import java.util.regex.Pattern;
4646
import jdk.test.lib.Platform;
47-
import jdk.test.lib.Platform;
4847

4948
import static java.lang.System.err;
5049
import static java.lang.System.out;
@@ -103,16 +102,11 @@ private static class Space {
103102
private final long free;
104103
private final long available;
105104

106-
Space(String name) {
105+
Space(String name) throws IOException {
107106
this.name = name;
108107
long[] sizes = new long[4];
109108
if (Platform.isWindows() && isCDDrive(name)) {
110-
try {
111-
getCDDriveSpace(name, sizes);
112-
} catch (IOException e) {
113-
e.printStackTrace();
114-
throw new RuntimeException("can't get CDDrive sizes");
115-
}
109+
getCDDriveSpace(name, sizes);
116110
} else {
117111
if (getSpace(name, sizes))
118112
System.err.println("WARNING: total space is estimated");
@@ -170,7 +164,7 @@ private static ArrayList<String> paths() throws IOException {
170164
return al;
171165
}
172166

173-
private static void compare(Space s) {
167+
private static void compare(Space s) throws IOException {
174168
File f = new File(s.name());
175169
long ts = f.getTotalSpace();
176170
long fs = f.getFreeSpace();
@@ -318,7 +312,7 @@ private static void compareZeroExist() {
318312
}
319313
}
320314

321-
private static int testFile(Path dir) {
315+
private static int testFile(Path dir) throws IOException {
322316
String dirName = dir.toString();
323317
out.format("--- Testing %s%n", dirName);
324318
compare(new Space(dir.getRoot().toString()));
@@ -333,10 +327,11 @@ private static int testFile(Path dir) {
333327
return fail != 0 ? 1 : 0;
334328
}
335329

336-
private static int testVolumes() {
330+
private static int testVolumes() throws IOException {
337331
out.println("--- Testing volumes");
338332
// Find all of the partitions on the machine and verify that the sizes
339-
// returned by File::getXSpace are equivalent to those from getSpace or getCDDriveSpace
333+
// returned by File::getXSpace are equivalent to those from getSpace
334+
// or getCDDriveSpace
340335
ArrayList<String> l;
341336
try {
342337
l = paths();
@@ -350,7 +345,18 @@ private static int testVolumes() {
350345
throw new RuntimeException("no partitions?");
351346

352347
for (var p : l) {
353-
Space s = new Space(p);
348+
Space s;
349+
try {
350+
s = new Space(p);
351+
} catch (IOException x) {
352+
// Avoid failing for transient file systems on Windows
353+
if (Platform.isWindows()) {
354+
File f = new File(p);
355+
if (!f.exists())
356+
continue;
357+
}
358+
throw new IOException("Failure for volume " + p, x);
359+
}
354360
compare(s);
355361
compareZeroNonExist();
356362
compareZeroExist();
@@ -408,19 +414,19 @@ public static void main(String[] args) throws Exception {
408414
// size[2] free space: number of free bytes in the volume
409415
// size[3] usable space: number of bytes available to the caller
410416
//
411-
private static native boolean getSpace0(String root, long[] space);
417+
private static native boolean getSpace0(String root, long[] space)
418+
throws IOException;
412419

413420
private static native boolean isCDDrive(String root);
414421

415-
private static boolean getSpace(String root, long[] space) {
422+
private static boolean getSpace(String root, long[] space)
423+
throws IOException {
416424
try {
417425
return getSpace0(root, space);
418-
} catch (RuntimeException e) {
426+
} catch (IOException e) {
419427
File f = new File(root);
420-
boolean exists = f.exists();
421-
boolean readable = f.canRead();
422428
System.err.printf("getSpace0 failed for %s (%s, %s)%n",
423-
root, exists, readable);
429+
root, f.exists(), f.canRead());
424430
throw e;
425431
}
426432
}

test/jdk/java/io/File/libGetXSpace.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -85,7 +85,7 @@ Java_GetXSpace_getSpace0
8585
BOOL hres = pfnGetDiskSpaceInformation(path, &diskSpaceInfo);
8686
(*env)->ReleaseStringChars(env, root, strchars);
8787
if (FAILED(hres)) {
88-
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
88+
JNU_ThrowByNameWithLastError(env, "java/io/IOException",
8989
"GetDiskSpaceInformationW");
9090
return totalSpaceIsEstimated;
9191
}
@@ -113,7 +113,7 @@ Java_GetXSpace_getSpace0
113113
&totalNumberOfBytes, &totalNumberOfFreeBytes);
114114
(*env)->ReleaseStringChars(env, root, strchars);
115115
if (FAILED(hres)) {
116-
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
116+
JNU_ThrowByNameWithLastError(env, "java/io/IOException",
117117
"GetDiskFreeSpaceExW");
118118
return totalSpaceIsEstimated;
119119
}
@@ -131,8 +131,7 @@ Java_GetXSpace_getSpace0
131131
char* chars = (char*)malloc((len + 1)*sizeof(char));
132132
if (chars == NULL) {
133133
(*env)->ReleaseStringChars(env, root, strchars);
134-
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
135-
"malloc");
134+
JNU_ThrowOutOfMemoryError(env, "malloc");
136135
return JNI_FALSE;
137136
}
138137

@@ -146,7 +145,7 @@ Java_GetXSpace_getSpace0
146145
int result = statfs(chars, &buf);
147146
free(chars);
148147
if (result < 0) {
149-
JNU_ThrowByNameWithLastError(env, "java/lang/RuntimeException",
148+
JNU_ThrowByNameWithLastError(env, "java/io/IOException",
150149
strerror(errno));
151150
return totalSpaceIsEstimated;
152151
}

0 commit comments

Comments
 (0)