test/java/util/jar/JarEntry/GetMethodsReturnClones.java

Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: XXX

@@ -38,26 +38,25 @@
 
     private final static String BASE = System.getProperty("test.src", ".") +
         System.getProperty("file.separator");
 
     public static void main(String[] args) throws Exception {
-        JarFile jf = new JarFile(BASE + "test.jar", true);
-
+        List<JarEntry> entries = new ArrayList<JarEntry>();
+        try (JarFile jf = new JarFile(BASE + "test.jar", true)) {
         byte[] buffer = new byte[8192];
         Enumeration<JarEntry> e = jf.entries();
-        List<JarEntry> entries = new ArrayList<JarEntry>();
         while (e.hasMoreElements()) {
             JarEntry je = e.nextElement();
             entries.add(je);
-            InputStream is = jf.getInputStream(je);
+                try (InputStream is = jf.getInputStream(je)) {
             while (is.read(buffer, 0, buffer.length) != -1) {
                 // we just read. this will throw a SecurityException
                 // if  a signature/digest check fails.
             }
-            is.close();
         }
-        jf.close();
+            }
+        }
 
         for (JarEntry je : entries) {
             Certificate[] certs = je.getCertificates();
             CodeSigner[] signers = je.getCodeSigners();
             if (certs != null) {