JDK-7030573 : test/java/io/FileInputStream/LargeFileAvailable.java fails when there is insufficient disk space
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-03-24
  • Updated: 2017-09-14
  • Resolved: 2012-05-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u21Fixed 8 b23Fixed
Description
The test attempts to create a 7GB file in the temporary file directory. It would be better if this test were changed to create the file in the working directory and in addition, check the free disk space so that it passes when there is insufficient disk space available.



TEST: java/io/FileInputStream/LargeFileAvailable.java
JDK under test: (/tmp/jprt/P4/T/003103.ss145989/testproduct/solaris_sparc_5.10-product)
java version "1.7.0-internal"
Java(TM) SE Runtime Environment (build 1.7.0-internal-201103220031.ss145989.tl-pit-2d-awt-swin-b00)
Java HotSpot(TM) Client VM (build 21.0-b04, mixed mode)

ACTION: build -- Passed. Build successful
REASON: Named class compiled on demand
TIME:   0.089 seconds
messages:
command: build LargeFileAvailable
reason: Named class compiled on demand
elapsed time (seconds): 0.089

ACTION: compile -- Passed. Compilation successful
REASON: .class file out of date or does not exist
TIME:   0.089 seconds
messages:
command: compile /tmp/jprt/P4/T/003103.ss145989/source/jdk/test/java/io/FileInputStream/LargeFileAvailable.java
reason: .class file out of date or does not exist
elapsed time (seconds): 0.089

ACTION: main -- Failed. Execution failed: `main' threw exception: java.io.IOException: No space left on device
REASON: Assumed action based on file name: run main LargeFileAvailable 
TIME:   0.026 seconds
messages:
command: main LargeFileAvailable
reason: Assumed action based on file name: run main LargeFileAvailable 
elapsed time (seconds): 0.026
STDOUT:
STDERR:
java.io.IOException: No space left on device
	at sun.nio.ch.FileDispatcherImpl.pwrite0(Native Method)
	at sun.nio.ch.FileDispatcherImpl.pwrite(FileDispatcherImpl.java:65)
	at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:86)
	at sun.nio.ch.IOUtil.write(IOUtil.java:61)
	at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:700)
	at LargeFileAvailable.createLargeFile(LargeFileAvailable.java:95)
	at LargeFileAvailable.main(LargeFileAvailable.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:613)
	at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
	at java.lang.Thread.run(Thread.java:722)

JavaTest Message: Test threw exception: java.io.IOException
JavaTest Message: shutting down test


TEST RESULT: Failed. Execution failed: `main' threw exception: java.io.IOException: No space left on device
--------------------------------------------------

Comments
EVALUATION http://hg.openjdk.java.net/jdk8/tl/jdk/rev/74c92c3e66ad
09-01-2012

SUGGESTED FIX If there isn't 7G available for a temp file, use the space that is available. diff --git a/test/java/io/FileInputStream/LargeFileAvailable.java b/test/java/io/FileInputStream/LargeFileAvailable.java --- a/test/java/io/FileInputStream/LargeFileAvailable.java +++ b/test/java/io/FileInputStream/LargeFileAvailable.java @@ -35,15 +35,15 @@ import static java.nio.file.StandardOpenOption.*; public class LargeFileAvailable { - private static final long FILESIZE = 7405576182L; public static void main(String args[]) throws Exception { + long FILESIZE = maxLargeFile(7405576182L); File file = createLargeFile(FILESIZE); try (FileInputStream fis = new FileInputStream(file)) { if (file.length() != FILESIZE) { throw new RuntimeException("unexpected file size = " + file.length()); } - long bigSkip = 3110608882L; + long bigSkip = (FILESIZE == 7405576182L ? 3110608882L : FILESIZE/2); long remaining = FILESIZE; remaining -= skipBytes(fis, bigSkip, remaining); remaining -= skipBytes(fis, 10L, remaining); @@ -82,9 +82,20 @@ return skip; } + private static long maxLargeFile (long filesize) throws Exception { + // Determine if less than 7G is available for a large temp file. + File largefile = File.createTempFile("largefile", null); + long spaceavailable = largefile.getUsableSpace(); + Files.delete(largefile.toPath()); + return spaceavailable < filesize + ? spaceavailable + : filesize ; + } + private static File createLargeFile(long filesize) throws Exception { // Create a large file as a sparse file if possible File largefile = File.createTempFile("largefile", null); + // re-create as a sparse file Files.delete(largefile.toPath()); try (FileChannel fc = @@ -93,6 +104,7 @@ ByteBuffer bb = ByteBuffer.allocate(1).put((byte)1); bb.rewind(); int rc = fc.write(bb, filesize-1); + if (rc != 1) { throw new RuntimeException("Failed to write 1 byte to the large file"); }
23-12-2011

EVALUATION Test should not assume that there is sufficient space for a 7G temp file. If less space is available, then use what is available.
23-12-2011