8144294: jdk/security/jarsigner/Function.java failed to clean up files after test on Windows
authorweijun
Tue, 01 Dec 2015 15:07:10 +0800
changeset 34356 5390ced223f0
parent 34355 3e63290b299a
child 34357 231fdaed751a
8144294: jdk/security/jarsigner/Function.java failed to clean up files after test on Windows Reviewed-by: xuelei
jdk/test/jdk/security/jarsigner/Function.java
--- a/jdk/test/jdk/security/jarsigner/Function.java	Tue Dec 01 10:02:06 2015 +0800
+++ b/jdk/test/jdk/security/jarsigner/Function.java	Tue Dec 01 15:07:10 2015 +0800
@@ -71,13 +71,17 @@
                         " -keypass changeit -dname" +
                         " CN=RSA -alias r -genkeypair -keyalg rsa").split(" "));
 
-        KeyStore ks = KeyStore.getInstance("JKS");
-        ks.load(new FileInputStream("ks"), "changeit".toCharArray());
-        PrivateKey key = (PrivateKey)ks.getKey("r", "changeit".toCharArray());
-        Certificate cert = ks.getCertificate("r");
-        JarSigner.Builder jsb = new JarSigner.Builder(key,
-                CertificateFactory.getInstance("X.509").generateCertPath(
-                        Collections.singletonList(cert)));
+        JarSigner.Builder jsb;
+
+        try (FileInputStream fis = new FileInputStream("ks")) {
+            KeyStore ks = KeyStore.getInstance("JKS");
+            ks.load(fis, "changeit".toCharArray());
+            PrivateKey key = (PrivateKey)ks.getKey("r", "changeit".toCharArray());
+            Certificate cert = ks.getCertificate("r");
+            jsb = new JarSigner.Builder(key,
+                    CertificateFactory.getInstance("X.509").generateCertPath(
+                            Collections.singletonList(cert)));
+        }
 
         jsb.digestAlgorithm("SHA1");
         jsb.signatureAlgorithm("SHA1withRSA");