test/java/util/zip/ZipFile/ReadAfterClose.java

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

*** 32,45 **** import java.io.*; import java.util.*; public class ReadAfterClose { public static void main(String[] argv) throws Exception { ! ZipFile zf = new ZipFile(new File(System.getProperty("test.src","."),"crash.jar")); ZipEntry zent = zf.getEntry("Test.java"); ! InputStream in = zf.getInputStream(zent); ! zf.close(); try { in.read(); } catch (IOException e) { return; } --- 32,48 ---- import java.io.*; import java.util.*; public class ReadAfterClose { public static void main(String[] argv) throws Exception { ! InputStream in; ! try (ZipFile zf = new ZipFile( ! new File(System.getProperty("test.src","."),"crash.jar"))) { ZipEntry zent = zf.getEntry("Test.java"); ! in = zf.getInputStream(zent); ! } ! // ensure zf is closed at this point try { in.read(); } catch (IOException e) { return; }