langtools/test/tools/javac/T6395974.java
changeset 27319 030080f03e4f
parent 24898 88fa65d2ac87
child 30730 d3ce7619db2c
--- a/langtools/test/tools/javac/T6395974.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/langtools/test/tools/javac/T6395974.java	Wed Oct 29 17:25:23 2014 -0700
@@ -44,24 +44,25 @@
         String testSrc = System.getProperty("test.src");
 
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        Iterable<?extends JavaFileObject> f =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self + ".java")));
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            Iterable<?extends JavaFileObject> f =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self + ".java")));
 
-        PrintWriter out = new PrintWriter(System.err, true);
+            PrintWriter out = new PrintWriter(System.err, true);
 
-        JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out,
-                                                          fm,
-                                                          null,
-                                                          Arrays.asList("-processor",
-                                                                        "Foo.java"),
-                                                          null,
-                                                          f);
+            JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out,
+                                                              fm,
+                                                              null,
+                                                              Arrays.asList("-processor",
+                                                                            "Foo.java"),
+                                                              null,
+                                                              f);
 
-        MyTaskListener tl = new MyTaskListener();
-        task.setTaskListener(tl);
+            MyTaskListener tl = new MyTaskListener();
+            task.setTaskListener(tl);
 
-        task.call();
+            task.call();
+        }
     }
 
     static class MyTaskListener implements TaskListener {