8026233: test/sun/security/tools/keytool/StorePasswords.java needs to clean up files
authorjuh
Thu, 17 Oct 2013 12:00:20 -0700
changeset 20879 05811931e266
parent 20878 ee92cf5c8888
child 20880 1b610151b316
8026233: test/sun/security/tools/keytool/StorePasswords.java needs to clean up files Reviewed-by: vinnie
jdk/test/sun/security/tools/keytool/StorePasswords.java
--- a/jdk/test/sun/security/tools/keytool/StorePasswords.java	Thu Oct 17 11:43:44 2013 -0700
+++ b/jdk/test/sun/security/tools/keytool/StorePasswords.java	Thu Oct 17 12:00:20 2013 -0700
@@ -77,6 +77,8 @@
         }
         System.out.println("\nStored " + storeCount + " user passwords, " +
             "recovered " + recoverCount + " user passwords");
+
+        new File(KEYSTORE).delete();
     }
 
     private static int store() throws Exception {
@@ -144,7 +146,9 @@
 
         // Store the PKCS#12 keystore
         System.out.println("Storing PKCS#12 keystore to: " + KEYSTORE);
-        keystore.store(new FileOutputStream(KEYSTORE), KEYSTORE_PWD);
+        try (FileOutputStream out = new FileOutputStream(KEYSTORE)) {
+            keystore.store(out, KEYSTORE_PWD);
+        }
 
         return count;
     }
@@ -154,7 +158,9 @@
         // Load the PKCS#12 keystore
         KeyStore keystore = KeyStore.getInstance("PKCS12");
         System.out.println("\nLoading PKCS#12 keystore from: " + KEYSTORE);
-        keystore.load(new FileInputStream(KEYSTORE), KEYSTORE_PWD);
+        try (FileInputStream in = new FileInputStream(KEYSTORE)) {
+            keystore.load(in, KEYSTORE_PWD);
+        }
 
         SecretKey key;
         SecretKeyFactory factory;