langtools/test/tools/javac/api/taskListeners/CompileEvent.java
changeset 27319 030080f03e4f
parent 26264 a09fedde76be
child 30730 d3ce7619db2c
--- a/langtools/test/tools/javac/api/taskListeners/CompileEvent.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/langtools/test/tools/javac/api/taskListeners/CompileEvent.java	Wed Oct 29 17:25:23 2014 -0700
@@ -73,18 +73,19 @@
         assertOutput(out.toString());
 
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> testFileObjects = fm.getJavaFileObjects(test);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> testFileObjects = fm.getJavaFileObjects(test);
 
-        //test events fired to listeners registered from plugins
-        //when starting compiler using JavaCompiler.getTask(...).call
-        List<String> options =
-                Arrays.asList("-Xplugin:compile-event", "-processorpath", testClasses);
-        out = new StringWriter();
-        boolean compResult = comp.getTask(out, null, null, options, null, testFileObjects).call();
-        if (!compResult)
-            throw new AssertionError("Compilation failed unexpectedly.");
-        assertOutput(out.toString());
+            //test events fired to listeners registered from plugins
+            //when starting compiler using JavaCompiler.getTask(...).call
+            List<String> options =
+                    Arrays.asList("-Xplugin:compile-event", "-processorpath", testClasses);
+            out = new StringWriter();
+            boolean compResult = comp.getTask(out, null, null, options, null, testFileObjects).call();
+            if (!compResult)
+                throw new AssertionError("Compilation failed unexpectedly.");
+            assertOutput(out.toString());
+        }
     }
 
     void assertOutput(String found) {