changeset 13148:b14c6fa78b4c

8144294: jdk/security/jarsigner/Function.java failed to clean up files after test on Windows Reviewed-by: xuelei
author weijun
date Tue, 01 Dec 2015 15:07:10 +0800
parents 6d129115a8ed
children 8c9484fe1bb2
files test/jdk/security/jarsigner/Function.java
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/security/jarsigner/Function.java	Tue Dec 01 10:02:06 2015 +0800
+++ b/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");