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
4444import java .util .regex .Matcher ;
4545import java .util .regex .Pattern ;
4646import jdk .test .lib .Platform ;
47- import jdk .test .lib .Platform ;
4847
4948import static java .lang .System .err ;
5049import 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 }
0 commit comments