test/java/util/zip/ZipFile/EnumAfterClose.java

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

@@ -31,14 +31,16 @@
 import java.util.zip.*;
 import java.util.Enumeration;
 
 public class EnumAfterClose {
     public static void main(String args[]) throws Exception {
-        ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
-                                          "input.zip"));
-        Enumeration e = zf.entries();
-        zf.close();
+        Enumeration e;
+        try (ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
+                                               "input.zip"))) {
+            e = zf.entries();
+        }
+        // ensure that the ZipFile is closed before checking the Enumeration
         try {
             if (e.hasMoreElements()) {
                 ZipEntry ze = (ZipEntry)e.nextElement();
             }
         } catch (IllegalStateException ie) {