langtools/test/tools/javac/api/T6357331.java
changeset 27319 030080f03e4f
parent 26264 a09fedde76be
child 30730 d3ce7619db2c
--- a/langtools/test/tools/javac/api/T6357331.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/langtools/test/tools/javac/api/T6357331.java	Wed Oct 29 17:25:23 2014 -0700
@@ -33,42 +33,43 @@
 
 public class T6357331
 {
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
         PrintWriter out = new PrintWriter(new StringWriter());
         List<String> opts = Arrays.asList("-d", ".");
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File thisFile = new File(System.getProperty("test.src"), "T6357331.java");
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
-        final JavacTask task = (JavacTask) (tool.getTask(out, fm, null, opts, null, files));
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File thisFile = new File(System.getProperty("test.src"), "T6357331.java");
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
+            final JavacTask task = (JavacTask) (tool.getTask(out, fm, null, opts, null, files));
 
-        // set a listener to verify that IllegalStateException is not thrown
-        // during the compilation
-        task.setTaskListener(new TaskListener() {
-                public void started(TaskEvent e) {
-                    task.getElements();
-                    task.getTypes();
-                }
-                public void finished(TaskEvent e) { }
-            });
+            // set a listener to verify that IllegalStateException is not thrown
+            // during the compilation
+            task.setTaskListener(new TaskListener() {
+                    public void started(TaskEvent e) {
+                        task.getElements();
+                        task.getTypes();
+                    }
+                    public void finished(TaskEvent e) { }
+                });
+
+            task.call();
 
-        task.call();
+            // now the compilation is over, we expect IllegalStateException (not NPE)
+            try {
+                task.getElements();
+                throw new AssertionError("IllegalStateException not thrown");
+            }
+            catch (IllegalStateException e) {
+                // expected
+            }
 
-        // now the compilation is over, we expect IllegalStateException (not NPE)
-        try {
-            task.getElements();
-            throw new AssertionError("IllegalStateException not thrown");
-        }
-        catch (IllegalStateException e) {
-            // expected
-        }
-
-        try {
-            task.getTypes();
-            throw new AssertionError("IllegalStateException not thrown");
-        }
-        catch (IllegalStateException e) {
-            // expected
+            try {
+                task.getTypes();
+                throw new AssertionError("IllegalStateException not thrown");
+            }
+            catch (IllegalStateException e) {
+                // expected
+            }
         }
     }
 }