# HG changeset patch # User aghaisas # Date 1500877497 -19800 # Node ID fbf6574581005e8f41a0b1a1d7411d4fb8383553 # Parent ac5434728c3b6e7ae2276096747ac9c7e34daa75 8183341: Better cleanup for javax/imageio/AllowSearch.java Reviewed-by: prr, jdv, pnarayanan Contributed-by: shashidhara.veerabhadraiah@oracle.com diff -r ac5434728c3b -r fbf657458100 jdk/test/javax/imageio/AllowSearch.java --- a/jdk/test/javax/imageio/AllowSearch.java Fri Jul 21 16:27:35 2017 -0700 +++ b/jdk/test/javax/imageio/AllowSearch.java Mon Jul 24 11:54:57 2017 +0530 @@ -23,7 +23,7 @@ /* * @test - * @bug 4420318 + * @bug 4420318 8183341 * @summary Checks that an IllegalStateException is thrown by getNumImages(true) * when seekForwardOnly is true * @modules java.desktop/com.sun.imageio.plugins.gif @@ -33,6 +33,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; import javax.imageio.ImageIO; import javax.imageio.ImageReader; @@ -43,20 +44,33 @@ import com.sun.imageio.plugins.png.PNGImageReader; public class AllowSearch { - private static void test(ImageReader reader, String format) throws IOException { - File f = File.createTempFile("imageio", ".tmp"); - ImageInputStream stream = ImageIO.createImageInputStream(f); - reader.setInput(stream, true); - boolean gotISE = false; + File f = null; + ImageInputStream stream = null; try { - int numImages = reader.getNumImages(true); - } catch (IOException ioe) { - gotISE = false; - } catch (IllegalStateException ise) { - gotISE = true; + f = File.createTempFile("imageio", ".tmp"); + stream = ImageIO.createImageInputStream(f); + reader.setInput(stream, true); + + try { + int numImages = reader.getNumImages(true); + } catch (IOException ioe) { + gotISE = false; + } catch (IllegalStateException ise) { + gotISE = true; + } + } finally { + if (stream != null) { + stream.close(); + } + + reader.dispose(); + + if (f != null) { + Files.delete(f.toPath()); + } } if (!gotISE) {