< prev index next >

test/jdk/java/io/FileOutputStream/UnreferencedFOSClosesFd.java

Print this page
rev 50699 : 8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"

@@ -23,10 +23,12 @@
 
 /**
  *
  * @test
  * @modules java.base/java.io:open
+ * @library /test/lib
+ * @build jdk.test.lib.util.FileUtils UnreferencedFOSClosesFd
  * @bug 6524062
  * @summary Test to ensure that FOS.finalize() invokes the close() method as per
  * the specification.
  * @run main/othervm UnreferencedFOSClosesFd
  */

@@ -39,15 +41,19 @@
 import java.lang.management.OperatingSystemMXBean;
 import java.lang.ref.Reference;
 import java.lang.ref.ReferenceQueue;
 import java.lang.ref.WeakReference;
 import java.lang.reflect.Field;
+import java.nio.file.Path;
+import java.util.ArrayDeque;
 import java.util.HashSet;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import com.sun.management.UnixOperatingSystemMXBean;
 
+import jdk.test.lib.util.FileUtils;
+
 public class UnreferencedFOSClosesFd {
 
     enum CleanupType {
         CLOSE,      // Cleanup is handled via calling close
         CLEANER}    // Cleanup is handled via Cleaner

@@ -131,12 +137,12 @@
         inFile.createNewFile();
         inFile.deleteOnExit();
 
         String name = inFile.getPath();
 
+        FileUtils.listFileDescriptors(System.out);
         long fdCount0 = getFdCount();
-        System.out.printf("initial count of open file descriptors: %d%n", fdCount0);
 
         int failCount = 0;
         failCount += test(new FileOutputStream(name), CleanupType.CLEANER);
 
         failCount += test(new StreamOverrides(name), CleanupType.CLEANER);

@@ -151,14 +157,14 @@
             throw new AssertionError("Failed test count: " + failCount);
         }
 
         // Check the final count of open file descriptors
         long fdCount = getFdCount();
-        System.out.printf("final count of open file descriptors: %d%n", fdCount);
         if (fdCount != fdCount0) {
-            throw new AssertionError("raw fd count wrong: expected: " + fdCount0
-            + ", actual: " + fdCount);
+            System.out.printf("initial count of open file descriptors: %d%n", fdCount0);
+            System.out.printf("final count of open file descriptors: %d%n", fdCount);
+            FileUtils.listFileDescriptors(System.out);
         }
     }
 
     // Get the count of open file descriptors, or -1 if not available
     private static long getFdCount() {
< prev index next >