--- old/src/java.base/share/classes/java/io/File.java 2019-10-17 10:29:12.000000000 -0700 +++ new/src/java.base/share/classes/java/io/File.java 2019-10-17 10:29:12.000000000 -0700 @@ -29,6 +29,7 @@ import java.net.URL; import java.net.MalformedURLException; import java.net.URISyntaxException; +import java.nio.file.FileStore; import java.nio.file.FileSystems; import java.nio.file.Path; import java.security.SecureRandom; @@ -1798,7 +1799,9 @@ /** * Returns the size of the partition named by this - * abstract pathname. + * abstract pathname. If the total number of bytes in the partition is + * greater than {@link Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be + * returned. * * @return The size, in bytes, of the partition or {@code 0L} if this * abstract pathname does not name a partition @@ -1810,6 +1813,7 @@ * read access to the file named by this abstract pathname * * @since 1.6 + * @see FileStore#getTotalSpace */ public long getTotalSpace() { SecurityManager sm = System.getSecurityManager(); @@ -1820,12 +1824,15 @@ if (isInvalid()) { return 0L; } - return fs.getSpace(this, FileSystem.SPACE_TOTAL); + long space = fs.getSpace(this, FileSystem.SPACE_TOTAL); + return space >= 0L ? space : Long.MAX_VALUE; } /** * Returns the number of unallocated bytes in the partition named by this abstract path name. + * href="#partName">named by this abstract path name. If the + * number of unallocated bytes in the partition is greater than + * {@link Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be returned. * *

The returned number of unallocated bytes is a hint, but not * a guarantee, that it is possible to use most or any of these @@ -1848,6 +1855,7 @@ * read access to the file named by this abstract pathname * * @since 1.6 + * @see FileStore#getUnallocatedSpace */ public long getFreeSpace() { SecurityManager sm = System.getSecurityManager(); @@ -1858,16 +1866,19 @@ if (isInvalid()) { return 0L; } - return fs.getSpace(this, FileSystem.SPACE_FREE); + long space = fs.getSpace(this, FileSystem.SPACE_FREE); + return space >= 0L ? space : Long.MAX_VALUE; } /** * Returns the number of bytes available to this virtual machine on the - * partition named by this abstract pathname. When - * possible, this method checks for write permissions and other operating - * system restrictions and will therefore usually provide a more accurate - * estimate of how much new data can actually be written than {@link - * #getFreeSpace}. + * partition named by this abstract pathname. If + * the number of available bytes in the partition is greater than + * {@link Long#MAX_VALUE}, then {@code Long.MAX_VALUE} will be returned. + * When possible, this method checks for write permissions and other + * operating system restrictions and will therefore usually provide a more + * accurate estimate of how much new data can actually be written than + * {@link #getFreeSpace}. * *

The returned number of available bytes is a hint, but not a * guarantee, that it is possible to use most or any of these bytes. The @@ -1889,6 +1900,7 @@ * read access to the file named by this abstract pathname * * @since 1.6 + * @see FileStore#getUsableSpace */ public long getUsableSpace() { SecurityManager sm = System.getSecurityManager(); @@ -1899,7 +1911,8 @@ if (isInvalid()) { return 0L; } - return fs.getSpace(this, FileSystem.SPACE_USABLE); + long space = fs.getSpace(this, FileSystem.SPACE_USABLE); + return space >= 0L ? space : Long.MAX_VALUE; } /* -- Temporary files -- */