6908541: Bad resource management in java/math/BigInteger/BigIntegerTest.java
authordarcy
Tue, 22 Dec 2009 21:48:19 -0800
changeset 4527 f95d12f08613
parent 4526 158aca5e2b0c
child 4528 395130ccd03a
6908541: Bad resource management in java/math/BigInteger/BigIntegerTest.java Reviewed-by: alanb
jdk/test/ProblemList.txt
jdk/test/java/math/BigInteger/BigIntegerTest.java
--- a/jdk/test/ProblemList.txt	Sat Dec 19 10:26:19 2009 -0800
+++ b/jdk/test/ProblemList.txt	Tue Dec 22 21:48:19 2009 -0800
@@ -499,10 +499,6 @@
 # Problems with rounding add failures on solaris-sparcv9 and -server
 java/math/BigDecimal/AddTests.java			 	solaris-sparcv9
 
-# Problems on windows with samevm, missing inputstream close()?
-# Also times out on solaris-sparcv9 -server
-java/math/BigInteger/BigIntegerTest.java		 	generic-all
-
 # Should be samevm? But seems problematic with samevm on windows
 java/math/BigInteger/ModPow65537.java			 	generic-all
 
--- a/jdk/test/java/math/BigInteger/BigIntegerTest.java	Sat Dec 19 10:26:19 2009 -0800
+++ b/jdk/test/java/math/BigInteger/BigIntegerTest.java	Tue Dec 22 21:48:19 2009 -0800
@@ -642,37 +642,71 @@
 
         for(int i = 0; i < bitPatterns.length; i++) {
             BigInteger b1 = new BigInteger(bitPatterns[i], 16);
+            BigInteger b2 = null;
 
             File f = new File("serialtest");
             FileOutputStream fos = new FileOutputStream(f);
-            ObjectOutputStream oos = new ObjectOutputStream(fos);
-            oos.writeObject(b1);
-            oos.flush();
-            oos.close();
-            FileInputStream fis = new FileInputStream(f);
-            ObjectInputStream ois = new ObjectInputStream(fis);
-            BigInteger b2 = (BigInteger)ois.readObject();
+            try {
+                ObjectOutputStream oos = new ObjectOutputStream(fos);
+                try {
+                    oos.writeObject(b1);
+                    oos.flush();
+                } finally {
+                    oos.close();
+                }
 
-            if (!b1.equals(b2) ||
-                !b1.equals(b1.or(b2))) {
-                failCount++;
-                System.err.println("Serialized failed for hex " +
-                                   b1.toString(16));
+                FileInputStream fis = new FileInputStream(f);
+                try {
+                    ObjectInputStream ois = new ObjectInputStream(fis);
+                    try {
+                        b2 = (BigInteger)ois.readObject();
+                    } finally {
+                        ois.close();
+                    }
+                } finally {
+                    fis.close();
+                }
+
+                if (!b1.equals(b2) ||
+                    !b1.equals(b1.or(b2))) {
+                    failCount++;
+                    System.err.println("Serialized failed for hex " +
+                                       b1.toString(16));
+                }
+            } finally {
+                fos.close();
             }
             f.delete();
         }
 
         for(int i=0; i<10; i++) {
             BigInteger b1 = fetchNumber(rnd.nextInt(100));
+            BigInteger b2 = null;
             File f = new File("serialtest");
             FileOutputStream fos = new FileOutputStream(f);
-            ObjectOutputStream oos = new ObjectOutputStream(fos);
-            oos.writeObject(b1);
-            oos.flush();
-            oos.close();
-            FileInputStream fis = new FileInputStream(f);
-            ObjectInputStream ois = new ObjectInputStream(fis);
-            BigInteger b2 = (BigInteger)ois.readObject();
+            try {
+                ObjectOutputStream oos = new ObjectOutputStream(fos);
+                try {
+                    oos.writeObject(b1);
+                    oos.flush();
+                } finally {
+                    oos.close();
+                }
+
+                FileInputStream fis = new FileInputStream(f);
+                try {
+                    ObjectInputStream ois = new ObjectInputStream(fis);
+                    try {
+                        b2 = (BigInteger)ois.readObject();
+                    } finally {
+                        ois.close();
+                    }
+                } finally {
+                    fis.close();
+                }
+            } finally {
+                fos.close();
+            }
 
             if (!b1.equals(b2) ||
                 !b1.equals(b1.or(b2)))