--- old/test/jdk/java/io/File/GetXSpace.java 2020-07-31 10:41:22.000000000 -0700 +++ new/test/jdk/java/io/File/GetXSpace.java 2020-07-31 10:41:22.000000000 -0700 @@ -35,6 +35,7 @@ import java.io.FilePermission; import java.io.InputStreamReader; import java.io.IOException; +import java.nio.file.Files; import java.security.Permission; import java.util.ArrayList; import java.util.regex.Matcher; @@ -47,9 +48,12 @@ private static SecurityManager [] sma = { null, new Allow(), new DenyFSA(), new DenyRead() }; - private static final String osName = System.getProperty("os.name"); + private static final String OS_NAME = System.getProperty("os.name"); + private static final boolean IS_MAC = OS_NAME.startsWith("Mac"); + private static final boolean IS_WIN = OS_NAME.startsWith("Windows"); + // FileSystem Total Used Available Use% MountedOn - private static final Pattern dfPattern = Pattern.compile("([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s].*)\n"); + private static final Pattern DF_PATTERN = Pattern.compile("([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s].*)\n"); private static int fail = 0; private static int pass = 0; @@ -129,7 +133,7 @@ } out.println(sb); - Matcher m = dfPattern.matcher(sb); + Matcher m = DF_PATTERN.matcher(sb); int j = 0; while (j < sb.length()) { if (m.find(j)) { @@ -138,7 +142,7 @@ String name = f; if (name == null) { // cygwin's df lists windows path as FileSystem (1st group) - name = osName.startsWith("Windows") ? m.group(1) : m.group(4); + name = IS_WIN ? m.group(1) : m.group(4); } al.add(new Space(m.group(2), m.group(3), name));; } @@ -201,13 +205,25 @@ // if the file system can dynamically change size, this check will fail if (ts != s.total()) { - fail(s.name(), s.total(), "!=", ts); + long bs = 1; + try { + bs = Files.getFileStore(f.toPath()).getBlockSize(); + } catch (IOException e) { + throw new RuntimeException(e); + } + // On macOS, the number of 1024 byte blocks might be incorrectly + // calculated by 'df' using integer division by 2 of the number of + // 512 byte blocks, resulting in a size smaller than the actual + // value when the number of blocks is odd. + if (!IS_MAC || bs != 512 || ts - s.total() != 512) { + fail(s.name(), s.total(), "!=", ts); + } } else { pass(); } // unix df returns statvfs.f_bavail - long tsp = (!osName.startsWith("Windows") ? us : fs); + long tsp = (!IS_WIN ? us : fs); if (!s.woomFree(tsp)) { fail(s.name(), s.free(), "??", tsp); } else {