langtools/test/tools/javac/api/T6358955.java
changeset 27319 030080f03e4f
parent 5520 86e4b9a9da40
child 30730 d3ce7619db2c
--- a/langtools/test/tools/javac/api/T6358955.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/langtools/test/tools/javac/api/T6358955.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,34 +36,35 @@
 public class T6358955 {
     public static void main(String[] args) throws Exception {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null)) {
 
-        File dir = new File("temp" + args.hashCode());
-        if (!dir.exists())
-            dir.mkdir();
-        if (!dir.isDirectory())
-            throw new AssertionError("Not a directory " + dir);
+            File dir = new File("temp" + args.hashCode());
+            if (!dir.exists())
+                dir.mkdir();
+            if (!dir.isDirectory())
+                throw new AssertionError("Not a directory " + dir);
 
-        try {
-            jfm.setLocation(StandardLocation.CLASS_OUTPUT,
-                            Arrays.asList(dir.getCanonicalFile().getParentFile()));
             try {
-                jfm.getFileForInput(StandardLocation.CLASS_OUTPUT, "", dir.getPath());
-                throw new AssertionError("IllegalArgumentException not thrown");
-            } catch (IllegalArgumentException e) {
-                System.out.println("OK: " + e.getLocalizedMessage());
-            }
-            try {
-                jfm.getJavaFileObjectsFromFiles(Arrays.asList(dir));
-                throw new AssertionError("IllegalArgumentException not thrown");
-            } catch (IllegalArgumentException e) {
-                System.out.println("OK: " + e.getLocalizedMessage());
-            }
-        } finally {
-            try {
-                dir.delete(); // cleanup
-            } catch (Throwable t) {
-                t.printStackTrace();
+                jfm.setLocation(StandardLocation.CLASS_OUTPUT,
+                                Arrays.asList(dir.getCanonicalFile().getParentFile()));
+                try {
+                    jfm.getFileForInput(StandardLocation.CLASS_OUTPUT, "", dir.getPath());
+                    throw new AssertionError("IllegalArgumentException not thrown");
+                } catch (IllegalArgumentException e) {
+                    System.out.println("OK: " + e.getLocalizedMessage());
+                }
+                try {
+                    jfm.getJavaFileObjectsFromFiles(Arrays.asList(dir));
+                    throw new AssertionError("IllegalArgumentException not thrown");
+                } catch (IllegalArgumentException e) {
+                    System.out.println("OK: " + e.getLocalizedMessage());
+                }
+            } finally {
+                try {
+                    dir.delete(); // cleanup
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                }
             }
         }
     }