changeset 2687:56f8be952a5c

8062348: langtools tests should close file manager (group 1) Reviewed-by: darcy
author jjg
date Wed, 29 Oct 2014 17:25:23 -0700
parents 82acac4e6d0d
children b0b7c051d199
files test/tools/all/RunCodingRules.java test/tools/javac/6341866/T6341866.java test/tools/javac/6400872/T6400872.java test/tools/javac/6402516/Checker.java test/tools/javac/6440583/T6440583.java test/tools/javac/6902720/Test.java test/tools/javac/7003595/T7003595.java test/tools/javac/7079713/TestCircularClassfile.java test/tools/javac/7142086/T7142086.java test/tools/javac/NoStringToLower.java test/tools/javac/Paths/6638501/JarFromManifestFailure.java test/tools/javac/Paths/TestCompileJARInClassPath.java test/tools/javac/T6265400.java test/tools/javac/T6340549.java test/tools/javac/T6351767.java test/tools/javac/T6361619.java test/tools/javac/T6395974.java test/tools/javac/T6397044.java test/tools/javac/T6397286.java test/tools/javac/T6403466.java test/tools/javac/T6406771.java test/tools/javac/T6407066.java test/tools/javac/T6410706.java test/tools/javac/T6458823/T6458823.java test/tools/javac/T6665791.java test/tools/javac/T6705935.java test/tools/javac/T6900149.java test/tools/javac/T6956462/T6956462.java test/tools/javac/T6956638.java test/tools/javac/T7142672/Bug.java test/tools/javac/T7159016.java test/tools/javac/T8003967/DetectMutableStaticFields.java test/tools/javac/T8010737/ParameterNamesAreNotCopiedToAnonymousInitTest.java test/tools/javac/TryWithResources/InterruptedExceptionTest.java test/tools/javac/TryWithResources/UnusedResourcesTest.java test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.java test/tools/javac/annotations/repeatingAnnotations/combo/Helper.java test/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java test/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java test/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java test/tools/javac/annotations/typeAnnotations/failures/CheckErrorsForSource7.java test/tools/javac/api/6420409/T6420409.java test/tools/javac/api/6420464/T6420464.java test/tools/javac/api/6431435/T6431435.java test/tools/javac/api/7086261/T7086261.java test/tools/javac/api/8007344/Test.java test/tools/javac/api/Sibling.java test/tools/javac/api/T6258271.java test/tools/javac/api/T6265137.java test/tools/javac/api/T6306137.java test/tools/javac/api/T6345974.java test/tools/javac/api/T6357331.java test/tools/javac/api/T6358786.java test/tools/javac/api/T6358955.java test/tools/javac/api/T6392782.java test/tools/javac/api/T6397104.java test/tools/javac/api/T6400205.java test/tools/javac/api/T6400207.java test/tools/javac/api/T6412669.java test/tools/javac/api/T6419926.java test/tools/javac/api/T6430241.java test/tools/javac/api/T6431879.java test/tools/javac/api/T6483788.java test/tools/javac/api/T6501502.java test/tools/javac/api/TestClientCodeWrapper.java test/tools/javac/api/TestDocComments.java test/tools/javac/api/TestGetElementReference.java test/tools/javac/api/TestGetScope.java test/tools/javac/api/TestJavacTask.java test/tools/javac/api/TestJavacTask_Lock.java test/tools/javac/api/TestJavacTask_Multiple.java test/tools/javac/api/TestJavacTask_ParseAttrGen.java test/tools/javac/api/TestSearchPaths.java test/tools/javac/api/TestTreePath.java test/tools/javac/api/TestTrees.java test/tools/javac/api/taskListeners/CompileEvent.java test/tools/javac/api/taskListeners/EventsBalancedTest.java test/tools/javac/api/taskListeners/TestSimpleAddRemove.java test/tools/javac/cast/intersection/IntersectionTypeParserTest.java test/tools/javac/classreader/T7031108.java test/tools/javac/defaultMethods/DefaultMethodFlags.java test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java test/tools/javac/defaultMethods/syntax/TestDefaultMethodsSyntax.java test/tools/javac/diags/CheckResourceKeys.java test/tools/javac/doclint/DocLintTest.java test/tools/javac/doctree/DocTreePathScannerTest.java test/tools/javac/doctree/SimpleDocTreeVisitorTest.java test/tools/javac/file/T7068451.java test/tools/javac/flow/LVTHarness.java test/tools/javac/generics/bridges/BridgeHarness.java test/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java test/tools/javac/generics/diamond/7030687/ParserTest.java test/tools/javac/generics/inference/7086601/T7086601b.java test/tools/javac/lambda/BadLambdaExpr.java test/tools/javac/lambda/TestSelfRef.java test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java test/tools/javac/lambda/methodReference/SamConversionComboTest.java test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java test/tools/javac/nativeHeaders/NativeHeaderTest.java test/tools/javac/options/xprefer/XPreferTest.java test/tools/javac/plugin/showtype/Test.java test/tools/javac/positions/TreeEndPosTest.java test/tools/javac/processing/6348193/T6348193.java test/tools/javac/processing/6348499/T6348499.java test/tools/javac/processing/6378728/T6378728.java test/tools/javac/processing/6414633/T6414633.java test/tools/javac/processing/6430209/T6430209.java test/tools/javac/processing/T6439826.java test/tools/javac/processing/errors/TestSuppression.java test/tools/javac/processing/loader/testClose/TestClose.java test/tools/javac/processing/model/testgetallmembers/Main.java test/tools/javac/processing/model/type/BoundsTest.java test/tools/javac/processing/model/type/IntersectionPropertiesTest.java test/tools/javac/processing/model/util/elements/doccomments/TestDocComments.java test/tools/javac/processing/model/util/elements/doccomments/TestPackageInfoComments.java test/tools/javac/processing/options/testCommandLineClasses/Test.java test/tools/javac/processing/rounds/BaseClassesNotReRead.java test/tools/javac/profiles/ProfileOptionTest.java test/tools/javac/resolve/ResolveHarness.java test/tools/javac/tree/ClassTreeTest.java test/tools/javac/tree/DocCommentToplevelTest.java test/tools/javac/tree/MissingSemicolonTest.java test/tools/javac/tree/PrettySimpleStringTest.java test/tools/javac/tree/T6963934.java test/tools/javac/tree/T6993305.java test/tools/javac/tree/TestToString.java test/tools/javac/tree/TreePosRoundsTest.java test/tools/javac/tree/TreePosTest.java test/tools/javac/unit/T6198196.java test/tools/javac/varargs/6199075/T6199075.java test/tools/javac/varargs/7043922/T7043922.java test/tools/javac/versions/Versions.java test/tools/javadoc/CheckResourceKeys.java test/tools/javadoc/api/basic/DocletPathTest.java test/tools/javadoc/api/basic/GetTask_DiagListenerTest.java test/tools/javadoc/api/basic/GetTask_DocletClassTest.java test/tools/javadoc/api/basic/GetTask_FileObjectsTest.java test/tools/javadoc/api/basic/GetTask_OptionsTest.java test/tools/javadoc/api/basic/GetTask_WriterTest.java test/tools/javadoc/api/basic/JavadocTaskImplTest.java test/tools/javadoc/api/basic/TagletPathTest.java test/tools/javadoc/api/basic/Task_reuseTest.java test/tools/javadoc/doclint/DocLintTest.java test/tools/javap/TestSuperclass.java test/tools/sjavac/DependencyCollection.java
diffstat 145 files changed, 2722 insertions(+), 2473 deletions(-) [+]
line wrap: on
line diff
--- a/test/tools/all/RunCodingRules.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/all/RunCodingRules.java	Wed Oct 29 17:25:23 2014 -0700
@@ -77,41 +77,42 @@
         }
 
         JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null);
-        DiagnosticListener<JavaFileObject> noErrors = diagnostic -> {
-            Assert.check(diagnostic.getKind() != Diagnostic.Kind.ERROR, diagnostic.toString());
-        };
+        try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
+            DiagnosticListener<JavaFileObject> noErrors = diagnostic -> {
+                Assert.check(diagnostic.getKind() != Diagnostic.Kind.ERROR, diagnostic.toString());
+            };
 
-        List<File> crulesFiles = Files.walk(crulesDir)
-                                      .filter(entry -> entry.getFileName().toString().endsWith(".java"))
-                                      .filter(entry -> entry.getParent().endsWith("crules"))
-                                      .map(entry -> entry.toFile())
-                                      .collect(Collectors.toList());
+            List<File> crulesFiles = Files.walk(crulesDir)
+                                          .filter(entry -> entry.getFileName().toString().endsWith(".java"))
+                                          .filter(entry -> entry.getParent().endsWith("crules"))
+                                          .map(entry -> entry.toFile())
+                                          .collect(Collectors.toList());
 
-        Path crulesTarget = targetDir.resolve("crules");
-        Files.createDirectories(crulesTarget);
-        List<String> crulesOptions = Arrays.asList("-d", crulesTarget.toString());
-        javaCompiler.getTask(null, fm, noErrors, crulesOptions, null,
-                fm.getJavaFileObjectsFromFiles(crulesFiles)).call();
-        Path registration = crulesTarget.resolve("META-INF/services/com.sun.source.util.Plugin");
-        Files.createDirectories(registration.getParent());
-        try (Writer metaInfServices = Files.newBufferedWriter(registration, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
-            metaInfServices.write("crules.CodingRulesAnalyzerPlugin\n");
+            Path crulesTarget = targetDir.resolve("crules");
+            Files.createDirectories(crulesTarget);
+            List<String> crulesOptions = Arrays.asList("-d", crulesTarget.toString());
+            javaCompiler.getTask(null, fm, noErrors, crulesOptions, null,
+                    fm.getJavaFileObjectsFromFiles(crulesFiles)).call();
+            Path registration = crulesTarget.resolve("META-INF/services/com.sun.source.util.Plugin");
+            Files.createDirectories(registration.getParent());
+            try (Writer metaInfServices = Files.newBufferedWriter(registration, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
+                metaInfServices.write("crules.CodingRulesAnalyzerPlugin\n");
+            }
+
+            List<File> sources = sourceDirs.stream()
+                                           .flatMap(dir -> silentFilesWalk(dir))
+                                           .filter(entry -> entry.getFileName().toString().endsWith(".java"))
+                                           .map(p -> p.toFile())
+                                           .collect(Collectors.toList());
+
+            Path sourceTarget = targetDir.resolve("classes");
+            Files.createDirectories(sourceTarget);
+            String processorPath = crulesTarget.toString() + File.pathSeparator + crulesDir.toString();
+            List<String> options = Arrays.asList("-d", sourceTarget.toString(),
+                    "-processorpath", processorPath, "-Xplugin:coding_rules");
+            javaCompiler.getTask(null, fm, noErrors, options, null,
+                    fm.getJavaFileObjectsFromFiles(sources)).call();
         }
-
-        List<File> sources = sourceDirs.stream()
-                                       .flatMap(dir -> silentFilesWalk(dir))
-                                       .filter(entry -> entry.getFileName().toString().endsWith(".java"))
-                                       .map(p -> p.toFile())
-                                       .collect(Collectors.toList());
-
-        Path sourceTarget = targetDir.resolve("classes");
-        Files.createDirectories(sourceTarget);
-        String processorPath = crulesTarget.toString() + File.pathSeparator + crulesDir.toString();
-        List<String> options = Arrays.asList("-d", sourceTarget.toString(),
-                "-processorpath", processorPath, "-Xplugin:coding_rules");
-        javaCompiler.getTask(null, fm, noErrors, options, null,
-                fm.getJavaFileObjectsFromFiles(sources)).call();
     }
 
     Stream<Path> silentFilesWalk(Path dir) throws IllegalStateException {
--- a/test/tools/javac/6341866/T6341866.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/6341866/T6341866.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2010, 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
@@ -113,58 +113,59 @@
 
         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
         MyDiagListener dl = new MyDiagListener();
-        StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
+        try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
 
-        // Note: class A references class B, so compile A if we want implicit compilation
-        File file =  (implicitType != ImplicitType.NONE) ? a_java : b_java;
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
+            // Note: class A references class B, so compile A if we want implicit compilation
+            File file =  (implicitType != ImplicitType.NONE) ? a_java : b_java;
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
 
-        //System.err.println("compile: " + opts + " " + files);
+            //System.err.println("compile: " + opts + " " + files);
 
-        boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
-        if (!ok) {
-            error("compilation failed");
-            return false;
-        }
-
-        // check implicit compilation results if necessary
-        if (implicitType != ImplicitType.NONE) {
-            boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
-            if (b_class.exists() != expectClass) {
-                if (b_class.exists())
-                    error("B implicitly compiled unexpectedly");
-                else
-                    error("B not impliictly compiled");
+            boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
+            if (!ok) {
+                error("compilation failed");
                 return false;
             }
+
+            // check implicit compilation results if necessary
+            if (implicitType != ImplicitType.NONE) {
+                boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
+                if (b_class.exists() != expectClass) {
+                    if (b_class.exists())
+                        error("B implicitly compiled unexpectedly");
+                    else
+                        error("B not impliictly compiled");
+                    return false;
+                }
+            }
+
+            // check message key results
+            String expectKey = null;
+            if (implicitType == ImplicitType.OPT_UNSET) {
+                switch (annoType) {
+                case SERVICE:
+                    expectKey = "compiler.warn.proc.use.proc.or.implicit";
+                    break;
+                case SPECIFY:
+                    expectKey = "compiler.warn.proc.use.implicit";
+                    break;
+                }
+            }
+
+            if (expectKey == null) {
+                if (dl.diagCodes.size() != 0) {
+                    error("no diagnostics expected");
+                    return false;
+                }
+            } else {
+                if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
+                    error("unexpected diagnostics generated");
+                    return false;
+                }
+            }
+
+            return true;
         }
-
-        // check message key results
-        String expectKey = null;
-        if (implicitType == ImplicitType.OPT_UNSET) {
-            switch (annoType) {
-            case SERVICE:
-                expectKey = "compiler.warn.proc.use.proc.or.implicit";
-                break;
-            case SPECIFY:
-                expectKey = "compiler.warn.proc.use.implicit";
-                break;
-            }
-        }
-
-        if (expectKey == null) {
-            if (dl.diagCodes.size() != 0) {
-                error("no diagnostics expected");
-                return false;
-            }
-        } else {
-            if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
-                error("unexpected diagnostics generated");
-                return false;
-            }
-        }
-
-        return true;
     }
 
     static void createProcessorServices(String name) throws IOException {
--- a/test/tools/javac/6400872/T6400872.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/6400872/T6400872.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2007, 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
@@ -58,8 +58,7 @@
                 throws IOException {
         System.err.println("compile...");
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
-        try {
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
             Iterable<? extends JavaFileObject> fileObjects =
                 fm.getJavaFileObjectsFromFiles(Arrays.asList(files));
 
@@ -78,8 +77,6 @@
                 compiler.getTask(null, fm, null, options, null, fileObjects);
             if (!task.call())
                 throw new AssertionError("compilation failed");
-        } finally {
-            fm.close();
         }
     }
 
--- a/test/tools/javac/6402516/Checker.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/6402516/Checker.java	Wed Oct 29 17:25:23 2014 -0700
@@ -54,25 +54,26 @@
         };
 
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(getFiles(testSrc, fileNames));
-        task = tool.getTask(null, fm, dl, null, null, files);
-        Iterable<? extends CompilationUnitTree> units = task.parse();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(getFiles(testSrc, fileNames));
+            task = tool.getTask(null, fm, dl, null, null, files);
+            Iterable<? extends CompilationUnitTree> units = task.parse();
 
-        if (errors)
-            throw new AssertionError("errors occurred creating trees");
+            if (errors)
+                throw new AssertionError("errors occurred creating trees");
 
-        ScopeScanner s = new ScopeScanner();
-        for (CompilationUnitTree unit: units) {
-            TreePath p = new TreePath(unit);
-            s.scan(p, getTrees());
-            additionalChecks(getTrees(), unit);
+            ScopeScanner s = new ScopeScanner();
+            for (CompilationUnitTree unit: units) {
+                TreePath p = new TreePath(unit);
+                s.scan(p, getTrees());
+                additionalChecks(getTrees(), unit);
+            }
+            task = null;
+
+            if (errors)
+                throw new AssertionError("errors occurred checking scopes");
         }
-        task = null;
-
-        if (errors)
-            throw new AssertionError("errors occurred checking scopes");
     }
 
     // default impl: split ref at ";" and call checkLocal(scope, ref_segment) on scope and its enclosing scopes
--- a/test/tools/javac/6440583/T6440583.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/6440583/T6440583.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
@@ -40,30 +40,31 @@
         String testSrc = System.getProperty("test.src", ".");
         String testClasses = System.getProperty("test.classes", ".");
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
-        JavacTask task = tool.getTask(null, fm, null, null, null, files);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
+            JavacTask task = tool.getTask(null, fm, null, null, null, files);
 
-        Iterable<? extends Tree> trees = task.parse();
+            Iterable<? extends Tree> trees = task.parse();
 
-        TreeScanner<Boolean,Void> checker = new TreeScanner<Boolean,Void>() {
-            public Boolean visitErroneous(ErroneousTree tree, Void ignore) {
-                JCErroneous etree = (JCErroneous) tree;
-                List<? extends Tree> errs = etree.getErrorTrees();
-                System.err.println("errs: " + errs);
-                if (errs == null || errs.size() == 0)
-                    throw new AssertionError("no error trees found");
-                found = true;
-                return true;
-            }
-        };
+            TreeScanner<Boolean,Void> checker = new TreeScanner<Boolean,Void>() {
+                public Boolean visitErroneous(ErroneousTree tree, Void ignore) {
+                    JCErroneous etree = (JCErroneous) tree;
+                    List<? extends Tree> errs = etree.getErrorTrees();
+                    System.err.println("errs: " + errs);
+                    if (errs == null || errs.size() == 0)
+                        throw new AssertionError("no error trees found");
+                    found = true;
+                    return true;
+                }
+            };
 
-        for (Tree tree: trees)
-            checker.scan(tree, null);
+            for (Tree tree: trees)
+                checker.scan(tree, null);
 
-        if (!found)
-            throw new AssertionError("no ErroneousTree nodes found");
+            if (!found)
+                throw new AssertionError("no ErroneousTree nodes found");
+        }
     }
 
     private static boolean found;
--- a/test/tools/javac/6902720/Test.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/6902720/Test.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -54,38 +54,39 @@
 
     void test(File test) throws Exception {
         JavacTool tool1 = JavacTool.create();
-        StandardJavaFileManager fm = tool1.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(test);
+        try (StandardJavaFileManager fm = tool1.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(test);
 
-        // parse test file into a tree, and write it out to a stringbuffer using Pretty
-        JavacTask t1 = tool1.getTask(null, fm, null, null, null, files);
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
-        Iterable<? extends CompilationUnitTree> trees = t1.parse();
-        for (CompilationUnitTree tree: trees) {
-            new Pretty(pw, true).printExpr((JCTree) tree);
+            // parse test file into a tree, and write it out to a stringbuffer using Pretty
+            JavacTask t1 = tool1.getTask(null, fm, null, null, null, files);
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+            Iterable<? extends CompilationUnitTree> trees = t1.parse();
+            for (CompilationUnitTree tree: trees) {
+                new Pretty(pw, true).printExpr((JCTree) tree);
+            }
+            pw.close();
+
+            final String out = sw.toString();
+            System.err.println("generated code:\n" + out + "\n");
+
+            // verify the generated code is valid Java by compiling it
+            JavacTool tool2 = JavacTool.create();
+            JavaFileObject fo = new SimpleJavaFileObject(URI.create("output"), JavaFileObject.Kind.SOURCE) {
+                @Override
+                public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+                    return out;
+                }
+            };
+            JavacTask t2 = tool2.getTask(null, fm, null, null, null, Collections.singleton(fo));
+            boolean ok = t2.call();
+            if (!ok)
+                throw new Exception("compilation of generated code failed");
+
+            File expectedClass = new File(test.getName().replace(".java", ".class"));
+            if (!expectedClass.exists())
+                throw new Exception(expectedClass + " not found");
         }
-        pw.close();
-
-        final String out = sw.toString();
-        System.err.println("generated code:\n" + out + "\n");
-
-        // verify the generated code is valid Java by compiling it
-        JavacTool tool2 = JavacTool.create();
-        JavaFileObject fo = new SimpleJavaFileObject(URI.create("output"), JavaFileObject.Kind.SOURCE) {
-            @Override
-            public CharSequence getCharContent(boolean ignoreEncodingErrors) {
-                return out;
-            }
-        };
-        JavacTask t2 = tool2.getTask(null, fm, null, null, null, Collections.singleton(fo));
-        boolean ok = t2.call();
-        if (!ok)
-            throw new Exception("compilation of generated code failed");
-
-        File expectedClass = new File(test.getName().replace(".java", ".class"));
-        if (!expectedClass.exists())
-            throw new Exception(expectedClass + " not found");
     }
 }
 
--- a/test/tools/javac/7003595/T7003595.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/7003595/T7003595.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -49,9 +49,6 @@
 
     /** global decls ***/
 
-    // Create a single file manager and reuse it for each compile to save time.
-    static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
-
     //statistics
     static int checkCount = 0;
 
@@ -112,15 +109,18 @@
     }
 
     public static void main(String... args) throws Exception {
-        for (ClassKind ck1 : ClassKind.values()) {
-            String cname1 = "C1";
-            for (ClassKind ck2 : ClassKind.values()) {
-                if (!ck1.isAllowed(ck2)) continue;
-                String cname2 = "C2";
-                for (ClassKind ck3 : ClassKind.values()) {
-                    if (!ck2.isAllowed(ck3)) continue;
-                    String cname3 = "C3";
-                    new T7003595(new ClassKind[] {ck1, ck2, ck3}, new String[] { cname1, cname2, cname3 }).compileAndCheck();
+        // Create a single file manager and reuse it for each compile to save time.
+        try (StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null)) {
+            for (ClassKind ck1 : ClassKind.values()) {
+                String cname1 = "C1";
+                for (ClassKind ck2 : ClassKind.values()) {
+                    if (!ck1.isAllowed(ck2)) continue;
+                    String cname2 = "C2";
+                    for (ClassKind ck3 : ClassKind.values()) {
+                        if (!ck2.isAllowed(ck3)) continue;
+                        String cname3 = "C3";
+                        new T7003595(fm, new ClassKind[] {ck1, ck2, ck3}, new String[] { cname1, cname2, cname3 }).compileAndCheck();
+                    }
                 }
             }
         }
@@ -132,8 +132,10 @@
 
     ClassKind[] cks;
     String[] cnames;
+    StandardJavaFileManager fm;
 
-    T7003595(ClassKind[] cks, String[] cnames) {
+    T7003595(StandardJavaFileManager fm, ClassKind[] cks, String[] cnames) {
+        this.fm = fm;
         this.cks = cks;
         this.cnames = cnames;
     }
--- a/test/tools/javac/7079713/TestCircularClassfile.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/7079713/TestCircularClassfile.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -100,13 +100,14 @@
 
     public static void main(String... args) throws Exception {
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-        int count = 0;
-        for (SourceKind sk1 : SourceKind.values()) {
-            for (SourceKind sk2 : SourceKind.values()) {
-                for (TestKind tk : TestKind.values()) {
-                    for (ClientKind ck : ClientKind.values()) {
-                        new TestCircularClassfile("sub_"+count++, sk1, sk2, tk, ck).check(comp, fm);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
+            int count = 0;
+            for (SourceKind sk1 : SourceKind.values()) {
+                for (SourceKind sk2 : SourceKind.values()) {
+                    for (TestKind tk : TestKind.values()) {
+                        for (ClientKind ck : ClientKind.values()) {
+                            new TestCircularClassfile("sub_"+count++, sk1, sk2, tk, ck).check(comp, fm);
+                        }
                     }
                 }
             }
--- a/test/tools/javac/7142086/T7142086.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/7142086/T7142086.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -96,10 +96,11 @@
     void run(List<JavaFileObject> sources) throws Exception {
         DiagnosticChecker dc = new DiagnosticChecker();
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-        JavacTask ct = (JavacTask)comp.getTask(null, fm, dc,
-                null, null, sources);
-        ct.analyze();
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
+            JavacTask ct = (JavacTask)comp.getTask(null, fm, dc,
+                    null, null, sources);
+            ct.analyze();
+        }
     }
 
     static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
--- a/test/tools/javac/NoStringToLower.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/NoStringToLower.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -54,31 +54,32 @@
      */
     boolean run(String... args) throws Exception {
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        JavaFileManager fm = c.getStandardFileManager(null, null, null);
-        JavaFileManager.Location javacLoc = findJavacLocation(fm);
-        String[] pkgs = {
-            "javax.annotation.processing",
-            "javax.lang.model",
-            "javax.tools",
-            "com.sun.source",
-            "com.sun.tools.classfile",
-            "com.sun.tools.doclet",
-            "com.sun.tools.doclint",
-            "com.sun.tools.javac",
-            "com.sun.tools.javadoc",
-            "com.sun.tools.javah",
-            "com.sun.tools.javap",
-            "com.sun.tools.jdeps",
-            "com.sun.tools.sjavac"
-        };
-        for (String pkg: pkgs) {
-            for (JavaFileObject fo: fm.list(javacLoc,
-                    pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
-                scan(fo);
+        try (JavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            JavaFileManager.Location javacLoc = findJavacLocation(fm);
+            String[] pkgs = {
+                "javax.annotation.processing",
+                "javax.lang.model",
+                "javax.tools",
+                "com.sun.source",
+                "com.sun.tools.classfile",
+                "com.sun.tools.doclet",
+                "com.sun.tools.doclint",
+                "com.sun.tools.javac",
+                "com.sun.tools.javadoc",
+                "com.sun.tools.javah",
+                "com.sun.tools.javap",
+                "com.sun.tools.jdeps",
+                "com.sun.tools.sjavac"
+            };
+            for (String pkg: pkgs) {
+                for (JavaFileObject fo: fm.list(javacLoc,
+                        pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
+                    scan(fo);
+                }
             }
+
+            return (errors == 0);
         }
-
-        return (errors == 0);
     }
 
     // depending on how the test is run, javac may be on bootclasspath or classpath
--- a/test/tools/javac/Paths/6638501/JarFromManifestFailure.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/Paths/6638501/JarFromManifestFailure.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -71,28 +71,29 @@
         }
     }
 
-    static void compile(File classOutDir, Iterable<File> classPath, File... files) {
+    static void compile(File classOutDir, Iterable<File> classPath, File... files) throws IOException {
         System.err.println("compile...");
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> fileObjects =
-                    fm.getJavaFileObjectsFromFiles(Arrays.asList(files));
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> fileObjects =
+                        fm.getJavaFileObjectsFromFiles(Arrays.asList(files));
 
-        List<String> options = new ArrayList<String>();
-        if (classOutDir != null) {
-            options.add("-d");
-            options.add(classOutDir.getPath());
+            List<String> options = new ArrayList<String>();
+            if (classOutDir != null) {
+                options.add("-d");
+                options.add(classOutDir.getPath());
+            }
+            if (classPath != null) {
+                options.add("-classpath");
+                options.add(join(classPath, File.pathSeparator));
+            }
+            options.add("-verbose");
+
+            JavaCompiler.CompilationTask task =
+                compiler.getTask(null, fm, null, options, null, fileObjects);
+            if (!task.call())
+                throw new AssertionError("compilation failed");
         }
-        if (classPath != null) {
-            options.add("-classpath");
-            options.add(join(classPath, File.pathSeparator));
-        }
-        options.add("-verbose");
-
-        JavaCompiler.CompilationTask task =
-            compiler.getTask(null, fm, null, options, null, fileObjects);
-        if (!task.call())
-            throw new AssertionError("compilation failed");
     }
 
     static void jar(File jar, Iterable<File> classPath, File base, File... files)
--- a/test/tools/javac/Paths/TestCompileJARInClassPath.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/Paths/TestCompileJARInClassPath.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -116,17 +116,18 @@
 
         javax.tools.JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
         DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
-        StandardJavaFileManager stdFileManager = javac.getStandardFileManager(diagnostics, null, null);
+        try (StandardJavaFileManager stdFileManager = javac.getStandardFileManager(diagnostics, null, null)) {
 
-        List<File> files = new ArrayList<>();
-        files.add(clientJarFile);
+            List<File> files = new ArrayList<>();
+            files.add(clientJarFile);
 
-        stdFileManager.setLocation(StandardLocation.CLASS_PATH, files);
+            stdFileManager.setLocation(StandardLocation.CLASS_PATH, files);
 
-        Iterable<? extends JavaFileObject> sourceFiles = stdFileManager.getJavaFileObjects(sourceFileToCompile);
+            Iterable<? extends JavaFileObject> sourceFiles = stdFileManager.getJavaFileObjects(sourceFileToCompile);
 
-        if (!javac.getTask(null, stdFileManager, diagnostics, null, null, sourceFiles).call()) {
-            throw new AssertionError("compilation failed");
+            if (!javac.getTask(null, stdFileManager, diagnostics, null, null, sourceFiles).call()) {
+                throw new AssertionError("compilation failed");
+            }
         }
     }
 }
--- a/test/tools/javac/T6265400.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6265400.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -44,10 +44,11 @@
                         throw new NullPointerException(SILLY_BILLY);
                     }
                 };
-            StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
-            Iterable<? extends JavaFileObject> files =
-                fm.getJavaFileObjectsFromStrings(Arrays.asList("badfile.java"));
-            javac.getTask(null, fm, dl, null, null, files).call();
+            try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
+                Iterable<? extends JavaFileObject> files =
+                    fm.getJavaFileObjectsFromStrings(Arrays.asList("badfile.java"));
+                javac.getTask(null, fm, dl, null, null, files).call();
+            }
         }
         catch (RuntimeException e) {
             Throwable cause = e.getCause();
--- a/test/tools/javac/T6340549.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6340549.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -44,13 +44,14 @@
 
         try {
             JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-            StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
-            jfm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File(".")));
+            try (StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null)) {
+                jfm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File(".")));
 
-            for (JavaFileObject jfo : jfm.list(StandardLocation.CLASS_PATH,
-                    "", EnumSet.of(Kind.OTHER), false)) {
-                if (new File(jfo.getName()).isDirectory()) {
-                    throw new AssertionError("Found directory: " + jfo);
+                for (JavaFileObject jfo : jfm.list(StandardLocation.CLASS_PATH,
+                        "", EnumSet.of(Kind.OTHER), false)) {
+                    if (new File(jfo.getName()).isDirectory()) {
+                        throw new AssertionError("Found directory: " + jfo);
+                    }
                 }
             }
         } finally {
--- a/test/tools/javac/T6351767.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6351767.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
@@ -38,52 +38,52 @@
     public static void main(String... args) throws Exception {
 
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        JavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
+        try (JavaFileManager jfm = compiler.getStandardFileManager(null, null, null)) {
 
-        // test null
-        try {
-            jfm.list(StandardLocation.SOURCE_PATH, null, EnumSet.of(Kind.SOURCE), false);
-            error("NPE not thrown");
+            // test null
+            try {
+                jfm.list(StandardLocation.SOURCE_PATH, null, EnumSet.of(Kind.SOURCE), false);
+                error("NPE not thrown");
+            }
+            catch (NullPointerException e) {
+                // expected
+            }
+
+            // test null fileKinds
+            try {
+                jfm.list(StandardLocation.SOURCE_PATH, "", null, false);
+                error("NPE not thrown");
+            }
+            catch (NullPointerException e) {
+                // expected
+            }
+
+            // test good package
+            boolean found = false;
+            for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
+                                               "java.lang",
+                                               EnumSet.of(Kind.CLASS),
+                                               false)) {
+                System.err.println("found " + jfo.toUri());
+                if (jfo.isNameCompatible("Object", Kind.CLASS))
+                    found = true;
+            }
+            if (!found)
+                error("expected file, java/lang/Object.class, not found");
+
+            found = false;
+            // test good package (VM name)
+            for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
+                                               "java/lang",
+                                               EnumSet.of(Kind.CLASS),
+                                               false)) {
+                System.err.println("found " + jfo.toUri());
+                if (jfo.isNameCompatible("Object", Kind.CLASS))
+                    found = true;
+            }
+            if (!found)
+                error("expected file, java/lang/Object.class, not found");
         }
-        catch (NullPointerException e) {
-            // expected
-        }
-
-        // test null fileKinds
-        try {
-            jfm.list(StandardLocation.SOURCE_PATH, "", null, false);
-            error("NPE not thrown");
-        }
-        catch (NullPointerException e) {
-            // expected
-        }
-
-        // test good package
-        boolean found = false;
-        for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
-                                           "java.lang",
-                                           EnumSet.of(Kind.CLASS),
-                                           false)) {
-            System.err.println("found " + jfo.toUri());
-            if (jfo.isNameCompatible("Object", Kind.CLASS))
-                found = true;
-        }
-        if (!found)
-            error("expected file, java/lang/Object.class, not found");
-
-        found = false;
-        // test good package (VM name)
-        for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
-                                           "java/lang",
-                                           EnumSet.of(Kind.CLASS),
-                                           false)) {
-            System.err.println("found " + jfo.toUri());
-            if (jfo.isNameCompatible("Object", Kind.CLASS))
-                found = true;
-        }
-        if (!found)
-            error("expected file, java/lang/Object.class, not found");
-
     }
 
     static void error(String msg) {
--- a/test/tools/javac/T6361619.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6361619.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
@@ -57,17 +57,18 @@
             }
         };
 
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        Iterable<? extends JavaFileObject> f =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir,
-                                                                  self + ".java")));
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            Iterable<? extends JavaFileObject> f =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir,
+                                                                      self + ".java")));
 
-        JavacTask task = tool.getTask(out, fm, dl, flags, null, f);
-        MyTaskListener tl = new MyTaskListener(task);
-        task.setTaskListener(tl);
+            JavacTask task = tool.getTask(out, fm, dl, flags, null, f);
+            MyTaskListener tl = new MyTaskListener(task);
+            task.setTaskListener(tl);
 
-        // should complete, without exceptions
-        task.call();
+            // should complete, without exceptions
+            task.call();
+        }
     }
 
     public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv) {
--- a/test/tools/javac/T6395974.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/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 {
--- a/test/tools/javac/T6397044.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6397044.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
@@ -42,14 +42,15 @@
         String srcDir = System.getProperty("test.src", ".");
         String self = T6397044.class.getName();
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files
-            = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java")));
-        JavacTask task = tool.getTask(null, fm, null, null, null, files);
-        Iterable<? extends CompilationUnitTree> trees = task.parse();
-        Checker checker = new Checker();
-        for (CompilationUnitTree tree: trees)
-            checker.check(tree);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files
+                = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java")));
+            JavacTask task = tool.getTask(null, fm, null, null, null, files);
+            Iterable<? extends CompilationUnitTree> trees = task.parse();
+            Checker checker = new Checker();
+            for (CompilationUnitTree tree: trees)
+                checker.check(tree);
+        }
     }
 
     public int x_public;
--- a/test/tools/javac/T6397286.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6397286.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
@@ -40,29 +40,30 @@
         String self = T6397286.class.getName();
 
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
 
-        JavacTask task = tool.getTask(null, fm, null, null, null, files);
-        task.setTaskListener(new TaskListener() {
-                public void started(TaskEvent e) {
-                    throw new TaskEventError(e);
+            JavacTask task = tool.getTask(null, fm, null, null, null, files);
+            task.setTaskListener(new TaskListener() {
+                    public void started(TaskEvent e) {
+                        throw new TaskEventError(e);
+                    }
+                    public void finished(TaskEvent e) {
+                    }
+                });
+
+            try {
+                task.call();
+                throw new AssertionError("no exception thrown");
+            } catch (RuntimeException e) {
+                if (e.getCause() instanceof TaskEventError) {
+                    TaskEventError tee = (TaskEventError) e.getCause();
+                    System.err.println("Exception thrown for " + tee.event + " as expected");
+                } else {
+                    e.printStackTrace();
+                    throw new AssertionError("TaskEventError not thrown");
                 }
-                public void finished(TaskEvent e) {
-                }
-            });
-
-        try {
-            task.call();
-            throw new AssertionError("no exception thrown");
-        } catch (RuntimeException e) {
-            if (e.getCause() instanceof TaskEventError) {
-                TaskEventError tee = (TaskEventError) e.getCause();
-                System.err.println("Exception thrown for " + tee.event + " as expected");
-            } else {
-                e.printStackTrace();
-                throw new AssertionError("TaskEventError not thrown");
             }
         }
     }
--- a/test/tools/javac/T6403466.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6403466.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2010, 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
@@ -51,24 +51,25 @@
     public static void main(String[] args) throws IOException {
         JavacTool tool = JavacTool.create();
 
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
 
-        Iterable<String> options = Arrays.asList("-processorpath", testClassDir,
-                                                 "-processor", self,
-                                                 "-s", ".",
-                                                 "-d", ".");
-        JavacTask task = tool.getTask(out, fm, null, options, null, files);
+            Iterable<String> options = Arrays.asList("-processorpath", testClassDir,
+                                                     "-processor", self,
+                                                     "-s", ".",
+                                                     "-d", ".");
+            JavacTask task = tool.getTask(out, fm, null, options, null, files);
 
-        VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out"));
-        task.setTaskListener(vtl);
+            VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out"));
+            task.setTaskListener(vtl);
 
-        if (!task.call())
-            throw new AssertionError("compilation failed");
+            if (!task.call())
+                throw new AssertionError("compilation failed");
 
-        if (vtl.iter.hasNext() || vtl.errors)
-            throw new AssertionError("comparison against golden file failed.");
+            if (vtl.iter.hasNext() || vtl.errors)
+                throw new AssertionError("comparison against golden file failed.");
+        }
     }
 
     public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
--- a/test/tools/javac/T6406771.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6406771.java	Wed Oct 29 17:25:23 2014 -0700
@@ -33,21 +33,22 @@
 
     // White-space after this point does not matter
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
         String self = T6406771.class.getName();
         String testSrc = System.getProperty("test.src");
         String testClasses = System.getProperty("test.classes");
 
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        JavaFileObject f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self+".java"))).iterator().next();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            JavaFileObject f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self+".java"))).iterator().next();
 
-        List<String> opts = Arrays.asList("-d", ".", "-processorpath", testClasses, "-processor", self, "-proc:only");
+            List<String> opts = Arrays.asList("-d", ".", "-processorpath", testClasses, "-processor", self, "-proc:only");
 
-        JavacTask task = tool.getTask(null, fm, null, opts, null, Arrays.asList(f));
+            JavacTask task = tool.getTask(null, fm, null, opts, null, Arrays.asList(f));
 
-        if (!task.call())
-            throw new AssertionError("failed");
+            if (!task.call())
+                throw new AssertionError("failed");
+        }
     }
 
     public boolean process(Set<? extends TypeElement> elems, RoundEnvironment rEnv) {
--- a/test/tools/javac/T6407066.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6407066.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
@@ -37,20 +37,21 @@
         String testClasses = System.getProperty("test.classes", ".");
 
         JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager jfm = tool.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager jfm = tool.getStandardFileManager(null, null, null)) {
 
-        List<File> path = new ArrayList<File>();
-        path.add(new File("BadDirectory"));
-        path.add(new File(testSrc));
-        path.add(new File("BadFile.jar"));
+            List<File> path = new ArrayList<File>();
+            path.add(new File("BadDirectory"));
+            path.add(new File(testSrc));
+            path.add(new File("BadFile.jar"));
 
-        jfm.setLocation(StandardLocation.SOURCE_PATH, path);
+            jfm.setLocation(StandardLocation.SOURCE_PATH, path);
 
-        List<File> path2  = new ArrayList<File>();
-        for (File f: jfm.getLocation(StandardLocation.SOURCE_PATH))
-            path2.add(f);
+            List<File> path2  = new ArrayList<File>();
+            for (File f: jfm.getLocation(StandardLocation.SOURCE_PATH))
+                path2.add(f);
 
-        if (!path.equals(path2))
-            throw new AssertionError("path not preserved");
+            if (!path.equals(path2))
+                throw new AssertionError("path not preserved");
+        }
     }
 }
--- a/test/tools/javac/T6410706.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6410706.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
@@ -44,21 +44,22 @@
         String testClasses = System.getProperty("test.classes", ".");
         JavacTool tool = JavacTool.create();
         MyDiagListener dl = new MyDiagListener();
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
-        JavacTask task = tool.getTask(null, fm, dl, null, null, files);
-        task.parse();
-        task.analyze();
-        task.generate();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
+            JavacTask task = tool.getTask(null, fm, dl, null, null, files);
+            task.parse();
+            task.analyze();
+            task.generate();
 
-        // expect 2 notes:
-        // Note: T6410706.java uses or overrides a deprecated API.
-        // Note: Recompile with -Xlint:deprecation for details.
+            // expect 2 notes:
+            // Note: T6410706.java uses or overrides a deprecated API.
+            // Note: Recompile with -Xlint:deprecation for details.
 
-        if (dl.notes != 2)
-            throw new AssertionError(dl.notes + " notes given");
+            if (dl.notes != 2)
+                throw new AssertionError(dl.notes + " notes given");
+        }
     }
 
     private static class MyDiagListener implements DiagnosticListener<JavaFileObject>
--- a/test/tools/javac/T6458823/T6458823.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6458823/T6458823.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -55,33 +55,34 @@
         }
         DiagnosticCollector<JavaFileObject> diagColl =
             new DiagnosticCollector<JavaFileObject>();
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
-        List<String> options = new ArrayList<String>();
-        options.add("-processor");
-        options.add("MyProcessor");
-        options.add("-proc:only");
-        List<File> files = new ArrayList<File>();
-        files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
-        final CompilationTask task = compiler.getTask(null, fm, diagColl,
-            options, null, fm.getJavaFileObjectsFromFiles(files));
-        task.call();
-        int diagCount = 0;
-        for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
-            if (diag.getKind() != Diagnostic.Kind.WARNING) {
-                throw new AssertionError("Only warnings expected");
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            List<String> options = new ArrayList<String>();
+            options.add("-processor");
+            options.add("MyProcessor");
+            options.add("-proc:only");
+            List<File> files = new ArrayList<File>();
+            files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
+            final CompilationTask task = compiler.getTask(null, fm, diagColl,
+                options, null, fm.getJavaFileObjectsFromFiles(files));
+            task.call();
+            int diagCount = 0;
+            for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
+                if (diag.getKind() != Diagnostic.Kind.WARNING) {
+                    throw new AssertionError("Only warnings expected");
+                }
+                System.out.println(diag);
+                if (diag.getPosition() == Diagnostic.NOPOS) {
+                    throw new AssertionError("No position info in message");
+                }
+                if (diag.getSource() == null) {
+                    throw new AssertionError("No source info in message");
+                }
+                diagCount++;
             }
-            System.out.println(diag);
-            if (diag.getPosition() == Diagnostic.NOPOS) {
-                throw new AssertionError("No position info in message");
+            if (diagCount != 2) {
+                throw new AssertionError("unexpected number of warnings: " +
+                    diagCount + ", expected: 2");
             }
-            if (diag.getSource() == null) {
-                throw new AssertionError("No source info in message");
-            }
-            diagCount++;
-        }
-        if (diagCount != 2) {
-            throw new AssertionError("unexpected number of warnings: " +
-                diagCount + ", expected: 2");
         }
     }
 }
--- a/test/tools/javac/T6665791.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6665791.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -47,29 +47,30 @@
         write(test_java, test);
 
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager manager =
-                compiler.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
-        final StringWriter sw = new StringWriter();
-        JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null,
-                null, units);
+        try (StandardJavaFileManager manager =
+                compiler.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
+            final StringWriter sw = new StringWriter();
+            JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null,
+                    null, units);
 
-        new TreeScanner<Boolean, Void>() {
-            @Override
-            public Boolean visitClass(ClassTree arg0, Void arg1) {
-                sw.write(arg0.toString());
-                return super.visitClass(arg0, arg1);
+            new TreeScanner<Boolean, Void>() {
+                @Override
+                public Boolean visitClass(ClassTree arg0, Void arg1) {
+                    sw.write(arg0.toString());
+                    return super.visitClass(arg0, arg1);
+                }
+            }.scan(task.parse(), null);
+
+            System.out.println("output:");
+            System.out.println(sw.toString());
+            String found = sw.toString().replaceAll("\\s+", " ").trim();
+            String expect = test.replaceAll("\\s+", " ").trim();
+            if (!expect.equals(found)) {
+                System.out.println("expect: " + expect);
+                System.out.println("found:  " + found);
+                throw new Exception("unexpected output");
             }
-        }.scan(task.parse(), null);
-
-        System.out.println("output:");
-        System.out.println(sw.toString());
-        String found = sw.toString().replaceAll("\\s+", " ").trim();
-        String expect = test.replaceAll("\\s+", " ").trim();
-        if (!expect.equals(found)) {
-            System.out.println("expect: " + expect);
-            System.out.println("found:  " + found);
-            throw new Exception("unexpected output");
         }
     }
 
--- a/test/tools/javac/T6705935.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6705935.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -45,46 +45,47 @@
             java_home = java_home.getParentFile();
 
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
-        //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
+        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
 
-        for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
-                                        "java.lang",
-                                        Collections.singleton(JavaFileObject.Kind.CLASS),
-                                        false)) {
-            test++;
+            for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
+                                            "java.lang",
+                                            Collections.singleton(JavaFileObject.Kind.CLASS),
+                                            false)) {
+                test++;
 
-            if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
-                System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
-                skip++;
-                continue;
+                if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
+                    System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
+                    skip++;
+                    continue;
+                }
+
+                //System.err.println(fo.getName());
+                String p = fo.getName();
+                int bra = p.indexOf("(");
+                int ket = p.indexOf(")");
+                //System.err.println(bra + "," + ket + "," + p.length());
+                if (bra == -1 || ket != p.length() -1)
+                    throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
+                String part1 = p.substring(0, bra);
+                String part2 = p.substring(bra + 1, ket);
+                //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
+                if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
+                    throw new Exception("bad path: " + p);
+
             }
 
-            //System.err.println(fo.getName());
-            String p = fo.getName();
-            int bra = p.indexOf("(");
-            int ket = p.indexOf(")");
-            //System.err.println(bra + "," + ket + "," + p.length());
-            if (bra == -1 || ket != p.length() -1)
-                throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
-            String part1 = p.substring(0, bra);
-            String part2 = p.substring(bra + 1, ket);
-            //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
-            if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
-                throw new Exception("bad path: " + p);
+            if (test == 0)
+                throw new Exception("no files found");
 
+            if (skip == 0)
+                System.out.println(test + " files found");
+            else
+                System.out.println(test + " files found, " + skip + " files skipped");
+
+            if (test == skip)
+                System.out.println("Warning: all files skipped; no platform classes found in zip files.");
         }
-
-        if (test == 0)
-            throw new Exception("no files found");
-
-        if (skip == 0)
-            System.out.println(test + " files found");
-        else
-            System.out.println(test + " files found, " + skip + " files skipped");
-
-        if (test == skip)
-            System.out.println("Warning: all files skipped; no platform classes found in zip files.");
     }
 
     private <T> List<T> asList(Iterable<? extends T> items) {
--- a/test/tools/javac/T6900149.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6900149.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -37,14 +37,15 @@
         DiagnosticCollector<JavaFileObject> diag =
                 new DiagnosticCollector<JavaFileObject>();
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm =
-                compiler.getStandardFileManager(null, null, null);
-        File emptyFile = createTempFile("Empty.java");
-        File[] files = new File[] { emptyFile, emptyFile };
-        CompilationTask task = compiler.getTask(null, fm, diag,
-                null, null, fm.getJavaFileObjects(files));
-        if (! task.call()) {
-            throw new AssertionError("compilation failed");
+        try (StandardJavaFileManager fm =
+                compiler.getStandardFileManager(null, null, null)) {
+            File emptyFile = createTempFile("Empty.java");
+            File[] files = new File[] { emptyFile, emptyFile };
+            CompilationTask task = compiler.getTask(null, fm, diag,
+                    null, null, fm.getJavaFileObjects(files));
+            if (! task.call()) {
+                throw new AssertionError("compilation failed");
+            }
         }
     }
 
--- a/test/tools/javac/T6956462/T6956462.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6956462/T6956462.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -44,14 +44,15 @@
         if (compiler == null) {
             throw new RuntimeException("can't get javax.tools.JavaCompiler!");
         }
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
-        List<File> files = new ArrayList<File>();
-        files.add(new File(T6956462.class.getResource("TestClass.java").toURI()));
-        final CompilationTask task = compiler.getTask(null, fm, null,
-            null, null, fm.getJavaFileObjectsFromFiles(files));
-        JavacTask javacTask = (JavacTask) task;
-        for (CompilationUnitTree cu : javacTask.parse()) {
-            cu.accept(new MyVisitor(javacTask), null);
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            List<File> files = new ArrayList<File>();
+            files.add(new File(T6956462.class.getResource("TestClass.java").toURI()));
+            final CompilationTask task = compiler.getTask(null, fm, null,
+                null, null, fm.getJavaFileObjectsFromFiles(files));
+            JavacTask javacTask = (JavacTask) task;
+            for (CompilationUnitTree cu : javacTask.parse()) {
+                cu.accept(new MyVisitor(javacTask), null);
+            }
         }
     }
 
--- a/test/tools/javac/T6956638.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T6956638.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -96,34 +96,35 @@
         List<String> compileOptions = Arrays.asList("-d", classesDir.getPath());
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
         DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
-        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null);
-        Iterable<? extends JavaFileObject> sourceFileObjects = fileManager.getJavaFileObjects(sourceFiles);
-        System.err.println("1- javac given java source JavaFileObjects " + sourceFileObjects);
-        JavaCompiler.CompilationTask task = compiler.getTask(compilerOutputStream, fileManager, null, compileOptions, null, sourceFileObjects);
-        JavacTask javacTask = (JavacTask) task;
+        try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null)) {
+            Iterable<? extends JavaFileObject> sourceFileObjects = fileManager.getJavaFileObjects(sourceFiles);
+            System.err.println("1- javac given java source JavaFileObjects " + sourceFileObjects);
+            JavaCompiler.CompilationTask task = compiler.getTask(compilerOutputStream, fileManager, null, compileOptions, null, sourceFileObjects);
+            JavacTask javacTask = (JavacTask) task;
 
-        Iterable<? extends CompilationUnitTree> parsedTrees = javacTask.parse();
-        Iterable<? extends Element> analyzedTrees = javacTask.analyze();
-        Iterable<? extends JavaFileObject> generatedFiles = javacTask.generate();
+            Iterable<? extends CompilationUnitTree> parsedTrees = javacTask.parse();
+            Iterable<? extends Element> analyzedTrees = javacTask.analyze();
+            Iterable<? extends JavaFileObject> generatedFiles = javacTask.generate();
 
-        System.err.println("2- parsed:" + size(parsedTrees) + " analysed:" + size(analyzedTrees) + " generated:" + size(generatedFiles));
+            System.err.println("2- parsed:" + size(parsedTrees) + " analysed:" + size(analyzedTrees) + " generated:" + size(generatedFiles));
 
-        System.err.print("3-");
-        for (JavaFileObject f : generatedFiles)
-            System.err.print(" " + f);
-        System.err.println("");
+            System.err.print("3-");
+            for (JavaFileObject f : generatedFiles)
+                System.err.print(" " + f);
+            System.err.println("");
 
-        System.err.print("5-");
-        for (File f : classesDir.listFiles())
-            System.err.print(" " + f);
-        System.err.println("");
+            System.err.print("5-");
+            for (File f : classesDir.listFiles())
+                System.err.print(" " + f);
+            System.err.println("");
 
-        System.err.println("----");
-        System.err.println(compilerOutputStream.toString());
+            System.err.println("----");
+            System.err.println(compilerOutputStream.toString());
 
-        if (size(generatedFiles) != size(parsedTrees)) {
-            throw new Exception("wrong number of files generated: " + size(generatedFiles)
-                    + " expected: " + size(parsedTrees));
+            if (size(generatedFiles) != size(parsedTrees)) {
+                throw new Exception("wrong number of files generated: " + size(generatedFiles)
+                        + " expected: " + size(parsedTrees));
+            }
         }
     }
 
--- a/test/tools/javac/T7142672/Bug.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T7142672/Bug.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -58,28 +58,29 @@
             }
         };
 
-        StandardJavaFileManager sjfm = javac.getStandardFileManager(dl,null,null);
+        try (StandardJavaFileManager sjfm = javac.getStandardFileManager(dl,null,null)) {
 
-        List<String> opts = new ArrayList<String>();
-        opts.add("-proc:only");
-        opts.add("-processor");
-        opts.add("AnnoProcessor");
+            List<String> opts = new ArrayList<String>();
+            opts.add("-proc:only");
+            opts.add("-processor");
+            opts.add("AnnoProcessor");
 
-        boolean xxx;
+            boolean xxx;
 
-        System.err.println("\n-- " + name);
-        task2 = javac.getTask(pw, sjfm, dl, opts, Arrays.asList(name), null);
-        xxx = task2.call();
+            System.err.println("\n-- " + name);
+            task2 = javac.getTask(pw, sjfm, dl, opts, Arrays.asList(name), null);
+            xxx = task2.call();
 
-        String out = sw.toString();
-        System.err.println(out);
-        if (out.contains("Assert")) {
-            System.err.println("--Failed: Assertion failure");
-            System.exit(1);
-        }
-        if (!out.contains(expectedMsg)) {
-            System.err.println("--Failed: Expected diagnostic not found");
-            System.exit(1);
+            String out = sw.toString();
+            System.err.println(out);
+            if (out.contains("Assert")) {
+                System.err.println("--Failed: Assertion failure");
+                System.exit(1);
+            }
+            if (!out.contains(expectedMsg)) {
+                System.err.println("--Failed: Expected diagnostic not found");
+                System.exit(1);
+            }
         }
     }
 }
--- a/test/tools/javac/T7159016.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T7159016.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -45,6 +45,7 @@
 import javax.lang.model.element.TypeElement;
 import javax.tools.Diagnostic;
 import javax.tools.JavaCompiler;
+import javax.tools.StandardJavaFileManager;
 import javax.tools.ToolProvider;
 
 public class T7159016 {
@@ -58,11 +59,13 @@
             w.close();
         }
         JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
-        JavaCompiler.CompilationTask task = jc.getTask(null, null, null, null, null,
-                                                       jc.getStandardFileManager(null, null, null).getJavaFileObjects(src));
-        task.setProcessors(Collections.singleton(new Proc()));
-        if (!task.call()) {
-            throw new Error("Test failed");
+        try (StandardJavaFileManager fm = jc.getStandardFileManager(null, null, null)) {
+            JavaCompiler.CompilationTask task = jc.getTask(null, fm, null, null, null,
+                                                           fm.getJavaFileObjects(src));
+            task.setProcessors(Collections.singleton(new Proc()));
+            if (!task.call()) {
+                throw new Error("Test failed");
+            }
         }
     }
 
--- a/test/tools/javac/T8003967/DetectMutableStaticFields.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T8003967/DetectMutableStaticFields.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2012, 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
@@ -179,18 +179,19 @@
             ConstantPoolException,
             InvalidDescriptor {
         JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        JavaFileManager.Location location =
-                StandardLocation.locationFor(resource.getPath());
-        fm.setLocation(location, com.sun.tools.javac.util.List.of(
-                new File(resource.getPath())));
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            JavaFileManager.Location location =
+                    StandardLocation.locationFor(resource.getPath());
+            fm.setLocation(location, com.sun.tools.javac.util.List.of(
+                    new File(resource.getPath())));
 
-        for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
-            String className = fm.inferBinaryName(location, file);
-            int index = className.lastIndexOf('.');
-            String pckName = index == -1 ? "" : className.substring(0, index);
-            if (shouldAnalyzePackage(pckName)) {
-                analyzeClassFile(ClassFile.read(file.openInputStream()));
+            for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
+                String className = fm.inferBinaryName(location, file);
+                int index = className.lastIndexOf('.');
+                String pckName = index == -1 ? "" : className.substring(0, index);
+                if (shouldAnalyzePackage(pckName)) {
+                    analyzeClassFile(ClassFile.read(file.openInputStream()));
+                }
             }
         }
     }
--- a/test/tools/javac/T8010737/ParameterNamesAreNotCopiedToAnonymousInitTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/T8010737/ParameterNamesAreNotCopiedToAnonymousInitTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -132,73 +132,74 @@
             throws IOException {
         Assert.checkNonNull(paramsToCheck, nonNullParamPositionsMsg);
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> fos =
-                fm.getJavaFileObjectsFromFiles(
-                Arrays.asList(new File(System.getProperty("test.src"),
-                this.getClass().getName() + ".java")));
-        JavacTask task = (JavacTask) c.getTask(null, fm, null,
-                Arrays.asList("-d", System.getProperty("user.dir")), null, fos);
+        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> fos =
+                    fm.getJavaFileObjectsFromFiles(
+                    Arrays.asList(new File(System.getProperty("test.src"),
+                    this.getClass().getName() + ".java")));
+            JavacTask task = (JavacTask) c.getTask(null, fm, null,
+                    Arrays.asList("-d", System.getProperty("user.dir")), null, fos);
 
-        BasicJavacTask impl = (BasicJavacTask)task;
-        Context context = impl.getContext();
-        final Names names = Names.instance(context);
+            BasicJavacTask impl = (BasicJavacTask)task;
+            Context context = impl.getContext();
+            final Names names = Names.instance(context);
 
-        task.addTaskListener(new TaskListener() {
+            task.addTaskListener(new TaskListener() {
 
-            @Override
-            public void started(TaskEvent e) {}
+                @Override
+                public void started(TaskEvent e) {}
 
-            @Override
-            public void finished(TaskEvent e) {
-                class TheTreeScanner extends TreeScanner {
-                    boolean foundAndCorrect = false;
+                @Override
+                public void finished(TaskEvent e) {
+                    class TheTreeScanner extends TreeScanner {
+                        boolean foundAndCorrect = false;
 
-                    @Override
-                    public void visitMethodDef(JCTree.JCMethodDecl tree) {
-                        ClassSymbol clazz = (ClassSymbol)tree.sym.owner;
-                        if (clazz.owner.name.toString().equals(classOwnerName) &&
-                            tree.sym.name == names.init) {
+                        @Override
+                        public void visitMethodDef(JCTree.JCMethodDecl tree) {
+                            ClassSymbol clazz = (ClassSymbol)tree.sym.owner;
+                            if (clazz.owner.name.toString().equals(classOwnerName) &&
+                                tree.sym.name == names.init) {
 
-                            int currentParamPos = 0;
-                            int paramArrayIndex = 0;
+                                int currentParamPos = 0;
+                                int paramArrayIndex = 0;
 
-                            List<VarSymbol> params = tree.sym.params;
-                            while (params.nonEmpty() && paramArrayIndex < paramsToCheck.size()) {
-                                VarSymbol param = params.head;
-                                if (currentParamPos == paramsToCheck.get(paramArrayIndex)) {
-                                    if (!param.name.toString()
-                                            .equals(paramNames.get(paramArrayIndex))) {
-                                        error(paramNameNotCopiedAssertionMsg);
+                                List<VarSymbol> params = tree.sym.params;
+                                while (params.nonEmpty() && paramArrayIndex < paramsToCheck.size()) {
+                                    VarSymbol param = params.head;
+                                    if (currentParamPos == paramsToCheck.get(paramArrayIndex)) {
+                                        if (!param.name.toString()
+                                                .equals(paramNames.get(paramArrayIndex))) {
+                                            error(paramNameNotCopiedAssertionMsg);
+                                        }
+                                        paramArrayIndex++;
                                     }
-                                    paramArrayIndex++;
+                                    currentParamPos++;
+                                    params = params.tail;
                                 }
-                                currentParamPos++;
-                                params = params.tail;
+                                foundAndCorrect = paramArrayIndex >= paramsToCheck.size();
                             }
-                            foundAndCorrect = paramArrayIndex >= paramsToCheck.size();
+                            super.visitMethodDef(tree);
                         }
-                        super.visitMethodDef(tree);
+                    }
+
+                    if (e.getKind() == TaskEvent.Kind.ANALYZE) {
+                        CompilationUnitTree compUnitTree = e.getCompilationUnit();
+                        boolean foundAndCorrect = false;
+                        for (Tree tree : compUnitTree.getTypeDecls()) {
+                            TheTreeScanner scanner = new TheTreeScanner();
+                            scanner.scan((JCTree) tree);
+                            foundAndCorrect = foundAndCorrect | scanner.foundAndCorrect;
+                        }
+                        if (!foundAndCorrect) {
+                            error(seekMethodNotFound);
+                        }
                     }
                 }
+            });
 
-                if (e.getKind() == TaskEvent.Kind.ANALYZE) {
-                    CompilationUnitTree compUnitTree = e.getCompilationUnit();
-                    boolean foundAndCorrect = false;
-                    for (Tree tree : compUnitTree.getTypeDecls()) {
-                        TheTreeScanner scanner = new TheTreeScanner();
-                        scanner.scan((JCTree) tree);
-                        foundAndCorrect = foundAndCorrect | scanner.foundAndCorrect;
-                    }
-                    if (!foundAndCorrect) {
-                        error(seekMethodNotFound);
-                    }
-                }
+            if (!task.call()) {
+                error(compilationFailed);
             }
-        });
-
-        if (!task.call()) {
-            error(compilationFailed);
         }
     }
 
--- a/test/tools/javac/TryWithResources/InterruptedExceptionTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/TryWithResources/InterruptedExceptionTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -117,16 +117,17 @@
 
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (XlintOption xlint : XlintOption.values()) {
-            for (SuppressLevel suppress_decl : SuppressLevel.values()) {
-                for (SuppressLevel suppress_use : SuppressLevel.values()) {
-                    for (ClassKind ck : ClassKind.values()) {
-                        for (ExceptionKind ek_decl : ExceptionKind.values()) {
-                            for (ExceptionKind ek_use : ExceptionKind.values()) {
-                                new InterruptedExceptionTest(xlint, suppress_decl,
-                                        suppress_use, ck, ek_decl, ek_use).run(comp, fm);
+            for (XlintOption xlint : XlintOption.values()) {
+                for (SuppressLevel suppress_decl : SuppressLevel.values()) {
+                    for (SuppressLevel suppress_use : SuppressLevel.values()) {
+                        for (ClassKind ck : ClassKind.values()) {
+                            for (ExceptionKind ek_decl : ExceptionKind.values()) {
+                                for (ExceptionKind ek_use : ExceptionKind.values()) {
+                                    new InterruptedExceptionTest(xlint, suppress_decl,
+                                            suppress_use, ck, ek_decl, ek_use).run(comp, fm);
+                                }
                             }
                         }
                     }
--- a/test/tools/javac/TryWithResources/UnusedResourcesTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/TryWithResources/UnusedResourcesTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -161,20 +161,24 @@
     }
 
     public static void main(String... args) throws Exception {
-        for (XlintOption xlint : XlintOption.values()) {
-            for (SuppressLevel suppressLevel : SuppressLevel.values()) {
-                for (ResourceUsage usage1 : ResourceUsage.values()) {
-                    for (ResourceUsage usage2 : ResourceUsage.values()) {
-                        for (ResourceUsage usage3 : ResourceUsage.values()) {
-                                test(xlint,
-                                        suppressLevel,
-                                        usage1,
-                                        usage2,
-                                        usage3);
+        try {
+            for (XlintOption xlint : XlintOption.values()) {
+                for (SuppressLevel suppressLevel : SuppressLevel.values()) {
+                    for (ResourceUsage usage1 : ResourceUsage.values()) {
+                        for (ResourceUsage usage2 : ResourceUsage.values()) {
+                            for (ResourceUsage usage3 : ResourceUsage.values()) {
+                                    test(xlint,
+                                            suppressLevel,
+                                            usage1,
+                                            usage2,
+                                            usage3);
+                            }
                         }
                     }
                 }
             }
+        } finally {
+            fm.close();
         }
     }
 
--- a/test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -41,38 +41,39 @@
         File testSrc = new File(System.getProperty("test.src"));
         File testFile = new File(testSrc, args[0]);
         if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source");
-        JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
-        JavacTask task = JavacTool.create().getTask(null,
-                                                    fm,
-                                                    null,
-                                                    Collections.<String>emptyList(),
-                                                    null,
-                                                    fm.getJavaFileObjects(testFile));
-        final Trees trees = Trees.instance(task);
-        final CompilationUnitTree cut = task.parse().iterator().next();
-        task.analyze();
+        try (JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null)) {
+            JavacTask task = JavacTool.create().getTask(null,
+                                                        fm,
+                                                        null,
+                                                        Collections.<String>emptyList(),
+                                                        null,
+                                                        fm.getJavaFileObjects(testFile));
+            final Trees trees = Trees.instance(task);
+            final CompilationUnitTree cut = task.parse().iterator().next();
+            task.analyze();
 
-        //ensure all the annotation attributes are annotated meaningfully
-        //all the attributes in the test file should contain either an identifier
-        //or a select, so only checking those for a reasonable Element/Symbol.
-        new TreePathScanner<Void, Void>() {
-            @Override
-            public Void visitIdentifier(IdentifierTree node, Void p) {
-                verifyAttributedMeaningfully();
-                return super.visitIdentifier(node, p);
-            }
-            @Override
-            public Void visitMemberSelect(MemberSelectTree node, Void p) {
-                verifyAttributedMeaningfully();
-                return super.visitMemberSelect(node, p);
-            }
-            private void verifyAttributedMeaningfully() {
-                Element el = trees.getElement(getCurrentPath());
+            //ensure all the annotation attributes are annotated meaningfully
+            //all the attributes in the test file should contain either an identifier
+            //or a select, so only checking those for a reasonable Element/Symbol.
+            new TreePathScanner<Void, Void>() {
+                @Override
+                public Void visitIdentifier(IdentifierTree node, Void p) {
+                    verifyAttributedMeaningfully();
+                    return super.visitIdentifier(node, p);
+                }
+                @Override
+                public Void visitMemberSelect(MemberSelectTree node, Void p) {
+                    verifyAttributedMeaningfully();
+                    return super.visitMemberSelect(node, p);
+                }
+                private void verifyAttributedMeaningfully() {
+                    Element el = trees.getElement(getCurrentPath());
 
-                if (el == null || el.getKind() == ElementKind.OTHER) {
-                    throw new IllegalStateException("Not attributed properly: " + getCurrentPath().getParentPath().getLeaf());
+                    if (el == null || el.getKind() == ElementKind.OTHER) {
+                        throw new IllegalStateException("Not attributed properly: " + getCurrentPath().getParentPath().getLeaf());
+                    }
                 }
-            }
-        }.scan(cut, null);
+            }.scan(cut, null);
+        }
     }
 }
--- a/test/tools/javac/annotations/repeatingAnnotations/combo/Helper.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/annotations/repeatingAnnotations/combo/Helper.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -102,29 +102,31 @@
             throw new RuntimeException("can't get javax.tools.JavaCompiler!");
         }
 
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
-
-        // Assuming filesCount can maximum be 2 and if true, one file is package-info.java
-        if (isPkgInfoPresent(files)) {
-            JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, null, null, files);
-            try {
-                fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
-                task.generate();
-            } catch (IOException ioe) {
-                throw new RuntimeException("Compilation failed for package level tests", ioe);
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            // Assuming filesCount can maximum be 2 and if true, one file is package-info.java
+            if (isPkgInfoPresent(files)) {
+                JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, null, null, files);
+                try {
+                    fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
+                    task.generate();
+                } catch (IOException ioe) {
+                    throw new RuntimeException("Compilation failed for package level tests", ioe);
+                }
+                int err = 0;
+                for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
+                    if(d.getKind() == Diagnostic.Kind.ERROR) {
+                      err++;
+                    }
+                }
+                ok = (err == 0);
+            } else {
+                CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, files);
+                ok = task.call();
             }
-            int err = 0;
-            for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
-                if(d.getKind() == Diagnostic.Kind.ERROR) {
-                  err++;
-                }
-            }
-            ok = (err == 0);
-        } else {
-            CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, files);
-            ok = task.call();
+            return ok;
+        } catch (IOException e) {
+            throw new Error(e);
         }
-        return ok;
     }
 
     static private boolean isPkgInfoPresent(Iterable<? extends JavaFileObject> files) {
--- a/test/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -46,18 +46,18 @@
     public static void main(String[] args) throws Exception {
         PrintWriter out = new PrintWriter(System.out, true);
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File testSrc = new File(System.getProperty("test.src"));
-        Iterable<? extends JavaFileObject> f =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java")));
-        JavacTask task = tool.getTask(out, fm, null, null, null, f);
-        Iterable<? extends CompilationUnitTree> trees = task.parse();
-        out.flush();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File testSrc = new File(System.getProperty("test.src"));
+            Iterable<? extends JavaFileObject> f =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java")));
+            JavacTask task = tool.getTask(out, fm, null, null, null, f);
+            Iterable<? extends CompilationUnitTree> trees = task.parse();
+            out.flush();
 
-        Scanner s = new Scanner();
-        for (CompilationUnitTree t: trees)
-            s.scan(t, null);
-
+            Scanner s = new Scanner();
+            for (CompilationUnitTree t: trees)
+                s.scan(t, null);
+        }
     }
 
     private static class Scanner extends TreeScanner<Void,Void> {
--- a/test/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -48,18 +48,18 @@
     public static void main(String[] args) throws Exception {
         PrintWriter out = new PrintWriter(System.out, true);
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File testSrc = new File(System.getProperty("test.src"));
-        Iterable<? extends JavaFileObject> f =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java")));
-        JavacTask task = tool.getTask(out, fm, null, null, null, f);
-        Iterable<? extends CompilationUnitTree> trees = task.parse();
-        out.flush();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File testSrc = new File(System.getProperty("test.src"));
+            Iterable<? extends JavaFileObject> f =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java")));
+            JavacTask task = tool.getTask(out, fm, null, null, null, f);
+            Iterable<? extends CompilationUnitTree> trees = task.parse();
+            out.flush();
 
-        Scanner s = new Scanner();
-        for (CompilationUnitTree t: trees)
-            s.scan(t, null);
-
+            Scanner s = new Scanner();
+            for (CompilationUnitTree t: trees)
+                s.scan(t, null);
+        }
     }
 
     private static class Scanner extends TreeScanner<Void,Void> {
--- a/test/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -47,18 +47,18 @@
     public static void main(String[] args) throws Exception {
         PrintWriter out = new PrintWriter(System.out, true);
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File testSrc = new File(System.getProperty("test.src"));
-        Iterable<? extends JavaFileObject> f =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java")));
-        JavacTask task = tool.getTask(out, fm, null, null, null, f);
-        Iterable<? extends CompilationUnitTree> trees = task.parse();
-        out.flush();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File testSrc = new File(System.getProperty("test.src"));
+            Iterable<? extends JavaFileObject> f =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java")));
+            JavacTask task = tool.getTask(out, fm, null, null, null, f);
+            Iterable<? extends CompilationUnitTree> trees = task.parse();
+            out.flush();
 
-        Scanner s = new Scanner();
-        for (CompilationUnitTree t: trees)
-            s.scan(t, null);
-
+            Scanner s = new Scanner();
+            for (CompilationUnitTree t: trees)
+                s.scan(t, null);
+        }
     }
 
     private static class Scanner extends TreeScanner<Void,Void> {
--- a/test/tools/javac/annotations/typeAnnotations/failures/CheckErrorsForSource7.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/annotations/typeAnnotations/failures/CheckErrorsForSource7.java	Wed Oct 29 17:25:23 2014 -0700
@@ -72,77 +72,78 @@
         File testSrc = new File(System.getProperty("test.src"));
         File testFile = new File(testSrc, args[0]);
         if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source");
-        JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
+        try (JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null)) {
 
-        //gather spans of the @TA annotations into typeAnnotationSpans:
-        JavacTask task = JavacTool.create().getTask(null,
-                                                    fm,
-                                                    null,
-                                                    Collections.<String>emptyList(),
-                                                    null,
-                                                    fm.getJavaFileObjects(testFile));
-        final Trees trees = Trees.instance(task);
-        final CompilationUnitTree cut = task.parse().iterator().next();
-        final List<int[]> typeAnnotationSpans = new ArrayList<>();
+            //gather spans of the @TA annotations into typeAnnotationSpans:
+            JavacTask task = JavacTool.create().getTask(null,
+                                                        fm,
+                                                        null,
+                                                        Collections.<String>emptyList(),
+                                                        null,
+                                                        fm.getJavaFileObjects(testFile));
+            final Trees trees = Trees.instance(task);
+            final CompilationUnitTree cut = task.parse().iterator().next();
+            final List<int[]> typeAnnotationSpans = new ArrayList<>();
 
-        new TreePathScanner<Void, Void>() {
-            @Override
-            public Void visitAnnotation(AnnotationTree node, Void p) {
-                if (node.getAnnotationType().getKind() == Kind.IDENTIFIER &&
-                    ((IdentifierTree) node.getAnnotationType()).getName().contentEquals("TA")) {
-                    int start = (int) trees.getSourcePositions().getStartPosition(cut, node);
-                    int end = (int) trees.getSourcePositions().getEndPosition(cut, node);
-                    typeAnnotationSpans.add(new int[] {start, end});
+            new TreePathScanner<Void, Void>() {
+                @Override
+                public Void visitAnnotation(AnnotationTree node, Void p) {
+                    if (node.getAnnotationType().getKind() == Kind.IDENTIFIER &&
+                        ((IdentifierTree) node.getAnnotationType()).getName().contentEquals("TA")) {
+                        int start = (int) trees.getSourcePositions().getStartPosition(cut, node);
+                        int end = (int) trees.getSourcePositions().getEndPosition(cut, node);
+                        typeAnnotationSpans.add(new int[] {start, end});
+                    }
+                    return null;
                 }
-                return null;
+            }.scan(cut, null);
+
+            //sort the spans in the reverse order, to simplify removing them from the source:
+            Collections.sort(typeAnnotationSpans, new Comparator<int[]>() {
+                @Override
+                public int compare(int[] o1, int[] o2) {
+                    return o2[0] - o1[0];
+                }
+            });
+
+            //verify the errors are produce correctly:
+            String originalSource = cut.getSourceFile().getCharContent(false).toString();
+
+            for (int[] toKeep : typeAnnotationSpans) {
+                //prepare updated source code by removing all the annotations except the toKeep one:
+                String updated = originalSource;
+
+                for (int[] span : typeAnnotationSpans) {
+                    if (span == toKeep) continue;
+
+                    updated = updated.substring(0, span[0]) + updated.substring(span[1]);
+                }
+
+                //parse and verify:
+                JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated);
+                DiagnosticCollector<JavaFileObject> errors = new DiagnosticCollector<>();
+                JavacTask task2 = JavacTool.create().getTask(null,
+                                                             fm,
+                                                             errors,
+                                                             Arrays.asList("-source", "7"),
+                                                             null,
+                                                             Arrays.asList(updatedFile));
+                task2.parse();
+
+                boolean found = false;
+
+                for (Diagnostic<? extends JavaFileObject> d : errors.getDiagnostics()) {
+                    if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERRORS.contains(d.getCode())) {
+                        if (found) {
+                            throw new IllegalStateException("More than one expected error found.");
+                        }
+                        found = true;
+                    }
+                }
+
+                if (!found)
+                    throw new IllegalStateException("Did not produce proper errors for: " + updated);
             }
-        }.scan(cut, null);
-
-        //sort the spans in the reverse order, to simplify removing them from the source:
-        Collections.sort(typeAnnotationSpans, new Comparator<int[]>() {
-            @Override
-            public int compare(int[] o1, int[] o2) {
-                return o2[0] - o1[0];
-            }
-        });
-
-        //verify the errors are produce correctly:
-        String originalSource = cut.getSourceFile().getCharContent(false).toString();
-
-        for (int[] toKeep : typeAnnotationSpans) {
-            //prepare updated source code by removing all the annotations except the toKeep one:
-            String updated = originalSource;
-
-            for (int[] span : typeAnnotationSpans) {
-                if (span == toKeep) continue;
-
-                updated = updated.substring(0, span[0]) + updated.substring(span[1]);
-            }
-
-            //parse and verify:
-            JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated);
-            DiagnosticCollector<JavaFileObject> errors = new DiagnosticCollector<>();
-            JavacTask task2 = JavacTool.create().getTask(null,
-                                                         fm,
-                                                         errors,
-                                                         Arrays.asList("-source", "7"),
-                                                         null,
-                                                         Arrays.asList(updatedFile));
-            task2.parse();
-
-            boolean found = false;
-
-            for (Diagnostic<? extends JavaFileObject> d : errors.getDiagnostics()) {
-                if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERRORS.contains(d.getCode())) {
-                    if (found) {
-                        throw new IllegalStateException("More than one expected error found.");
-                    }
-                    found = true;
-                }
-            }
-
-            if (!found)
-                throw new IllegalStateException("Did not produce proper errors for: " + updated);
         }
     }
 
--- a/test/tools/javac/api/6420409/T6420409.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/6420409/T6420409.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
@@ -46,21 +46,22 @@
 
     public static void main(String... args) throws IOException {
         final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
-        final StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        fm.setLocation(SOURCE_PATH,  Arrays.asList(test_classes)); // switcheroo !!!
-        fm.setLocation(CLASS_PATH,   Arrays.asList(test_src));
-        fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
-        final Iterable<? extends JavaFileObject> compilationUnits =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(test_src, "T6420409.java")));
-        tool.getTask(null,
-                     fm,
-                     null,
-                     Arrays.asList("-proc:none"),
-                     null,
-                     compilationUnits).call();
-        test(fm.getLocation(CLASS_PATH),   test_src,     CLASS_PATH);
-        test(fm.getLocation(SOURCE_PATH),  test_classes, SOURCE_PATH);
-        test(fm.getLocation(CLASS_OUTPUT), test_classes, CLASS_OUTPUT);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            fm.setLocation(SOURCE_PATH,  Arrays.asList(test_classes)); // switcheroo !!!
+            fm.setLocation(CLASS_PATH,   Arrays.asList(test_src));
+            fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
+            final Iterable<? extends JavaFileObject> compilationUnits =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(test_src, "T6420409.java")));
+            tool.getTask(null,
+                         fm,
+                         null,
+                         Arrays.asList("-proc:none"),
+                         null,
+                         compilationUnits).call();
+            test(fm.getLocation(CLASS_PATH),   test_src,     CLASS_PATH);
+            test(fm.getLocation(SOURCE_PATH),  test_classes, SOURCE_PATH);
+            test(fm.getLocation(CLASS_OUTPUT), test_classes, CLASS_OUTPUT);
+        }
     }
 
     static void test(Iterable<? extends File> path, File file, Location location) {
--- a/test/tools/javac/api/6420464/T6420464.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/6420464/T6420464.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
@@ -38,15 +38,16 @@
 
     public static void main(String... args) throws IOException {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager mgr = compiler.getStandardFileManager(null, null, null);
-        mgr.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(test_src));
-        JavaFileObject f = mgr.getJavaFileForInput(StandardLocation.SOURCE_PATH,
-                                                   "T6420464",
-                                                   JavaFileObject.Kind.SOURCE);
-        if (!f.isNameCompatible("T6420464", JavaFileObject.Kind.SOURCE))
-            throw new AssertionError("isNameCompatible(SOURCE) fails on " + f.toUri());
-        if (f.isNameCompatible("T6420464", JavaFileObject.Kind.OTHER))
-            throw new AssertionError("isNameCompatible(OTHER) fails on " + f.toUri());
-        System.out.println("OK");
+        try (StandardJavaFileManager mgr = compiler.getStandardFileManager(null, null, null)) {
+            mgr.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(test_src));
+            JavaFileObject f = mgr.getJavaFileForInput(StandardLocation.SOURCE_PATH,
+                                                       "T6420464",
+                                                       JavaFileObject.Kind.SOURCE);
+            if (!f.isNameCompatible("T6420464", JavaFileObject.Kind.SOURCE))
+                throw new AssertionError("isNameCompatible(SOURCE) fails on " + f.toUri());
+            if (f.isNameCompatible("T6420464", JavaFileObject.Kind.OTHER))
+                throw new AssertionError("isNameCompatible(OTHER) fails on " + f.toUri());
+            System.out.println("OK");
+        }
     }
 }
--- a/test/tools/javac/api/6431435/T6431435.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/6431435/T6431435.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
@@ -39,18 +39,19 @@
         String testSrc = System.getProperty("test.src", ".");
         String testClasses = System.getProperty("test.classes", ".");
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
-        fm.setLocation(StandardLocation.SOURCE_PATH, Arrays.asList(new File(testSrc)));
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(
-                new File(testSrc, "A.java")));
-        JavacTask task = tool.getTask(null, fm, null, null, null, files);
-        boolean ok = true;
-        ok &= check("parse", task.parse(), 1);       // A.java
-        ok &= check("analyze", task.analyze(), 3);   // A, Foo, p.B
-        ok &= check("generate", task.generate(), 5); // A, Foo, Foo$Baz, Foo$1, p.B
-        if (!ok)
-            throw new AssertionError("Test failed");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
+            fm.setLocation(StandardLocation.SOURCE_PATH, Arrays.asList(new File(testSrc)));
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(
+                    new File(testSrc, "A.java")));
+            JavacTask task = tool.getTask(null, fm, null, null, null, files);
+            boolean ok = true;
+            ok &= check("parse", task.parse(), 1);       // A.java
+            ok &= check("analyze", task.analyze(), 3);   // A, Foo, p.B
+            ok &= check("generate", task.generate(), 5); // A, Foo, Foo$Baz, Foo$1, p.B
+            if (!ok)
+                throw new AssertionError("Test failed");
+        }
     }
 
     private static boolean check(String name, Iterable<?> iter, int expect) {
--- a/test/tools/javac/api/7086261/T7086261.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/7086261/T7086261.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -66,10 +66,11 @@
 
     void test() throws Throwable {
         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
-        JavaFileManager jfm = javac.getStandardFileManager(null, null, null);
-        JavaCompiler.CompilationTask task =
-                javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource()));
-        task.call();
+        try (JavaFileManager jfm = javac.getStandardFileManager(null, null, null)) {
+            JavaCompiler.CompilationTask task =
+                    javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource()));
+            task.call();
+        }
     }
 
     public static void main(String[] args) throws Throwable {
--- a/test/tools/javac/api/8007344/Test.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/8007344/Test.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -83,14 +83,15 @@
         File testSrc = new File(System.getProperty("test.src"));
         File thisFile = new File(testSrc, getClass().getName() + ".java");
         JavacTool javac = JavacTool.create();
-        StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
-        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
-        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile);
-        testAnnoProcessor(javac, fm, fos, out, EXPECT_DOC_COMMENTS);
-        testTaskListener(javac, fm, fos, out, EXPECT_DOC_COMMENTS);
+        try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
+            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
+            Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile);
+            testAnnoProcessor(javac, fm, fos, out, EXPECT_DOC_COMMENTS);
+            testTaskListener(javac, fm, fos, out, EXPECT_DOC_COMMENTS);
 
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
+        }
     }
 
     void testAnnoProcessor(JavacTool javac, StandardJavaFileManager fm,
--- a/test/tools/javac/api/Sibling.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/Sibling.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2009, 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
@@ -39,17 +39,18 @@
 public class Sibling {
     public static void main(String... args) throws IOException {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
-        JavaFileObject sibling =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File("Test.java")))
-            .iterator().next();
-        JavaFileObject classFile =  fm.getJavaFileForOutput(CLASS_OUTPUT,
-                                                            "foo.bar.baz.Test",
-                                                            CLASS,
-                                                            sibling);
-        File file = new File("Test.class").getAbsoluteFile();
-        if (!classFile.toUri().equals(file.toURI()))
-            throw new AssertionError("Expected " + file.toURI() + ", got " +
-                                     classFile.toUri());
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            JavaFileObject sibling =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File("Test.java")))
+                .iterator().next();
+            JavaFileObject classFile =  fm.getJavaFileForOutput(CLASS_OUTPUT,
+                                                                "foo.bar.baz.Test",
+                                                                CLASS,
+                                                                sibling);
+            File file = new File("Test.class").getAbsoluteFile();
+            if (!classFile.toUri().equals(file.toURI()))
+                throw new AssertionError("Expected " + file.toURI() + ", got " +
+                                         classFile.toUri());
+        }
     }
 }
--- a/test/tools/javac/api/T6258271.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6258271.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -33,7 +33,7 @@
 import javax.tools.*;
 
 public class T6258271 {
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
         DiagnosticListener<JavaFileObject> dl =  new DiagnosticListener<JavaFileObject>() {
                 public void report(Diagnostic<? extends JavaFileObject> message) {
@@ -43,9 +43,10 @@
                     System.out.println(message);
                 }
             };
-        StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromStrings(Arrays.asList("nofile.java"));
-        javac.getTask(null, fm, dl, null, null, files).call();
+        try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromStrings(Arrays.asList("nofile.java"));
+            javac.getTask(null, fm, dl, null, null, files).call();
+        }
     }
 }
--- a/test/tools/javac/api/T6265137.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6265137.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -29,11 +29,12 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Arrays;
 import javax.tools.*;
 
 public class T6265137 {
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
         DiagnosticListener<JavaFileObject> dl =  new DiagnosticListener<JavaFileObject>() {
                 public void report(Diagnostic<? extends JavaFileObject> message) {
@@ -45,10 +46,11 @@
                     System.out.flush();
                 }
         };
-        StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
-        String srcdir = System.getProperty("test.src");
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6265137a.java")));
-        javac.getTask(null, fm, dl, Arrays.asList("-target","9"), null, files).call();
+        try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
+            String srcdir = System.getProperty("test.src");
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6265137a.java")));
+            javac.getTask(null, fm, dl, Arrays.asList("-target","9"), null, files).call();
+        }
     }
 }
--- a/test/tools/javac/api/T6306137.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6306137.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -87,10 +87,18 @@
         }
     }
 
+    void close() throws IOException {
+        fm.close();
+    }
+
     public static void main(String[] args) throws IOException {
         T6306137 self = new T6306137();
-        self.test("utf-8", true);
-        self.test("ascii", false);
-        self.test("utf-8", true);
+        try {
+            self.test("utf-8", true);
+            self.test("ascii", false);
+            self.test("utf-8", true);
+        } finally {
+            self.close();
+        }
     }
 }
--- a/test/tools/javac/api/T6345974.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6345974.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
@@ -45,17 +45,18 @@
     public static void main(String[] args) throws Exception {
         PrintWriter out = new PrintWriter(System.out, true);
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File testSrc = new File(System.getProperty("test.src"));
-        Iterable<? extends JavaFileObject> f =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
-        JavacTask task = tool.getTask(out, fm, null, null, null, f);
-        Iterable<? extends CompilationUnitTree> trees = task.parse();
-        out.flush();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File testSrc = new File(System.getProperty("test.src"));
+            Iterable<? extends JavaFileObject> f =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
+            JavacTask task = tool.getTask(out, fm, null, null, null, f);
+            Iterable<? extends CompilationUnitTree> trees = task.parse();
+            out.flush();
 
-        Scanner s = new Scanner();
-        for (CompilationUnitTree t: trees)
-            s.scan(t, null);
+            Scanner s = new Scanner();
+            for (CompilationUnitTree t: trees)
+                s.scan(t, null);
+        }
     }
 
     private static class Scanner extends TreeScanner<Void,Void> {
--- a/test/tools/javac/api/T6357331.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/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
+            }
         }
     }
 }
--- a/test/tools/javac/api/T6358786.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6358786.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -44,16 +44,17 @@
 public class T6358786 {
     public static void main(String... args) throws IOException {
         JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        String srcdir = System.getProperty("test.src");
-        File file = new File(srcdir, args[0]);
-        JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file)));
-        Elements elements = task.getElements();
-        for (TypeElement clazz : task.enter(task.parse())) {
-            String doc = elements.getDocComment(clazz);
-            if (doc == null)
-                throw new AssertionError(clazz.getSimpleName() + ": no doc comment");
-            System.out.format("%s: %s%n", clazz.getSimpleName(), doc);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            String srcdir = System.getProperty("test.src");
+            File file = new File(srcdir, args[0]);
+            JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file)));
+            Elements elements = task.getElements();
+            for (TypeElement clazz : task.enter(task.parse())) {
+                String doc = elements.getDocComment(clazz);
+                if (doc == null)
+                    throw new AssertionError(clazz.getSimpleName() + ": no doc comment");
+                System.out.format("%s: %s%n", clazz.getSimpleName(), doc);
+            }
         }
     }
 }
--- a/test/tools/javac/api/T6358955.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/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();
+                }
             }
         }
     }
--- a/test/tools/javac/api/T6392782.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6392782.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2010, 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
@@ -38,21 +38,22 @@
     public static void main(String... args) throws IOException {
         String testSrc = System.getProperty("test.src", ".");
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java")));
-        JavacTask task = tool.getTask(null, fm, null, null, null, files);
-        Iterable<? extends Tree> trees = task.parse();
-        TreeScanner<Integer,Void> scanner = new MyScanner();
-        check(scanner, 6, scanner.scan(trees, null));
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java")));
+            JavacTask task = tool.getTask(null, fm, null, null, null, files);
+            Iterable<? extends Tree> trees = task.parse();
+            TreeScanner<Integer,Void> scanner = new MyScanner();
+            check(scanner, 6, scanner.scan(trees, null));
 
-        CountNodes nodeCounter = new CountNodes();
-        // 359 nodes with the regular parser; 360 nodes with EndPosParser
-        // We automatically switch to EndPosParser when calling JavacTask.parse()
-        check(nodeCounter, 360, nodeCounter.scan(trees, null));
+            CountNodes nodeCounter = new CountNodes();
+            // 359 nodes with the regular parser; 360 nodes with EndPosParser
+            // We automatically switch to EndPosParser when calling JavacTask.parse()
+            check(nodeCounter, 362, nodeCounter.scan(trees, null));
 
-        CountIdentifiers idCounter = new CountIdentifiers();
-        check(idCounter, 107, idCounter.scan(trees, null));
+            CountIdentifiers idCounter = new CountIdentifiers();
+            check(idCounter, 107, idCounter.scan(trees, null));
+        }
     }
 
     private static void check(TreeScanner<?,?> scanner, int expect, int found) {
--- a/test/tools/javac/api/T6397104.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6397104.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2012, 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
@@ -65,16 +65,15 @@
     void test(boolean hasLocation, File siblingFile, String relName, String expectedPath)
         throws Exception
     {
-        StandardJavaFileManager fm;
-        if (hasLocation) {
-            for (Location location : StandardLocation.values()) {
-                fm = tool.getStandardFileManager(null, null, null);
-                fm.setLocation(location, Arrays.asList(new File(".")));
-                test(fm, location, siblingFile, relName, expectedPath);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            if (hasLocation) {
+                for (Location location : StandardLocation.values()) {
+                    fm.setLocation(location, Arrays.asList(new File(".")));
+                    test(fm, location, siblingFile, relName, expectedPath);
+                }
+            } else {
+                test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
             }
-        } else {
-            fm = tool.getStandardFileManager(null, null, null);
-            test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
         }
     }
 
--- a/test/tools/javac/api/T6400205.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6400205.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
@@ -28,22 +28,24 @@
  * @author  Peter von der Ah\u00e9
  */
 
+import java.io.IOException;
 import javax.tools.*;
 import static javax.tools.StandardLocation.*;
 
 public class T6400205 {
-    public static void main(String... args) {
-        JavaFileManager fm =
-            ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
-        try {
-            fm.getClassLoader(null);
-            throw new AssertionError("NullPointerException not thrown");
-        } catch (NullPointerException e) {
-            // expected result
+    public static void main(String... args) throws IOException {
+        try (JavaFileManager fm =
+                ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
+            try {
+                fm.getClassLoader(null);
+                throw new AssertionError("NullPointerException not thrown");
+            } catch (NullPointerException e) {
+                // expected result
+            }
+            ClassLoader cl = fm.getClassLoader(locationFor("bogus"));
+            if (cl != null)
+                throw new AssertionError("non-null class loader for bogus location");
+            System.err.println("Test PASSED.");
         }
-        ClassLoader cl = fm.getClassLoader(locationFor("bogus"));
-        if (cl != null)
-            throw new AssertionError("non-null class loader for bogus location");
-        System.err.println("Test PASSED.");
     }
 }
--- a/test/tools/javac/api/T6400207.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6400207.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
@@ -61,28 +61,29 @@
     }
 
     public static void main(String... args) throws Exception {
-        JavaFileManager fm =
-            ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
-        JavaFileManager.Location bogusLocation = locationFor("bogus");
-        JavaFileManager.Location knownLocation = CLASS_PATH;
-        String packageName = "java.lang";
-        Set<JavaFileObject.Kind> kinds = EnumSet.of(CLASS);
+        try (JavaFileManager fm =
+                ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
+            JavaFileManager.Location bogusLocation = locationFor("bogus");
+            JavaFileManager.Location knownLocation = CLASS_PATH;
+            String packageName = "java.lang";
+            Set<JavaFileObject.Kind> kinds = EnumSet.of(CLASS);
 
-        for (StandardLocation location : StandardLocation.values()) {
-            if (location != locationFor(location.getName()))
-                throw new AssertionError(location + " != locationFor(" +
-                                         location.getName() + ")");
+            for (StandardLocation location : StandardLocation.values()) {
+                if (location != locationFor(location.getName()))
+                    throw new AssertionError(location + " != locationFor(" +
+                                             location.getName() + ")");
+            }
+
+            testList(fm, null, null, null);
+            testList(fm, bogusLocation, packageName, kinds);
+            testList(fm, knownLocation, packageName, kinds);
+            testList(fm, null, packageName, kinds);
+            testList(fm, knownLocation, null, kinds);
+            testList(fm, knownLocation, packageName, null);
+            testList(fm, bogusLocation, null, kinds);
+            testList(fm, bogusLocation, packageName, null);
+
+            System.err.println("Test PASSED.");
         }
-
-        testList(fm, null, null, null);
-        testList(fm, bogusLocation, packageName, kinds);
-        testList(fm, knownLocation, packageName, kinds);
-        testList(fm, null, packageName, kinds);
-        testList(fm, knownLocation, null, kinds);
-        testList(fm, knownLocation, packageName, null);
-        testList(fm, bogusLocation, null, kinds);
-        testList(fm, bogusLocation, packageName, null);
-
-        System.err.println("Test PASSED.");
     }
 }
--- a/test/tools/javac/api/T6412669.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6412669.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2010, 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
@@ -64,22 +64,23 @@
         //System.err.println("toolsClasses: " + toolsClasses);
 
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses, toolsClasses));
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6412669.class.getName()+".java")));
-        String[] opts = { "-proc:only", "-processor", T6412669.class.getName()};
-        StringWriter sw = new StringWriter();
-        JavacTask task = tool.getTask(sw, fm, null, Arrays.asList(opts), null, files);
-        boolean ok = task.call();
-        String out = sw.toString();
-        if (!out.isEmpty())
-            System.err.println(out);
-        if (!ok)
-            throw new AssertionError("compilation of test program failed");
-        // verify we found an annotated element to exercise the SourcePositions API
-        if (!out.contains("processing element"))
-            throw new AssertionError("expected text not found in compilation output");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses, toolsClasses));
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6412669.class.getName()+".java")));
+            String[] opts = { "-proc:only", "-processor", T6412669.class.getName()};
+            StringWriter sw = new StringWriter();
+            JavacTask task = tool.getTask(sw, fm, null, Arrays.asList(opts), null, files);
+            boolean ok = task.call();
+            String out = sw.toString();
+            if (!out.isEmpty())
+                System.err.println(out);
+            if (!ok)
+                throw new AssertionError("compilation of test program failed");
+            // verify we found an annotated element to exercise the SourcePositions API
+            if (!out.contains("processing element"))
+                throw new AssertionError("expected text not found in compilation output");
+        }
     }
 
     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
--- a/test/tools/javac/api/T6419926.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6419926.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -35,17 +35,18 @@
 public class T6419926 {
     public static void main(String[] argv) throws Exception {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager mgr = compiler.getStandardFileManager( new DiagnosticCollector<JavaFileObject>(), null, null);
-        System.out.println( new File( new File(".").toURI() ).getAbsolutePath() );
-        mgr.setLocation(StandardLocation.CLASS_OUTPUT,
-                            Collections.singleton(new File(".")));
+        try (StandardJavaFileManager mgr = compiler.getStandardFileManager( new DiagnosticCollector<JavaFileObject>(), null, null)) {
+            System.out.println( new File( new File(".").toURI() ).getAbsolutePath() );
+            mgr.setLocation(StandardLocation.CLASS_OUTPUT,
+                                Collections.singleton(new File(".")));
 
-        FileObject fo = mgr.getFileForOutput(StandardLocation.CLASS_OUTPUT,
-                                "", "file.to.delete", null);
-        URI uri = fo.toUri();
-        System.out.println( uri );
+            FileObject fo = mgr.getFileForOutput(StandardLocation.CLASS_OUTPUT,
+                                    "", "file.to.delete", null);
+            URI uri = fo.toUri();
+            System.out.println( uri );
 
-        if (!"file".equals(uri.getScheme()))
-            throw new Exception("unexpected scheme for uri: " + uri.getScheme());
+            if (!"file".equals(uri.getScheme()))
+                throw new Exception("unexpected scheme for uri: " + uri.getScheme());
+        }
     }
 }
--- a/test/tools/javac/api/T6430241.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6430241.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
     /*
-     * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+     * Copyright (c) 2011, 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
@@ -134,21 +134,22 @@
             System.err.println("test task API: " + pcp);
 
             JavacTool tool = JavacTool.create();
-            StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
+            try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
 
-            if (pcp != null)
-                fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
+                if (pcp != null)
+                    fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
 
-            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
+                Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
 
-            StringWriter sw = new StringWriter();
-            PrintWriter pw = new PrintWriter(sw);
-            JavacTask task = tool.getTask(pw, fm, null, null, null, files);
-            boolean ok = task.call();
-            String out = showOutput(sw.toString());
+                StringWriter sw = new StringWriter();
+                PrintWriter pw = new PrintWriter(sw);
+                JavacTask task = tool.getTask(pw, fm, null, null, null, files);
+                boolean ok = task.call();
+                String out = showOutput(sw.toString());
 
-            checkCompilationOK(ok);
-            checkOutput(out, expectWarnings);
+                checkCompilationOK(ok);
+                checkOutput(out, expectWarnings);
+            }
         }
 
         //----- utility methods
--- a/test/tools/javac/api/T6431879.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6431879.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
@@ -39,18 +39,18 @@
         String testSrc = System.getProperty("test.src", ".");
         String testClasses = System.getProperty("test.classes", ".");
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6431879.class.getName()+".java")));
-        JavacTask task = tool.getTask(null, fm, null, null, null, files);
-        Iterable<? extends CompilationUnitTree> trees = task.parse();
-        TreeScanner<Void,Trees> dependencyScanner = new DependencyScanner();
-        Trees treeUtil = Trees.instance(task);
-        for (CompilationUnitTree unit : trees) {
-            //System.err.println("scan " + unit);
-            dependencyScanner.scan(unit, treeUtil);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6431879.class.getName()+".java")));
+            JavacTask task = tool.getTask(null, fm, null, null, null, files);
+            Iterable<? extends CompilationUnitTree> trees = task.parse();
+            TreeScanner<Void,Trees> dependencyScanner = new DependencyScanner();
+            Trees treeUtil = Trees.instance(task);
+            for (CompilationUnitTree unit : trees) {
+                //System.err.println("scan " + unit);
+                dependencyScanner.scan(unit, treeUtil);
+            }
         }
-
     }
 
     private static class DependencyScanner<R,P> extends TreePathScanner<R,P> {
--- a/test/tools/javac/api/T6483788.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6483788.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -42,14 +42,15 @@
     void run() throws Exception {
         File jar = createJar();
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
-        fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(jar));
-        JavaFileObject fo = fm.getJavaFileForInput(StandardLocation.CLASS_PATH, "dummy", JavaFileObject.Kind.CLASS);
-        System.err.println("file: " + fo);
-        URI uri = fo.toUri();
-        System.err.println("uri: " + uri);
-        if (uri.toString().contains(" "))
-            throw new Exception("unexpected space character found");
+        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(jar));
+            JavaFileObject fo = fm.getJavaFileForInput(StandardLocation.CLASS_PATH, "dummy", JavaFileObject.Kind.CLASS);
+            System.err.println("file: " + fo);
+            URI uri = fo.toUri();
+            System.err.println("uri: " + uri);
+            if (uri.toString().contains(" "))
+                throw new Exception("unexpected space character found");
+        }
     }
 
     File createJar() throws IOException {
--- a/test/tools/javac/api/T6501502.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/T6501502.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -46,16 +46,18 @@
     // we test a number of platform-independent paths.
     void run() throws Exception {
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        fm = c.getStandardFileManager(null, null, null);
-        System.err.println(System.getProperties());
-        File tmpDir = new File(System.getProperty("java.io.tmpdir"));
-        File testSrcDir = new File(System.getProperty("test.src"));
-        File testClassesDir = new File(System.getProperty("test.classes"));
-        test(new File("abc.tmp"));
-        test(new File(tmpDir, "bad.file"));
-        test(new File(testSrcDir, "T6501501.java"));
-        test(new File(testClassesDir, "T6501501.class"));
-        test(new File("a b"));
+        try (StandardJavaFileManager sfm = c.getStandardFileManager(null, null, null)) {
+            fm = sfm;
+            System.err.println(System.getProperties());
+            File tmpDir = new File(System.getProperty("java.io.tmpdir"));
+            File testSrcDir = new File(System.getProperty("test.src"));
+            File testClassesDir = new File(System.getProperty("test.classes"));
+            test(new File("abc.tmp"));
+            test(new File(tmpDir, "bad.file"));
+            test(new File(testSrcDir, "T6501501.java"));
+            test(new File(testClassesDir, "T6501501.class"));
+            test(new File("a b"));
+        }
     }
 
     void test(File f) throws Exception {
--- a/test/tools/javac/api/TestClientCodeWrapper.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestClientCodeWrapper.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -56,34 +56,36 @@
      */
     void run() throws Exception {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        defaultFileManager = compiler.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            defaultFileManager = fm;
 
-        for (Method m: getMethodsExcept(JavaFileManager.class, "close", "getJavaFileForInput")) {
-            test(m);
+            for (Method m: getMethodsExcept(JavaFileManager.class, "close", "getJavaFileForInput")) {
+                test(m);
+            }
+
+            for (Method m: getMethodsExcept(FileObject.class, "delete")) {
+                test(m);
+            }
+
+            for (Method m: getMethods(JavaFileObject.class)) {
+                test(m);
+            }
+
+            for (Method m: getMethodsExcept(Processor.class, "getCompletions")) {
+                test(m);
+            }
+
+            for (Method m: DiagnosticListener.class.getDeclaredMethods()) {
+                test(m);
+            }
+
+            for (Method m: TaskListener.class.getDeclaredMethods()) {
+                test(m);
+            }
+
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
         }
-
-        for (Method m: getMethodsExcept(FileObject.class, "delete")) {
-            test(m);
-        }
-
-        for (Method m: getMethods(JavaFileObject.class)) {
-            test(m);
-        }
-
-        for (Method m: getMethodsExcept(Processor.class, "getCompletions")) {
-            test(m);
-        }
-
-        for (Method m: DiagnosticListener.class.getDeclaredMethods()) {
-            test(m);
-        }
-
-        for (Method m: TaskListener.class.getDeclaredMethods()) {
-            test(m);
-        }
-
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
     }
 
     /** Get a sorted set of the methods declared on a class. */
--- a/test/tools/javac/api/TestDocComments.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestDocComments.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -52,23 +52,23 @@
         File file = new File(testSrc, "TestDocComments.java");
 
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+            Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
+            JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
+            Iterable<? extends CompilationUnitTree> units = task.parse();
+            Trees trees = Trees.instance(task);
 
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
-        Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
-        JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
-        Iterable<? extends CompilationUnitTree> units = task.parse();
-        Trees trees = Trees.instance(task);
+            CommentScanner s = new CommentScanner();
+            int n = s.scan(units, trees);
 
-        CommentScanner s = new CommentScanner();
-        int n = s.scan(units, trees);
+            if (n != 12)
+                error("Unexpected number of doc comments found: " + n);
 
-        if (n != 12)
-            error("Unexpected number of doc comments found: " + n);
-
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
+        }
     }
 
     /**
--- a/test/tools/javac/api/TestGetElementReference.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestGetElementReference.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -50,31 +50,32 @@
 
     public static void main(String... args) throws IOException {
         File source = new File(System.getProperty("test.src", "."), "TestGetElementReferenceData.java").getAbsoluteFile();
-        StandardJavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
-        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
-        JavacTask ct = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, diagnostics, Arrays.asList("-Xjcov"), null, fm.getJavaFileObjects(source));
-        Trees trees = Trees.instance(ct);
-        CompilationUnitTree cut = ct.parse().iterator().next();
+        try (StandardJavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
+            DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
+            JavacTask ct = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, diagnostics, Arrays.asList("-Xjcov"), null, fm.getJavaFileObjects(source));
+            Trees trees = Trees.instance(ct);
+            CompilationUnitTree cut = ct.parse().iterator().next();
 
-        ct.analyze();
+            ct.analyze();
 
-        for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
-            if (d.getKind() == Diagnostic.Kind.ERROR) {
-                throw new IllegalStateException("Should have been attributed without errors: " + diagnostics.getDiagnostics());
+            for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
+                if (d.getKind() == Diagnostic.Kind.ERROR) {
+                    throw new IllegalStateException("Should have been attributed without errors: " + diagnostics.getDiagnostics());
+                }
             }
-        }
 
-        Pattern p = Pattern.compile("/\\*getElement:(.*?)\\*/");
-        Matcher m = p.matcher(cut.getSourceFile().getCharContent(false));
+            Pattern p = Pattern.compile("/\\*getElement:(.*?)\\*/");
+            Matcher m = p.matcher(cut.getSourceFile().getCharContent(false));
 
-        while (m.find()) {
-            TreePath tp = pathFor(trees, cut, m.start() - 1);
-            Element found = trees.getElement(tp);
-            String expected = m.group(1);
-            String actual = found != null ? found.getKind() + ":" + symbolToString(found) : "<null>";
+            while (m.find()) {
+                TreePath tp = pathFor(trees, cut, m.start() - 1);
+                Element found = trees.getElement(tp);
+                String expected = m.group(1);
+                String actual = found != null ? found.getKind() + ":" + symbolToString(found) : "<null>";
 
-            if (!expected.equals(actual)) {
-                throw new IllegalStateException("expected=" + expected + "; actual=" + actual);
+                if (!expected.equals(actual)) {
+                    throw new IllegalStateException("expected=" + expected + "; actual=" + actual);
+                }
             }
         }
     }
--- a/test/tools/javac/api/TestGetScope.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestGetScope.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -29,6 +29,7 @@
 
 import com.sun.source.tree.IdentifierTree;
 import java.io.File;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -51,24 +52,25 @@
 
 @SupportedAnnotationTypes("*")
 public class TestGetScope extends AbstractProcessor {
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         new TestGetScope().run();
     }
 
-    public void run() {
+    public void run() throws IOException {
         File srcDir = new File(System.getProperty("test.src"));
         File thisFile = new File(srcDir, getClass().getName() + ".java");
 
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
 
-        List<String> opts = Arrays.asList("-proc:only", "-doe");
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
-        JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files);
-        t.setProcessors(Collections.singleton(this));
-        boolean ok = t.call();
-        if (!ok)
-            throw new Error("compilation failed");
+            List<String> opts = Arrays.asList("-proc:only", "-doe");
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
+            JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files);
+            t.setProcessors(Collections.singleton(this));
+            boolean ok = t.call();
+            if (!ok)
+                throw new Error("compilation failed");
+        }
     }
 
     @Override
--- a/test/tools/javac/api/TestJavacTask.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestJavacTask.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -41,8 +41,8 @@
 
 public class TestJavacTask {
     static final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+    static final StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
     static JavacTaskImpl getTask(File... file) {
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
         Iterable<? extends JavaFileObject> files =
             fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
         return (JavacTaskImpl)compiler.getTask(null, fm, null, null, null, files);
@@ -69,7 +69,11 @@
     }
 
     public static void main(String... args) throws IOException {
-        basicTest(args);
-        checkKindError();
+        try {
+            basicTest(args);
+            checkKindError();
+        } finally {
+            fm.close();
+        }
     }
 }
--- a/test/tools/javac/api/TestJavacTask_Lock.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestJavacTask_Lock.java	Wed Oct 29 17:25:23 2014 -0700
@@ -67,15 +67,18 @@
     void run() throws Exception {
         comp = ToolProvider.getSystemJavaCompiler();
         fm = comp.getStandardFileManager(null, null, null);
+        try {
+            for (MethodKind first: MethodKind.values()) {
+                for (MethodKind second: MethodKind.values()) {
+                    test(first, second);
+                }
+            }
 
-        for (MethodKind first: MethodKind.values()) {
-            for (MethodKind second: MethodKind.values()) {
-                test(first, second);
-            }
+            if (errors > 0)
+                throw new Exception(errors + " errors found");
+        } finally {
+            fm.close();
         }
-
-        if (errors > 0)
-            throw new Exception(errors + " errors found");
     }
 
     void test(MethodKind first, MethodKind second) {
--- a/test/tools/javac/api/TestJavacTask_Multiple.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestJavacTask_Multiple.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -68,16 +68,19 @@
     void run() throws Exception {
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
         StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-        for (TestKind tk: TestKind.values()) {
-            test(comp, fm, tk);
+        try {
+            for (TestKind tk: TestKind.values()) {
+                test(comp, fm, tk);
+            }
+
+            int expect = TestKind.values().length * MAX_TASKS;
+            if (count != expect) {
+                throw new Exception("Unexpected number of tests completed: " + count
+                        + ", expected: " + expect);
+            }
+        } finally {
+            fm.close();
         }
-
-        int expect = TestKind.values().length * MAX_TASKS;
-        if (count != expect) {
-            throw new Exception("Unexpected number of tests completed: " + count
-                    + ", expected: " + expect);
-        }
-
     }
 
     void test(JavaCompiler comp, StandardJavaFileManager fm, TestKind tk) {
--- a/test/tools/javac/api/TestJavacTask_ParseAttrGen.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestJavacTask_ParseAttrGen.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -45,14 +45,17 @@
     void run() throws Exception {
         comp = ToolProvider.getSystemJavaCompiler();
         fm = comp.getStandardFileManager(null, null, null);
-
-        final boolean[] booleanValues = { false, true };
-        for (boolean pk: booleanValues) {
-            for (boolean ak: booleanValues) {
-                for (boolean gk: booleanValues) {
-                    test(pk, ak, gk);
+        try {
+            final boolean[] booleanValues = { false, true };
+            for (boolean pk: booleanValues) {
+                for (boolean ak: booleanValues) {
+                    for (boolean gk: booleanValues) {
+                        test(pk, ak, gk);
+                    }
                 }
             }
+        } finally {
+            fm.close();
         }
     }
 
--- a/test/tools/javac/api/TestSearchPaths.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestSearchPaths.java	Wed Oct 29 17:25:23 2014 -0700
@@ -76,30 +76,33 @@
     void run() throws Exception {
         compiler = ToolProvider.getSystemJavaCompiler();
         fileManager = compiler.getStandardFileManager(null, null, null);
+        try {
+            // basic output path
+            testClassOutput();
 
-        // basic output path
-        testClassOutput();
+            // basic search paths
+            testClassPath();
+            testSourcePath();
+            testPlatformClassPath();
 
-        // basic search paths
-        testClassPath();
-        testSourcePath();
-        testPlatformClassPath();
+            // annotation processing
+            testAnnotationProcessorPath();
+            testSourceOutput();
 
-        // annotation processing
-        testAnnotationProcessorPath();
-        testSourceOutput();
+            // javah equivalent
+            testNativeHeaderOutput();
 
-        // javah equivalent
-        testNativeHeaderOutput();
+            // future-proof: guard against new StandardLocations being added
+            if (!tested.equals(EnumSet.allOf(StandardLocation.class))) {
+                error("not all standard locations have been tested");
+                out.println("not yet tested: " + EnumSet.complementOf(tested));
+            }
 
-        // future-proof: guard against new StandardLocations being added
-        if (!tested.equals(EnumSet.allOf(StandardLocation.class))) {
-            error("not all standard locations have been tested");
-            out.println("not yet tested: " + EnumSet.complementOf(tested));
-        }
-
-        if (errors > 0) {
-            throw new Exception(errors + " errors occurred");
+            if (errors > 0) {
+                throw new Exception(errors + " errors occurred");
+            }
+        } finally {
+            fileManager.close();
         }
     }
 
--- a/test/tools/javac/api/TestTreePath.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestTreePath.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
@@ -105,17 +105,18 @@
 
     public void run() throws IOException {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fileManager
-            = compiler.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> tests
-            = fileManager.getJavaFileObjects(writeTestFile());
+        try (StandardJavaFileManager fileManager
+                = compiler.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> tests
+                = fileManager.getJavaFileObjects(writeTestFile());
 
-        JavaCompiler.CompilationTask task =
-            ToolProvider.getSystemJavaCompiler().getTask(
-                    null, null, null,
-                    Arrays.asList("-processor", this.getClass().getName()), null,
-                    tests);
-        task.call();
+            JavaCompiler.CompilationTask task =
+                ToolProvider.getSystemJavaCompiler().getTask(
+                        null, null, null,
+                        Arrays.asList("-processor", this.getClass().getName()), null,
+                        tests);
+            task.call();
+        }
     }
 
     public static void main(String[] args) throws IOException {
--- a/test/tools/javac/api/TestTrees.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/TestTrees.java	Wed Oct 29 17:25:23 2014 -0700
@@ -74,29 +74,30 @@
                 }
             };
 
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
 
-        Iterable<String> opts = Arrays.asList("-d", ".", "-XDcompilePolicy=simple");
+            Iterable<String> opts = Arrays.asList("-d", ".", "-XDcompilePolicy=simple");
 
-        System.err.println("simple compilation, no processing");
-        JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
-        task.setTaskListener(new MyTaskListener(task));
-        if (!task.call())
-            throw new AssertionError("compilation failed");
+            System.err.println("simple compilation, no processing");
+            JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
+            task.setTaskListener(new MyTaskListener(task));
+            if (!task.call())
+                throw new AssertionError("compilation failed");
 
-        opts =  Arrays.asList("-d", ".", "-processorpath", testClassDir, "-processor", self,
-            "-XDcompilePolicy=simple");
+            opts =  Arrays.asList("-d", ".", "-processorpath", testClassDir, "-processor", self,
+                "-XDcompilePolicy=simple");
 
-        System.err.println();
-        System.err.println("compilation with processing");
-        task = tool.getTask(out, fm, dl,opts, null, files);
-        if (!task.call())
-            throw new AssertionError("compilation failed");
+            System.err.println();
+            System.err.println("compilation with processing");
+            task = tool.getTask(out, fm, dl,opts, null, files);
+            if (!task.call())
+                throw new AssertionError("compilation failed");
 
-        if (errors > 0)
-            throw new AssertionError(errors + " errors occurred");
+            if (errors > 0)
+                throw new AssertionError(errors + " errors occurred");
+        }
     }
 
     void testElement(Trees trees, Element e) {
--- a/test/tools/javac/api/taskListeners/CompileEvent.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/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) {
--- a/test/tools/javac/api/taskListeners/EventsBalancedTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/taskListeners/EventsBalancedTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -44,7 +44,12 @@
     StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
 
     public static void main(String... args) throws IOException {
-        new EventsBalancedTest().test();
+        EventsBalancedTest t = new EventsBalancedTest();
+        try {
+            t.test();
+        } finally {
+            t.fm.close();
+        }
     }
 
     void test() throws IOException {
--- a/test/tools/javac/api/taskListeners/TestSimpleAddRemove.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/api/taskListeners/TestSimpleAddRemove.java	Wed Oct 29 17:25:23 2014 -0700
@@ -203,7 +203,12 @@
     }
 
     public static void main(String... args) throws Exception {
-        new TestSimpleAddRemove().run();
+        TestSimpleAddRemove t = new TestSimpleAddRemove();
+        try {
+            t.run();
+        } finally {
+            t.fm.close();
+        }
     }
 
     JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler();
--- a/test/tools/javac/cast/intersection/IntersectionTypeParserTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/cast/intersection/IntersectionTypeParserTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -104,35 +104,36 @@
     public static void main(String... args) throws Exception {
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (CastKind ck : CastKind.values()) {
-            for (TypeKind t1 : TypeKind.values()) {
-                for (ArrayKind ak1 : ArrayKind.values()) {
-                    Type typ1 = new Type(t1, ak1);
-                    if (ck.nBounds == 1) {
-                        new IntersectionTypeParserTest(ck, typ1).run(comp, fm);
-                        continue;
-                    }
-                    for (TypeKind t2 : TypeKind.values()) {
-                        for (ArrayKind ak2 : ArrayKind.values()) {
-                            Type typ2 = new Type(t2, ak2);
-                            if (ck.nBounds == 2) {
-                                new IntersectionTypeParserTest(ck, typ1, typ2).run(comp, fm);
-                                continue;
-                            }
-                            for (TypeKind t3 : TypeKind.values()) {
-                                for (ArrayKind ak3 : ArrayKind.values()) {
-                                    Type typ3 = new Type(t3, ak3);
-                                    new IntersectionTypeParserTest(ck, typ1, typ2, typ3).run(comp, fm);
+            for (CastKind ck : CastKind.values()) {
+                for (TypeKind t1 : TypeKind.values()) {
+                    for (ArrayKind ak1 : ArrayKind.values()) {
+                        Type typ1 = new Type(t1, ak1);
+                        if (ck.nBounds == 1) {
+                            new IntersectionTypeParserTest(ck, typ1).run(comp, fm);
+                            continue;
+                        }
+                        for (TypeKind t2 : TypeKind.values()) {
+                            for (ArrayKind ak2 : ArrayKind.values()) {
+                                Type typ2 = new Type(t2, ak2);
+                                if (ck.nBounds == 2) {
+                                    new IntersectionTypeParserTest(ck, typ1, typ2).run(comp, fm);
+                                    continue;
+                                }
+                                for (TypeKind t3 : TypeKind.values()) {
+                                    for (ArrayKind ak3 : ArrayKind.values()) {
+                                        Type typ3 = new Type(t3, ak3);
+                                        new IntersectionTypeParserTest(ck, typ1, typ2, typ3).run(comp, fm);
+                                    }
                                 }
                             }
                         }
                     }
                 }
             }
+            System.out.println("Total check executed: " + checkCount);
         }
-        System.out.println("Total check executed: " + checkCount);
     }
 
     CastKind ck;
--- a/test/tools/javac/classreader/T7031108.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/classreader/T7031108.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -68,39 +68,40 @@
 
     void run() throws Exception {
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        // step 1: compile test classes
-        File cwd = new File(".");
-        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(cwd));
-        compile(comp, fm, null, null, pC);
+            // step 1: compile test classes
+            File cwd = new File(".");
+            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(cwd));
+            compile(comp, fm, null, null, pC);
 
-        // step 2: verify functioning of processor
-        fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
-                fm.getLocation(StandardLocation.CLASS_PATH));
-        fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(cwd));
-        compile(comp, fm, null, getClass().getName(), dummy);
+            // step 2: verify functioning of processor
+            fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
+                    fm.getLocation(StandardLocation.CLASS_PATH));
+            fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(cwd));
+            compile(comp, fm, null, getClass().getName(), dummy);
 
-        File pC_class = new File(new File("p"), "C.class");
-        pC_class.delete();
+            File pC_class = new File(new File("p"), "C.class");
+            pC_class.delete();
 
-        DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
-        compile(comp, fm, dc, getClass().getName(), dummy);
-        List<Diagnostic<? extends JavaFileObject>> diags =dc.getDiagnostics();
+            DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
+            compile(comp, fm, dc, getClass().getName(), dummy);
+            List<Diagnostic<? extends JavaFileObject>> diags =dc.getDiagnostics();
 
-        System.err.println(diags);
-        switch (diags.size()) {
-            case 0:
-                throw new Exception("no diagnostics received");
-            case 1:
-                String code = diags.get(0).getCode();
-                String expect = "compiler.err.proc.cant.access.1";
-                if (!expect.equals(code))
-                    throw new Exception("unexpected diag code: " + code
-                            + ", expected: " + expect);
-                break;
-            default:
-                throw new Exception("unexpected diags received");
+            System.err.println(diags);
+            switch (diags.size()) {
+                case 0:
+                    throw new Exception("no diagnostics received");
+                case 1:
+                    String code = diags.get(0).getCode();
+                    String expect = "compiler.err.proc.cant.access.1";
+                    if (!expect.equals(code))
+                        throw new Exception("unexpected diag code: " + code
+                                + ", expected: " + expect);
+                    break;
+                default:
+                    throw new Exception("unexpected diags received");
+            }
         }
     }
 
--- a/test/tools/javac/defaultMethods/DefaultMethodFlags.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/defaultMethods/DefaultMethodFlags.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -54,31 +54,32 @@
 
     void checkDefaultMethodFlags() throws IOException {
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> fos =
-                fm.getJavaFileObjectsFromFiles(
-                Arrays.asList(new File(
-                System.getProperty("test.src"),
-                this.getClass().getSimpleName() + ".java")));
-        JavacTask task = (JavacTask) c.getTask(null, fm, null, null, null, fos);
+        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> fos =
+                    fm.getJavaFileObjectsFromFiles(
+                    Arrays.asList(new File(
+                    System.getProperty("test.src"),
+                    this.getClass().getSimpleName() + ".java")));
+            JavacTask task = (JavacTask) c.getTask(null, fm, null, null, null, fos);
 
-        task.addTaskListener(new TaskListener() {
+            task.addTaskListener(new TaskListener() {
 
-            @Override
-            public void started(TaskEvent e) {}
+                @Override
+                public void started(TaskEvent e) {}
 
-            @Override
-            public void finished(TaskEvent e) {
-                if (e.getKind() == TaskEvent.Kind.ANALYZE) {
-                    TypeElement te = e.getTypeElement();
-                    if (te.getSimpleName().toString().equals("I")) {
-                        checkDefaultInterface(te);
+                @Override
+                public void finished(TaskEvent e) {
+                    if (e.getKind() == TaskEvent.Kind.ANALYZE) {
+                        TypeElement te = e.getTypeElement();
+                        if (te.getSimpleName().toString().equals("I")) {
+                            checkDefaultInterface(te);
+                        }
                     }
                 }
-            }
-        });
+            });
 
-        task.analyze();
+            task.analyze();
+        }
     }
 
     void checkDefaultInterface(TypeElement te) {
--- a/test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -123,18 +123,19 @@
 
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (MethodKind mk1 : MethodKind.values()) {
-            for (SignatureKind sk1 : SignatureKind.values()) {
-                for (BodyExpr be1 : BodyExpr.values()) {
-                    for (MethodKind mk2 : MethodKind.values()) {
-                        for (SignatureKind sk2 : SignatureKind.values()) {
-                            for (BodyExpr be2 : BodyExpr.values()) {
-                                for (MethodKind mk3 : MethodKind.values()) {
-                                    for (SignatureKind sk3 : SignatureKind.values()) {
-                                        for (BodyExpr be3 : BodyExpr.values()) {
-                                            new InterfaceMethodHidingTest(mk1, mk2, mk3, sk1, sk2, sk3, be1, be2, be3).run(comp, fm);
+            for (MethodKind mk1 : MethodKind.values()) {
+                for (SignatureKind sk1 : SignatureKind.values()) {
+                    for (BodyExpr be1 : BodyExpr.values()) {
+                        for (MethodKind mk2 : MethodKind.values()) {
+                            for (SignatureKind sk2 : SignatureKind.values()) {
+                                for (BodyExpr be2 : BodyExpr.values()) {
+                                    for (MethodKind mk3 : MethodKind.values()) {
+                                        for (SignatureKind sk3 : SignatureKind.values()) {
+                                            for (BodyExpr be3 : BodyExpr.values()) {
+                                                new InterfaceMethodHidingTest(mk1, mk2, mk3, sk1, sk2, sk3, be1, be2, be3).run(comp, fm);
+                                            }
                                         }
                                     }
                                 }
@@ -143,8 +144,8 @@
                     }
                 }
             }
+            System.out.println("Total check executed: " + checkCount);
         }
-        System.out.println("Total check executed: " + checkCount);
     }
 
     MethodKind mk1, mk2, mk3;
--- a/test/tools/javac/defaultMethods/syntax/TestDefaultMethodsSyntax.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/defaultMethods/syntax/TestDefaultMethodsSyntax.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -188,20 +188,21 @@
 
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (VersionKind vk : VersionKind.values()) {
-            for (EnclosingKind ek : EnclosingKind.values()) {
-                for (MethodKind mk : MethodKind.values()) {
-                    for (ModifierKind modk1 : ModifierKind.values()) {
-                        for (ModifierKind modk2 : ModifierKind.values()) {
-                            new TestDefaultMethodsSyntax(vk, ek, mk, modk1, modk2).run(comp, fm);
+            for (VersionKind vk : VersionKind.values()) {
+                for (EnclosingKind ek : EnclosingKind.values()) {
+                    for (MethodKind mk : MethodKind.values()) {
+                        for (ModifierKind modk1 : ModifierKind.values()) {
+                            for (ModifierKind modk2 : ModifierKind.values()) {
+                                new TestDefaultMethodsSyntax(vk, ek, mk, modk1, modk2).run(comp, fm);
+                            }
                         }
                     }
                 }
             }
+            System.out.println("Total check executed: " + checkCount);
         }
-        System.out.println("Total check executed: " + checkCount);
     }
 
     VersionKind vk;
--- a/test/tools/javac/diags/CheckResourceKeys.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/diags/CheckResourceKeys.java	Wed Oct 29 17:25:23 2014 -0700
@@ -313,27 +313,28 @@
     Set<String> getCodeStrings() throws IOException {
         Set<String> results = new TreeSet<String>();
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        JavaFileManager fm = c.getStandardFileManager(null, null, null);
-        JavaFileManager.Location javacLoc = findJavacLocation(fm);
-        String[] pkgs = {
-            "javax.annotation.processing",
-            "javax.lang.model",
-            "javax.tools",
-            "com.sun.source",
-            "com.sun.tools.javac"
-        };
-        for (String pkg: pkgs) {
-            for (JavaFileObject fo: fm.list(javacLoc,
-                    pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
-                String name = fo.getName();
-                // ignore resource files, and files which are not really part of javac
-                if (name.matches(".*resources.[A-Za-z_0-9]+\\.class.*")
-                        || name.matches(".*CreateSymbols\\.class.*"))
-                    continue;
-                scan(fo, results);
+        try (JavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            JavaFileManager.Location javacLoc = findJavacLocation(fm);
+            String[] pkgs = {
+                "javax.annotation.processing",
+                "javax.lang.model",
+                "javax.tools",
+                "com.sun.source",
+                "com.sun.tools.javac"
+            };
+            for (String pkg: pkgs) {
+                for (JavaFileObject fo: fm.list(javacLoc,
+                        pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
+                    String name = fo.getName();
+                    // ignore resource files, and files which are not really part of javac
+                    if (name.matches(".*resources.[A-Za-z_0-9]+\\.class.*")
+                            || name.matches(".*CreateSymbols\\.class.*"))
+                        continue;
+                    scan(fo, results);
+                }
             }
+            return results;
         }
-        return results;
     }
 
     // depending on how the test is run, javac may be on bootclasspath or classpath
--- a/test/tools/javac/doclint/DocLintTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/doclint/DocLintTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -109,44 +109,48 @@
     void run() throws Exception {
         javac = ToolProvider.getSystemJavaCompiler();
         fm = javac.getStandardFileManager(null, null, null);
-        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
-        file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
-            @Override
-            public CharSequence getCharContent(boolean ignoreEncoding) {
-                return code;
-            }
-        };
+        try {
+            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
+            file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
+                @Override
+                public CharSequence getCharContent(boolean ignoreEncoding) {
+                    return code;
+                }
+            };
 
-        test(Collections.<String>emptyList(),
-                Main.Result.OK,
-                EnumSet.noneOf(Message.class));
+            test(Collections.<String>emptyList(),
+                    Main.Result.OK,
+                    EnumSet.noneOf(Message.class));
 
-        test(Arrays.asList("-Xdoclint:none"),
-                Main.Result.OK,
-                EnumSet.noneOf(Message.class));
+            test(Arrays.asList("-Xdoclint:none"),
+                    Main.Result.OK,
+                    EnumSet.noneOf(Message.class));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
+            test(Arrays.asList(rawDiags, "-Xdoclint"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
-                Main.Result.OK,
-                EnumSet.of(Message.DL_WRN12));
+            test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
+                    Main.Result.OK,
+                    EnumSet.of(Message.DL_WRN12));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
+            test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR9));
+            test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR9));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
-                Main.Result.CMDERR,
-                EnumSet.of(Message.OPT_BADARG));
+            test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
+                    Main.Result.CMDERR,
+                    EnumSet.of(Message.OPT_BADARG));
 
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
+        } finally {
+            fm.close();
+        }
     }
 
     void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
--- a/test/tools/javac/doctree/DocTreePathScannerTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/doctree/DocTreePathScannerTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -66,22 +66,23 @@
         }
 
         JavacTool javac = JavacTool.create();
-        StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
 
-        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
+            Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
 
-        JavacTask t = javac.getTask(null, fm, null, null, null, fos);
-        DocTrees trees = DocTrees.instance(t);
+            JavacTask t = javac.getTask(null, fm, null, null, null, fos);
+            DocTrees trees = DocTrees.instance(t);
 
-        Iterable<? extends CompilationUnitTree> units = t.parse();
+            Iterable<? extends CompilationUnitTree> units = t.parse();
 
-        DeclScanner ds = new DeclScanner(trees);
-        for (CompilationUnitTree unit: units) {
-            ds.scan(unit, null);
+            DeclScanner ds = new DeclScanner(trees);
+            for (CompilationUnitTree unit: units) {
+                ds.scan(unit, null);
+            }
+
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
         }
-
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
     }
 
     void error(String msg) {
--- a/test/tools/javac/doctree/SimpleDocTreeVisitorTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/doctree/SimpleDocTreeVisitorTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -66,28 +66,29 @@
         }
 
         JavacTool javac = JavacTool.create();
-        StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
 
-        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
+            Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
 
-        JavacTask t = javac.getTask(null, fm, null, null, null, fos);
-        DocTrees trees = DocTrees.instance(t);
+            JavacTask t = javac.getTask(null, fm, null, null, null, fos);
+            DocTrees trees = DocTrees.instance(t);
 
-        Iterable<? extends CompilationUnitTree> units = t.parse();
+            Iterable<? extends CompilationUnitTree> units = t.parse();
 
-        Set<DocTree.Kind> found = EnumSet.noneOf(DocTree.Kind.class);
-        DeclScanner ds = new DeclScanner(trees, found);
-        for (CompilationUnitTree unit: units) {
-            ds.scan(unit, null);
+            Set<DocTree.Kind> found = EnumSet.noneOf(DocTree.Kind.class);
+            DeclScanner ds = new DeclScanner(trees, found);
+            for (CompilationUnitTree unit: units) {
+                ds.scan(unit, null);
+            }
+
+            for (DocTree.Kind k: DocTree.Kind.values()) {
+                if (!found.contains(k) && k != DocTree.Kind.OTHER)
+                    error("not found: " + k);
+            }
+
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
         }
-
-        for (DocTree.Kind k: DocTree.Kind.values()) {
-            if (!found.contains(k) && k != DocTree.Kind.OTHER)
-                error("not found: " + k);
-        }
-
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
     }
 
     void error(String msg) {
--- a/test/tools/javac/file/T7068451.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/file/T7068451.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -47,6 +47,7 @@
 import javax.tools.Diagnostic.Kind;
 import javax.tools.JavaCompiler;
 import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.StandardJavaFileManager;
 import javax.tools.StandardLocation;
 import javax.tools.ToolProvider;
 
@@ -75,34 +76,36 @@
         System.err.println("FIRST compilation");
         System.err.println();
 
-        CompilationTask task = compiler.getTask(null, null, null, opts, null,
-                compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input));
-        task.setProcessors(Collections.singleton(new Proc("first")));
-        check("compilation", task.call());
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            CompilationTask task = compiler.getTask(null, fm, null, opts, null,
+                    fm.getJavaFileObjects(input));
+            task.setProcessors(Collections.singleton(new Proc("first")));
+            check("compilation", task.call());
 
-        writeFile(tmp, "X.java", "package p; class X { { p.C.second(); } }");
+            writeFile(tmp, "X.java", "package p; class X { { p.C.second(); } }");
 
-        //Thread.sleep(2000);
+            //Thread.sleep(2000);
 
-        System.err.println();
-        System.err.println("SECOND compilation");
-        System.err.println();
+            System.err.println();
+            System.err.println("SECOND compilation");
+            System.err.println();
 
-        task = compiler.getTask(null, null, null, opts, null,
-                compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input));
-        task.setProcessors(Collections.singleton(new Proc("second")));
-        check("compilation", task.call());
+            task = compiler.getTask(null, fm, null, opts, null,
+                    fm.getJavaFileObjects(input));
+            task.setProcessors(Collections.singleton(new Proc("second")));
+            check("compilation", task.call());
 
-        //Thread.sleep(2000);
+            //Thread.sleep(2000);
 
-        System.err.println();
-        System.err.println("SECOND compilation, REPEATED");
-        System.err.println();
+            System.err.println();
+            System.err.println("SECOND compilation, REPEATED");
+            System.err.println();
 
-        task = compiler.getTask(null, null, null, opts, null,
-                compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input));
-        task.setProcessors(Collections.singleton(new Proc("second")));
-        check("compilation", task.call());
+            task = compiler.getTask(null, fm, null, opts, null,
+                    fm.getJavaFileObjects(input));
+            task.setProcessors(Collections.singleton(new Proc("second")));
+            check("compilation", task.call());
+        }
     }
 
     void check(String msg, boolean ok) {
--- a/test/tools/javac/flow/LVTHarness.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/flow/LVTHarness.java	Wed Oct 29 17:25:23 2014 -0700
@@ -76,18 +76,21 @@
     static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
 
     public static void main(String[] args) throws Exception {
+        try {
+            String testDir = System.getProperty("test.src");
+            fm.setLocation(SOURCE_PATH, Arrays.asList(new File(testDir, "tests")));
 
-        String testDir = System.getProperty("test.src");
-        fm.setLocation(SOURCE_PATH, Arrays.asList(new File(testDir, "tests")));
+            // Make sure classes are written to scratch dir.
+            fm.setLocation(CLASS_OUTPUT, Arrays.asList(new File(".")));
 
-        // Make sure classes are written to scratch dir.
-        fm.setLocation(CLASS_OUTPUT, Arrays.asList(new File(".")));
-
-        for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(SOURCE), true)) {
-            new LVTHarness(jfo).check();
-        }
-        if (nerrors > 0) {
-            throw new AssertionError("Errors were found");
+            for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(SOURCE), true)) {
+                new LVTHarness(jfo).check();
+            }
+            if (nerrors > 0) {
+                throw new AssertionError("Errors were found");
+            }
+        } finally {
+            fm.close();
         }
     }
 
--- a/test/tools/javac/generics/bridges/BridgeHarness.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/generics/bridges/BridgeHarness.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -70,19 +70,23 @@
     static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
 
     public static void main(String[] args) throws Exception {
-        //set sourcepath
-        fm.setLocation(SOURCE_PATH,
-                Arrays.asList(new File(System.getProperty("test.src"), "tests")));
-        //set output (-d)
-        fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT,
-                Arrays.asList(new File(System.getProperty("user.dir"))));
-        for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
-            //for each source, compile and check against annotations
-            new BridgeHarness(jfo).compileAndCheck();
-        }
-        //if there were errors, fail
-        if (nerrors > 0) {
-            throw new AssertionError("Errors were found");
+        try {
+            //set sourcepath
+            fm.setLocation(SOURCE_PATH,
+                    Arrays.asList(new File(System.getProperty("test.src"), "tests")));
+            //set output (-d)
+            fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT,
+                    Arrays.asList(new File(System.getProperty("user.dir"))));
+            for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
+                //for each source, compile and check against annotations
+                new BridgeHarness(jfo).compileAndCheck();
+            }
+            //if there were errors, fail
+            if (nerrors > 0) {
+                throw new AssertionError("Errors were found");
+            }
+        } finally {
+            fm.close();
         }
     }
 
--- a/test/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -150,17 +150,17 @@
 
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
-        for (BoundKind boundKind : BoundKind.values()) {
-            for (ConstructorKind constructorKind : ConstructorKind.values()) {
-                for (TypeArgumentKind declArgKind : TypeArgumentKind.values()) {
-                    for (TypeArgArity arity : TypeArgArity.values()) {
-                        for (TypeArgumentKind useArgKind : TypeArgumentKind.values()) {
-                            for (TypeArgumentKind diamondArgKind : TypeArgumentKind.values()) {
-                                for (ArgumentKind argKind : ArgumentKind.values()) {
-                                    new GenericConstructorAndDiamondTest(boundKind, constructorKind,
-                                            declArgKind, arity, useArgKind, diamondArgKind, argKind).run(comp, fm);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
+            for (BoundKind boundKind : BoundKind.values()) {
+                for (ConstructorKind constructorKind : ConstructorKind.values()) {
+                    for (TypeArgumentKind declArgKind : TypeArgumentKind.values()) {
+                        for (TypeArgArity arity : TypeArgArity.values()) {
+                            for (TypeArgumentKind useArgKind : TypeArgumentKind.values()) {
+                                for (TypeArgumentKind diamondArgKind : TypeArgumentKind.values()) {
+                                    for (ArgumentKind argKind : ArgumentKind.values()) {
+                                        new GenericConstructorAndDiamondTest(boundKind, constructorKind,
+                                                declArgKind, arity, useArgKind, diamondArgKind, argKind).run(comp, fm);
+                                    }
                                 }
                             }
                         }
--- a/test/tools/javac/generics/diamond/7030687/ParserTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/generics/diamond/7030687/ParserTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -78,26 +78,27 @@
 
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (TypeQualifierArity arity : TypeQualifierArity.values()) {
-            for (TypeArgumentKind tak1 : TypeArgumentKind.values()) {
-                if (arity == TypeQualifierArity.ONE) {
-                    new ParserTest(arity, tak1).run(comp, fm);
-                    continue;
-                }
-                for (TypeArgumentKind tak2 : TypeArgumentKind.values()) {
-                    if (arity == TypeQualifierArity.TWO) {
-                        new ParserTest(arity, tak1, tak2).run(comp, fm);
+            for (TypeQualifierArity arity : TypeQualifierArity.values()) {
+                for (TypeArgumentKind tak1 : TypeArgumentKind.values()) {
+                    if (arity == TypeQualifierArity.ONE) {
+                        new ParserTest(arity, tak1).run(comp, fm);
                         continue;
                     }
-                    for (TypeArgumentKind tak3 : TypeArgumentKind.values()) {
-                        if (arity == TypeQualifierArity.THREE) {
-                            new ParserTest(arity, tak1, tak2, tak3).run(comp, fm);
+                    for (TypeArgumentKind tak2 : TypeArgumentKind.values()) {
+                        if (arity == TypeQualifierArity.TWO) {
+                            new ParserTest(arity, tak1, tak2).run(comp, fm);
                             continue;
                         }
-                        for (TypeArgumentKind tak4 : TypeArgumentKind.values()) {
-                            new ParserTest(arity, tak1, tak2, tak3, tak4).run(comp, fm);
+                        for (TypeArgumentKind tak3 : TypeArgumentKind.values()) {
+                            if (arity == TypeQualifierArity.THREE) {
+                                new ParserTest(arity, tak1, tak2, tak3).run(comp, fm);
+                                continue;
+                            }
+                            for (TypeArgumentKind tak4 : TypeArgumentKind.values()) {
+                                new ParserTest(arity, tak1, tak2, tak3, tak4).run(comp, fm);
+                            }
                         }
                     }
                 }
--- a/test/tools/javac/generics/inference/7086601/T7086601b.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/generics/inference/7086601/T7086601b.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -86,18 +86,19 @@
 
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (TypeKind a1 : TypeKind.values()) {
-            for (TypeKind a2 : TypeKind.values()) {
-                for (TypeKind a3 : TypeKind.values()) {
-                    for (MethodCallKind mck : MethodCallKind.values()) {
-                        new T7086601b(a1, a2, a3, mck).run(comp, fm);
+            for (TypeKind a1 : TypeKind.values()) {
+                for (TypeKind a2 : TypeKind.values()) {
+                    for (TypeKind a3 : TypeKind.values()) {
+                        for (MethodCallKind mck : MethodCallKind.values()) {
+                            new T7086601b(a1, a2, a3, mck).run(comp, fm);
+                        }
                     }
                 }
             }
+            System.out.println("Total check executed: " + checkCount);
         }
-        System.out.println("Total check executed: " + checkCount);
     }
 
     TypeKind a1;
--- a/test/tools/javac/lambda/BadLambdaExpr.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/lambda/BadLambdaExpr.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -105,18 +105,19 @@
 
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (ParameterListKind plk : ParameterListKind.values()) {
-            for (ParameterKind pk : ParameterKind.values()) {
-                for (ArrowKind ak : ArrowKind.values()) {
-                    for (ExprKind ek : ExprKind.values()) {
-                        new BadLambdaExpr(plk, pk, ak, ek).run(comp, fm);
+            for (ParameterListKind plk : ParameterListKind.values()) {
+                for (ParameterKind pk : ParameterKind.values()) {
+                    for (ArrowKind ak : ArrowKind.values()) {
+                        for (ExprKind ek : ExprKind.values()) {
+                            new BadLambdaExpr(plk, pk, ak, ek).run(comp, fm);
+                        }
                     }
                 }
             }
+            System.out.println("Total check executed: " + checkCount);
         }
-        System.out.println("Total check executed: " + checkCount);
     }
 
     ParameterListKind plk;
--- a/test/tools/javac/lambda/TestSelfRef.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/lambda/TestSelfRef.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -114,22 +114,23 @@
 
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (EnclosingKind ek : EnclosingKind.values()) {
-            for (SiteKind sk : SiteKind.values()) {
-                if (sk == SiteKind.STATIC_INIT && ek == EnclosingKind.MEMBER_INNER)
-                    continue;
-                for (InnerKind ik : InnerKind.values()) {
-                    if (ik != InnerKind.NONE && sk == SiteKind.NONE)
-                        break;
-                    for (RefKind rk : RefKind.values()) {
-                        new TestSelfRef(ek, sk, ik, rk).run(comp, fm);
+            for (EnclosingKind ek : EnclosingKind.values()) {
+                for (SiteKind sk : SiteKind.values()) {
+                    if (sk == SiteKind.STATIC_INIT && ek == EnclosingKind.MEMBER_INNER)
+                        continue;
+                    for (InnerKind ik : InnerKind.values()) {
+                        if (ik != InnerKind.NONE && sk == SiteKind.NONE)
+                            break;
+                        for (RefKind rk : RefKind.values()) {
+                            new TestSelfRef(ek, sk, ik, rk).run(comp, fm);
+                        }
                     }
                 }
             }
+            System.out.println("Total check executed: " + checkCount);
         }
-        System.out.println("Total check executed: " + checkCount);
     }
 
     EnclosingKind ek;
--- a/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -185,14 +185,15 @@
     public static void main(String... args) throws Exception {
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (CastInfo cInfo : allCastInfo()) {
-            for (ExpressionKind ek : ExpressionKind.values()) {
-                new IntersectionTargetTypeTest(cInfo, ek).run(comp, fm);
+            for (CastInfo cInfo : allCastInfo()) {
+                for (ExpressionKind ek : ExpressionKind.values()) {
+                    new IntersectionTargetTypeTest(cInfo, ek).run(comp, fm);
+                }
             }
+            System.out.println("Total check executed: " + checkCount);
         }
-        System.out.println("Total check executed: " + checkCount);
     }
 
     static List<CastInfo> allCastInfo() {
--- a/test/tools/javac/lambda/methodReference/SamConversionComboTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/lambda/methodReference/SamConversionComboTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -250,13 +250,17 @@
     }
 
     public static void main(String[] args) throws Exception {
-        for(Context ct : Context.values()) {
-            for (FInterface fi : FInterface.values()) {
-                for (MethodDef md: MethodDef.values()) {
-                    new SamConversionComboTest(fi, ct, md).test();
+        try {
+            for(Context ct : Context.values()) {
+                for (FInterface fi : FInterface.values()) {
+                    for (MethodDef md: MethodDef.values()) {
+                        new SamConversionComboTest(fi, ct, md).test();
+                    }
                 }
             }
+            System.out.println("total tests: " + count);
+        } finally {
+            fm.close();
         }
-        System.out.println("total tests: " + count);
     }
 }
--- a/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -28,6 +28,7 @@
 import com.sun.source.util.JavacTask;
 import com.sun.tools.javac.util.Pair;
 
+import java.io.IOException;
 import java.net.URI;
 import java.util.Arrays;
 import java.util.ArrayList;
@@ -41,6 +42,7 @@
 import javax.tools.StandardJavaFileManager;
 import javax.tools.ToolProvider;
 
+import org.testng.annotations.AfterSuite;
 import org.testng.annotations.Test;
 import org.testng.annotations.BeforeSuite;
 import org.testng.annotations.DataProvider;
@@ -70,12 +72,19 @@
         fm = comp.getStandardFileManager(null, null, null);
     }
 
+    @AfterSuite
+    static void teardown() throws IOException {
+        fm.close();
+    }
+
     public static void main(String[] args) throws Exception {
         init();
 
         for (Pair<TestKind,Hierarchy> fdtest : generateCases()) {
             runTest(fdtest.fst, fdtest.snd, comp, fm);
         }
+
+        teardown();
     }
 
     @Test(dataProvider = "fdCases")
--- a/test/tools/javac/nativeHeaders/NativeHeaderTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/nativeHeaders/NativeHeaderTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -193,27 +193,30 @@
     void run() throws Exception {
         javac = JavacTool.create();
         fm = javac.getStandardFileManager(null, null, null);
-
-        for (RunKind rk: RunKind.values()) {
-            for (GenKind gk: GenKind.values()) {
-                for (Method m: getClass().getDeclaredMethods()) {
-                    Annotation a = m.getAnnotation(Test.class);
-                    if (a != null) {
-                        init(rk, gk, m.getName());
-                        try {
-                            m.invoke(this, new Object[] { rk, gk });
-                        } catch (InvocationTargetException e) {
-                            Throwable cause = e.getCause();
-                            throw (cause instanceof Exception) ? ((Exception) cause) : e;
+        try {
+            for (RunKind rk: RunKind.values()) {
+                for (GenKind gk: GenKind.values()) {
+                    for (Method m: getClass().getDeclaredMethods()) {
+                        Annotation a = m.getAnnotation(Test.class);
+                        if (a != null) {
+                            init(rk, gk, m.getName());
+                            try {
+                                m.invoke(this, new Object[] { rk, gk });
+                            } catch (InvocationTargetException e) {
+                                Throwable cause = e.getCause();
+                                throw (cause instanceof Exception) ? ((Exception) cause) : e;
+                            }
+                            System.err.println();
                         }
-                        System.err.println();
                     }
                 }
             }
+            System.err.println(testCount + " tests" + ((errorCount == 0) ? "" : ", " + errorCount + " errors"));
+            if (errorCount > 0)
+                throw new Exception(errorCount + " errors found");
+        } finally {
+            fm.close();
         }
-        System.err.println(testCount + " tests" + ((errorCount == 0) ? "" : ", " + errorCount + " errors"));
-        if (errorCount > 0)
-            throw new Exception(errorCount + " errors found");
     }
 
     /**
--- a/test/tools/javac/options/xprefer/XPreferTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/options/xprefer/XPreferTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -45,6 +45,7 @@
 
 import javax.tools.JavaCompiler;
 import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.StandardJavaFileManager;
 import javax.tools.ToolProvider;
 
 
@@ -73,27 +74,31 @@
     }
 
     final static JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
+    final static StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
     final static File OUTPUT_DIR = new File("out");
 
     public static void main(String... args) throws Exception {
+        try {
+            // Initialize test-directories
+            OUTPUT_DIR.mkdir();
+            for (Dir dir : Dir.values())
+                dir.file.mkdir();
 
-        // Initialize test-directories
-        OUTPUT_DIR.mkdir();
-        for (Dir dir : Dir.values())
-            dir.file.mkdir();
+            int testCaseCounter = 0;
 
-        int testCaseCounter = 0;
+            for (List<Dir> dirSubset : SubseqIter.subseqsOf(Dir.values())) {
 
-        for (List<Dir> dirSubset : SubseqIter.subseqsOf(Dir.values())) {
+                if (dirSubset.isEmpty())
+                    continue;
 
-            if (dirSubset.isEmpty())
-                continue;
-
-            for (ImplicitOption policy : ImplicitOption.values()) {
-                for (List<Dir> dirOrder : PermutationIterator.permutationsOf(dirSubset)) {
-                    new TestCase(dirOrder, policy, testCaseCounter++).run();
+                for (ImplicitOption policy : ImplicitOption.values()) {
+                    for (List<Dir> dirOrder : PermutationIterator.permutationsOf(dirSubset)) {
+                        new TestCase(dirOrder, policy, testCaseCounter++).run();
+                    }
                 }
             }
+        } finally {
+            fm.close();
         }
     }
 
@@ -234,8 +239,8 @@
             if(dir == Dir.SOURCE_PATH)
                 return src;
             // ...otherwise compile into a ".class".
-            CompilationTask task = comp.getTask(null, null, null, null, null,
-                    comp.getStandardFileManager(null, null, null).getJavaFileObjects(src));
+            CompilationTask task = comp.getTask(null, fm, null, null, null,
+                    fm.getJavaFileObjects(src));
             File dest = new File(dir.file, classId + ".class");
             if(!task.call() || !dest.exists())
                 throw new RuntimeException("Compilation failure.");
--- a/test/tools/javac/plugin/showtype/Test.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/plugin/showtype/Test.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -71,21 +71,25 @@
     }
 
     void run() throws Exception {
-        // compile the plugin explicitly, to a non-standard directory
-        // so that we don't find it on the wrong path by accident
-        pluginClasses.mkdirs();
-        compile("-d", pluginClasses.getPath(), pluginSrc.getPath());
-        writeFile(new File(pluginClasses, "META-INF/services/com.sun.source.util.Plugin"),
-                "ShowTypePlugin\n");
-        jar("cf", pluginJar.getPath(), "-C", pluginClasses.getPath(), ".");
+        try {
+            // compile the plugin explicitly, to a non-standard directory
+            // so that we don't find it on the wrong path by accident
+            pluginClasses.mkdirs();
+            compile("-d", pluginClasses.getPath(), pluginSrc.getPath());
+            writeFile(new File(pluginClasses, "META-INF/services/com.sun.source.util.Plugin"),
+                    "ShowTypePlugin\n");
+            jar("cf", pluginJar.getPath(), "-C", pluginClasses.getPath(), ".");
 
-        testCommandLine("-Xplugin:showtype", ref1);
-        testCommandLine("-Xplugin:showtype PI", ref2);
-        testAPI("-Xplugin:showtype", ref1);
-        testAPI("-Xplugin:showtype PI", ref2);
+            testCommandLine("-Xplugin:showtype", ref1);
+            testCommandLine("-Xplugin:showtype PI", ref2);
+            testAPI("-Xplugin:showtype", ref1);
+            testAPI("-Xplugin:showtype PI", ref2);
 
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
+        } finally {
+            fm.close();
+        }
     }
 
     void testAPI(String opt, List<String> ref) throws Exception {
--- a/test/tools/javac/positions/TreeEndPosTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/positions/TreeEndPosTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -137,32 +137,33 @@
         File tempDir = new File(".");
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
         DiagnosticCollector dc = new DiagnosticCollector();
-        JavaFileManager javaFileManager = getJavaFileManager(compiler, dc);
-        List<String> options = new ArrayList<>();
-        options.add("-cp");
-        options.add(tempDir.getPath());
-        options.add("-d");
-        options.add(tempDir.getPath());
-        options.add("-XDshouldStopPolicy=GENERATE");
+        try (JavaFileManager javaFileManager = getJavaFileManager(compiler, dc)) {
+            List<String> options = new ArrayList<>();
+            options.add("-cp");
+            options.add(tempDir.getPath());
+            options.add("-d");
+            options.add(tempDir.getPath());
+            options.add("-XDshouldStopPolicy=GENERATE");
 
-        List<JavaFileObject> sources = new ArrayList<>();
-        sources.add(src);
-        JavaCompiler.CompilationTask task =
-                compiler.getTask(writer, javaFileManager,
-                dc, options, null,
-                sources);
-        task.call();
-        for (Diagnostic diagnostic : (List<Diagnostic>) dc.getDiagnostics()) {
-            long actualStart = diagnostic.getStartPosition();
-            long actualEnd = diagnostic.getEndPosition();
-            System.out.println("Source: " + src.source);
-            System.out.println("Diagnostic: " + diagnostic);
-            System.out.print("Start position: Expected: " + src.startPos);
-            System.out.println(", Actual: " + actualStart);
-            System.out.print("End position: Expected: " + src.endPos);
-            System.out.println(", Actual: " + actualEnd);
-            if (src.startPos != actualStart || src.endPos != actualEnd) {
-                throw new RuntimeException("error: trees don't match");
+            List<JavaFileObject> sources = new ArrayList<>();
+            sources.add(src);
+            JavaCompiler.CompilationTask task =
+                    compiler.getTask(writer, javaFileManager,
+                    dc, options, null,
+                    sources);
+            task.call();
+            for (Diagnostic diagnostic : (List<Diagnostic>) dc.getDiagnostics()) {
+                long actualStart = diagnostic.getStartPosition();
+                long actualEnd = diagnostic.getEndPosition();
+                System.out.println("Source: " + src.source);
+                System.out.println("Diagnostic: " + diagnostic);
+                System.out.print("Start position: Expected: " + src.startPos);
+                System.out.println(", Actual: " + actualStart);
+                System.out.print("End position: Expected: " + src.endPos);
+                System.out.println(", Actual: " + actualEnd);
+                if (src.startPos != actualStart || src.endPos != actualEnd) {
+                    throw new RuntimeException("error: trees don't match");
+                }
             }
         }
     }
--- a/test/tools/javac/processing/6348193/T6348193.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/6348193/T6348193.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2008, 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
@@ -85,35 +85,36 @@
 
         MyDiagListener dl = new MyDiagListener();
         PrintWriter out = new PrintWriter(System.err, true);
-        StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null);
-        File file = new File(System.getProperty("test.src"), myName+".java");
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
-        boolean ok = t.getTask(out, null, dl, args, null, files).call();
+        try (StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null)) {
+            File file = new File(System.getProperty("test.src"), myName+".java");
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
+            boolean ok = t.getTask(out, null, dl, args, null, files).call();
 
-        if (config == NoGoodBad.GOOD || proc == NoYes.YES) {
-            if (secMgr == NoYes.YES) {
-                if (dl.last == null)
-                    throw new AssertionError("Security manager installed, and processors present, "
-                                             + " but no diagnostic received");
+            if (config == NoGoodBad.GOOD || proc == NoYes.YES) {
+                if (secMgr == NoYes.YES) {
+                    if (dl.last == null)
+                        throw new AssertionError("Security manager installed, and processors present, "
+                                                 + " but no diagnostic received");
+                }
+                else {
+                    if (!processed.exists())
+                        throw new AssertionError("No security manager installed, and processors present, "
+                                                 + " but no processing occurred");
+                }
+            }
+            else if (config == NoGoodBad.BAD) {
+                // TODO: should verify that no compiler crash occurred
+                // needs revised JSR199 spec
             }
             else {
-                if (!processed.exists())
-                    throw new AssertionError("No security manager installed, and processors present, "
-                                             + " but no processing occurred");
+                if (processed.exists())
+                    throw new AssertionError("No processors present, but processing occurred!");
             }
+
+            if (verbose)
+                System.err.println("OK");
         }
-        else if (config == NoGoodBad.BAD) {
-            // TODO: should verify that no compiler crash occurred
-            // needs revised JSR199 spec
-        }
-        else {
-            if (processed.exists())
-                throw new AssertionError("No processors present, but processing occurred!");
-        }
-
-        if (verbose)
-            System.err.println("OK");
     }
 
     // set up or remove a service configuration file
--- a/test/tools/javac/processing/6348499/T6348499.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/6348499/T6348499.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2012, 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
@@ -44,32 +44,33 @@
 
 
 public class T6348499 {
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         String testSrc = System.getProperty("test.src", ".");
         String testClasses = System.getProperty("test.classes");
         String testClassPath = System.getProperty("test.class.path", testClasses);
         String A_java = new File(testSrc, "A.java").getPath();
         JavacTool tool = JavacTool.create();
         MyDiagListener dl = new MyDiagListener();
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
-        Iterable<String> opts = Arrays.asList("-proc:only",
-                                              "-processor", "A",
-                                              "-processorpath", testClassPath);
-        StringWriter out = new StringWriter();
-        JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
-        task.call();
-        String s = out.toString();
-        System.err.print(s);
-        // Expect the following 1 multi-line diagnostic, and no output to log
-        //     error: cannot access A_0
-        //     bad class file: A_0.class
-        //     illegal start of class file
-        //     Please remove or make sure it appears in the correct subdirectory of the classpath.
-        System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
-        if (dl.count != 1 || s.length() != 0)
-            throw new AssertionError("unexpected output from compiler");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
+            Iterable<String> opts = Arrays.asList("-proc:only",
+                                                  "-processor", "A",
+                                                  "-processorpath", testClassPath);
+            StringWriter out = new StringWriter();
+            JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
+            task.call();
+            String s = out.toString();
+            System.err.print(s);
+            // Expect the following 1 multi-line diagnostic, and no output to log
+            //     error: cannot access A_0
+            //     bad class file: A_0.class
+            //     illegal start of class file
+            //     Please remove or make sure it appears in the correct subdirectory of the classpath.
+            System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
+            if (dl.count != 1 || s.length() != 0)
+                throw new AssertionError("unexpected output from compiler");
+        }
     }
 
     static class MyDiagListener implements DiagnosticListener<JavaFileObject> {
--- a/test/tools/javac/processing/6378728/T6378728.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/6378728/T6378728.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
@@ -64,21 +64,22 @@
         }
     }
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
         // Get a compiler tool
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
         String srcdir = System.getProperty("test.src");
         File source = new File(srcdir, "T6378728.java");
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
 
-        CompilationTask task =
-            compiler.getTask(null,
-                             new ExceptionalFileManager(fm),
-                             null,
-                             Arrays.asList("-proc:only"),
-                             null,
-                             fm.getJavaFileObjectsFromFiles(Arrays.asList(source)));
-        if (!task.call())
-            throw new RuntimeException("Unexpected compilation failure");
+            CompilationTask task =
+                compiler.getTask(null,
+                                 new ExceptionalFileManager(fm),
+                                 null,
+                                 Arrays.asList("-proc:only"),
+                                 null,
+                                 fm.getJavaFileObjectsFromFiles(Arrays.asList(source)));
+            if (!task.call())
+                throw new RuntimeException("Unexpected compilation failure");
+        }
     }
 }
--- a/test/tools/javac/processing/6414633/T6414633.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/6414633/T6414633.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2012, 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
@@ -40,29 +40,30 @@
 import com.sun.tools.javac.api.*;
 
 public class T6414633 {
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         String testSrc = System.getProperty("test.src", ".");
         String testClasses = System.getProperty("test.classes", ".");
         String testClassPath = System.getProperty("test.class.path", testClasses);
 
         JavacTool tool = JavacTool.create();
         MyDiagListener dl = new MyDiagListener();
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        try {
-            fm.setLocation(StandardLocation.CLASS_PATH, pathToFiles(testClassPath));
-        } catch (IOException e) {
-            throw new AssertionError(e);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            try {
+                fm.setLocation(StandardLocation.CLASS_PATH, pathToFiles(testClassPath));
+            } catch (IOException e) {
+                throw new AssertionError(e);
+            }
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, A.class.getName()+".java")));
+            String[] opts = { "-proc:only",
+                              "-processor", A.class.getName() };
+            JavacTask task = tool.getTask(null, fm, dl, Arrays.asList(opts), null, files);
+            task.call();
+
+            // two annotations on the same element -- expect 2 diags from the processor
+            if (dl.diags != 2)
+                throw new AssertionError(dl.diags + " diagnostics reported");
         }
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, A.class.getName()+".java")));
-        String[] opts = { "-proc:only",
-                          "-processor", A.class.getName() };
-        JavacTask task = tool.getTask(null, fm, dl, Arrays.asList(opts), null, files);
-        task.call();
-
-        // two annotations on the same element -- expect 2 diags from the processor
-        if (dl.diags != 2)
-            throw new AssertionError(dl.diags + " diagnostics reported");
     }
 
     private static List<File> pathToFiles(String path) {
--- a/test/tools/javac/processing/6430209/T6430209.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/6430209/T6430209.java	Wed Oct 29 17:25:23 2014 -0700
@@ -58,22 +58,23 @@
         String testClassPath = System.getProperty("test.class.path");
         JavacTool tool = JavacTool.create();
         MyDiagListener dl = new MyDiagListener();
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File(".")));
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(
-            new File(testSrc, "test0.java"), new File(testSrc, "test1.java")));
-        Iterable<String> opts = Arrays.asList("-proc:only",
-                                              "-processor", "b6341534",
-                                              "-processorpath", testClassPath);
-        StringWriter out = new StringWriter();
-        JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
-        task.call();
-        String s = out.toString();
-        System.err.print(s);
-        // Expect the following 2 diagnostics, and no output to log
-        System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
-        if (dl.count != 2 || s.length() != 0)
-            throw new AssertionError("unexpected output from compiler");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File(".")));
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(
+                new File(testSrc, "test0.java"), new File(testSrc, "test1.java")));
+            Iterable<String> opts = Arrays.asList("-proc:only",
+                                                  "-processor", "b6341534",
+                                                  "-processorpath", testClassPath);
+            StringWriter out = new StringWriter();
+            JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
+            task.call();
+            String s = out.toString();
+            System.err.print(s);
+            // Expect the following 2 diagnostics, and no output to log
+            System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
+            if (dl.count != 2 || s.length() != 0)
+                throw new AssertionError("unexpected output from compiler");
+        }
     }
 
     static class MyDiagListener implements DiagnosticListener<JavaFileObject> {
--- a/test/tools/javac/processing/T6439826.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/T6439826.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2010, 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
@@ -40,28 +40,29 @@
 
 @SupportedAnnotationTypes("*")
 public class T6439826 extends AbstractProcessor {
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         String testSrc = System.getProperty("test.src", ".");
         String testClasses = System.getProperty("test.classes");
         JavacTool tool = JavacTool.create();
         MyDiagListener dl = new MyDiagListener();
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        Iterable<? extends JavaFileObject> files =
-            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6439826.class.getName()+".java")));
-        Iterable<String> opts = Arrays.asList("-proc:only",
-                                              "-processor", "T6439826",
-                                              "-processorpath", testClasses);
-        StringWriter out = new StringWriter();
-        JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
-        task.call();
-        String s = out.toString();
-        System.err.print(s);
-        // Expect the following 2 diagnostics, and no output to log
-        //   Foo.java:1: illegal character: \35
-        //   Foo.java:1: reached end of file while parsing
-        System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
-        if (dl.count != 2 || s.length() != 0)
-            throw new AssertionError("unexpected output from compiler");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6439826.class.getName()+".java")));
+            Iterable<String> opts = Arrays.asList("-proc:only",
+                                                  "-processor", "T6439826",
+                                                  "-processorpath", testClasses);
+            StringWriter out = new StringWriter();
+            JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
+            task.call();
+            String s = out.toString();
+            System.err.print(s);
+            // Expect the following 2 diagnostics, and no output to log
+            //   Foo.java:1: illegal character: \35
+            //   Foo.java:1: reached end of file while parsing
+            System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
+            if (dl.count != 2 || s.length() != 0)
+                throw new AssertionError("unexpected output from compiler");
+        }
     }
 
     public boolean process(Set<? extends TypeElement> annotations,
--- a/test/tools/javac/processing/errors/TestSuppression.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/errors/TestSuppression.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -100,41 +100,42 @@
 
         DiagListener dl = new DiagListener();
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
-        fm.setLocation(StandardLocation.CLASS_PATH,
-                Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
-        fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
-        fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
-        List<String> args = new ArrayList<String>();
-//        args.add("-XprintProcessorInfo");
-        args.add("-XprintRounds");
-        args.add("-Agen=" + gen);
-        if (wk == WarningKind.YES)
-            args.add("-Xlint:serial");
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
+            fm.setLocation(StandardLocation.CLASS_PATH,
+                    Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
+            fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
+            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
+            List<String> args = new ArrayList<String>();
+    //        args.add("-XprintProcessorInfo");
+            args.add("-XprintRounds");
+            args.add("-Agen=" + gen);
+            if (wk == WarningKind.YES)
+                args.add("-Xlint:serial");
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
 
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
-        JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
-        task.setProcessors(Arrays.asList(new AnnoProc()));
-        boolean ok = task.call();
-        pw.close();
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+            JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
+            task.setProcessors(Arrays.asList(new AnnoProc()));
+            boolean ok = task.call();
+            pw.close();
 
-        System.err.println("ok:" + ok + " diags:" + dl.counts);
-        if (sw.toString().length() > 0) {
-            System.err.println("output:\n" + sw.toString());
+            System.err.println("ok:" + ok + " diags:" + dl.counts);
+            if (sw.toString().length() > 0) {
+                System.err.println("output:\n" + sw.toString());
+            }
+
+            for (Diagnostic.Kind dk: Diagnostic.Kind.values()) {
+                Integer v = dl.counts.get(dk);
+                int found = (v == null) ? 0 : v;
+                int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
+                if (found != expect) {
+                    error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
+                }
+            }
+
+            System.err.println();
         }
-
-        for (Diagnostic.Kind dk: Diagnostic.Kind.values()) {
-            Integer v = dl.counts.get(dk);
-            int found = (v == null) ? 0 : v;
-            int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
-            if (found != expect) {
-                error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
-            }
-        }
-
-        System.err.println();
     }
 
     File createDir(File parent, String name) {
--- a/test/tools/javac/processing/loader/testClose/TestClose.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/loader/testClose/TestClose.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -117,50 +117,51 @@
 
     void run() throws IOException {
         JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
 
-        File classes = new File("classes");
-        classes.mkdirs();
-        File extraClasses = new File("extraClasses");
-        extraClasses.mkdirs();
+            File classes = new File("classes");
+            classes.mkdirs();
+            File extraClasses = new File("extraClasses");
+            extraClasses.mkdirs();
 
-        System.out.println("compiling classes to extraClasses");
-        {   // setup class in extraClasses
-            fm.setLocation(StandardLocation.CLASS_OUTPUT,
-                    Collections.singleton(extraClasses));
-            List<? extends JavaFileObject> files = Arrays.asList(
-                    new MemFile("AnnoProc.java", annoProc),
-                    new MemFile("Callback.java", callback));
-            JavacTask task = tool.getTask(null, fm, null, null, null, files);
-            check(task.call());
-        }
+            System.out.println("compiling classes to extraClasses");
+            {   // setup class in extraClasses
+                fm.setLocation(StandardLocation.CLASS_OUTPUT,
+                        Collections.singleton(extraClasses));
+                List<? extends JavaFileObject> files = Arrays.asList(
+                        new MemFile("AnnoProc.java", annoProc),
+                        new MemFile("Callback.java", callback));
+                JavacTask task = tool.getTask(null, fm, null, null, null, files);
+                check(task.call());
+            }
 
-        System.out.println("compiling dummy to classes with anno processor");
-        {   // use that class in a TaskListener after processing has completed
-            PrintStream prev = System.out;
-            String out;
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            try (PrintStream ps = new PrintStream(baos)) {
-                System.setOut(ps);
-                File testClasses = new File(System.getProperty("test.classes"));
-                fm.setLocation(StandardLocation.CLASS_OUTPUT,
-                        Collections.singleton(classes));
-                fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
-                        Arrays.asList(extraClasses, testClasses));
-                List<? extends JavaFileObject> files = Arrays.asList(
-                        new MemFile("my://dummy", "class Dummy { }"));
-                List<String> options = Arrays.asList("-processor", "AnnoProc");
-                JavacTask task = tool.getTask(null, fm, null, options, null, files);
-                task.setTaskListener(this);
-                check(task.call());
-            } finally {
-                System.setOut(prev);
-                out = baos.toString();
-                if (!out.isEmpty())
-                    System.out.println(out);
+            System.out.println("compiling dummy to classes with anno processor");
+            {   // use that class in a TaskListener after processing has completed
+                PrintStream prev = System.out;
+                String out;
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                try (PrintStream ps = new PrintStream(baos)) {
+                    System.setOut(ps);
+                    File testClasses = new File(System.getProperty("test.classes"));
+                    fm.setLocation(StandardLocation.CLASS_OUTPUT,
+                            Collections.singleton(classes));
+                    fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
+                            Arrays.asList(extraClasses, testClasses));
+                    List<? extends JavaFileObject> files = Arrays.asList(
+                            new MemFile("my://dummy", "class Dummy { }"));
+                    List<String> options = Arrays.asList("-processor", "AnnoProc");
+                    JavacTask task = tool.getTask(null, fm, null, options, null, files);
+                    task.setTaskListener(this);
+                    check(task.call());
+                } finally {
+                    System.setOut(prev);
+                    out = baos.toString();
+                    if (!out.isEmpty())
+                        System.out.println(out);
+                }
+                check(out.contains("AnnoProc$1: run()"));
+                check(out.contains("Callback: run()"));
             }
-            check(out.contains("AnnoProc$1: run()"));
-            check(out.contains("Callback: run()"));
         }
     }
 
--- a/test/tools/javac/processing/model/testgetallmembers/Main.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/model/testgetallmembers/Main.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2013, 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
@@ -64,66 +64,67 @@
             return;
         }
         JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        fm.setLocation(CLASS_PATH, Collections.<File>emptyList());
-        JavacTask javac = (JavacTask)tool.getTask(null, fm, null, null, null, null);
-        Elements elements = javac.getElements();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            fm.setLocation(CLASS_PATH, Collections.<File>emptyList());
+            JavacTask javac = (JavacTask)tool.getTask(null, fm, null, null, null, null);
+            Elements elements = javac.getElements();
 
-        final Set<String> packages = new LinkedHashSet<String>();
+            final Set<String> packages = new LinkedHashSet<String>();
 
-        int nestedClasses = 0;
-        int classes = 0;
+            int nestedClasses = 0;
+            int classes = 0;
 
-        for (JavaFileObject file : fm.list(PLATFORM_CLASS_PATH, "", EnumSet.of(CLASS), true)) {
-            String type = fm.inferBinaryName(PLATFORM_CLASS_PATH, file);
-            if (type.endsWith("package-info"))
-                continue;
-            try {
-                TypeElement elem = elements.getTypeElement(type);
-                if (elem == null && type.indexOf('$') > 0) {
-                    nestedClasses++;
+            for (JavaFileObject file : fm.list(PLATFORM_CLASS_PATH, "", EnumSet.of(CLASS), true)) {
+                String type = fm.inferBinaryName(PLATFORM_CLASS_PATH, file);
+                if (type.endsWith("package-info"))
+                    continue;
+                try {
+                    TypeElement elem = elements.getTypeElement(type);
+                    if (elem == null && type.indexOf('$') > 0) {
+                        nestedClasses++;
+                        type = null;
+                        continue;
+                    }
+                    classes++;
+                    packages.add(getPackage(elem).getQualifiedName().toString());
+                    elements.getTypeElement(type).getKind(); // force completion
                     type = null;
-                    continue;
+                } finally {
+                    if (type != null)
+                        System.err.println("Looking at " + type);
                 }
-                classes++;
-                packages.add(getPackage(elem).getQualifiedName().toString());
-                elements.getTypeElement(type).getKind(); // force completion
-                type = null;
-            } finally {
-                if (type != null)
-                    System.err.println("Looking at " + type);
             }
+            javac = null;
+            elements = null;
+
+            javac = (JavacTask)tool.getTask(null, fm, null, null, null, null);
+            elements = javac.getElements();
+
+            for (String name : packages) {
+                PackageElement pe = elements.getPackageElement(name);
+                for (Element e : pe.getEnclosedElements()) {
+                    e.getSimpleName().getClass();
+                }
+            }
+            /*
+             * A few sanity checks based on current values:
+             *
+             * packages: 775, classes: 12429 + 5917
+             *
+             * As the platform evolves the numbers are likely to grow
+             * monotonically but in case somebody gets a clever idea for
+             * limiting the number of packages exposed, this number might
+             * drop.  So we test low values.
+             */
+            System.out.format("packages: %s, classes: %s + %s%n",
+                              packages.size(), classes, nestedClasses);
+            if (classes < 9000)
+                throw new AssertionError("Too few classes in PLATFORM_CLASS_PATH ;-)");
+            if (packages.size() < 530)
+                throw new AssertionError("Too few packages in PLATFORM_CLASS_PATH ;-)");
+            if (nestedClasses < 3000)
+                throw new AssertionError("Too few nested classes in PLATFORM_CLASS_PATH ;-)");
         }
-        javac = null;
-        elements = null;
-
-        javac = (JavacTask)tool.getTask(null, fm, null, null, null, null);
-        elements = javac.getElements();
-
-        for (String name : packages) {
-            PackageElement pe = elements.getPackageElement(name);
-            for (Element e : pe.getEnclosedElements()) {
-                e.getSimpleName().getClass();
-            }
-        }
-        /*
-         * A few sanity checks based on current values:
-         *
-         * packages: 775, classes: 12429 + 5917
-         *
-         * As the platform evolves the numbers are likely to grow
-         * monotonically but in case somebody gets a clever idea for
-         * limiting the number of packages exposed, this number might
-         * drop.  So we test low values.
-         */
-        System.out.format("packages: %s, classes: %s + %s%n",
-                          packages.size(), classes, nestedClasses);
-        if (classes < 9000)
-            throw new AssertionError("Too few classes in PLATFORM_CLASS_PATH ;-)");
-        if (packages.size() < 530)
-            throw new AssertionError("Too few packages in PLATFORM_CLASS_PATH ;-)");
-        if (nestedClasses < 3000)
-            throw new AssertionError("Too few nested classes in PLATFORM_CLASS_PATH ;-)");
     }
     /*
      * If -XX:+AggressiveOpts has been used to test, the option currently
--- a/test/tools/javac/processing/model/type/BoundsTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/model/type/BoundsTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -25,6 +25,7 @@
  * @test
  * @bug 6499673
  * @library /tools/javac/lib
+ * @ignore 8062245 Test executes incorrect class
  * @build JavacTestingAbstractProcessor BoundsTest
  * @run main BoundsTest
  * @summary Assertion check for TypeVariable.getUpperBound() fails
@@ -113,15 +114,19 @@
     }
 
     public void run() throws IOException {
-        runOne(Intersection_name, Intersection_contents,
-               Intersection_bounds, Intersection_supers);
-        runOne(Single_name, Single_contents,
-               Single_bounds, Single_supers);
-        runOne(NoBounds_name, NoBounds_contents,
-               NoBounds_bounds, NoBounds_supers);
+        try {
+            runOne(Intersection_name, Intersection_contents,
+                   Intersection_bounds, Intersection_supers);
+            runOne(Single_name, Single_contents,
+                   Single_bounds, Single_supers);
+            runOne(NoBounds_name, NoBounds_contents,
+                   NoBounds_bounds, NoBounds_supers);
 
-        if (0 != errors)
-            throw new RuntimeException(errors + " errors occurred");
+            if (0 != errors)
+                throw new RuntimeException(errors + " errors occurred");
+        } finally {
+            fm.close();
+        }
     }
 
     public static void main(String... args) throws IOException {
--- a/test/tools/javac/processing/model/type/IntersectionPropertiesTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/model/type/IntersectionPropertiesTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -76,10 +76,14 @@
     }
 
     public void run() throws IOException {
-        runOne(Intersection_name, Intersection_contents);
+        try {
+            runOne(Intersection_name, Intersection_contents);
 
-        if (0 != errors)
-            throw new RuntimeException(errors + " errors occurred");
+            if (0 != errors)
+                throw new RuntimeException(errors + " errors occurred");
+        } finally {
+            fm.close();
+        }
     }
 
     public static void main(String... args) throws IOException {
--- a/test/tools/javac/processing/model/util/elements/doccomments/TestDocComments.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/model/util/elements/doccomments/TestDocComments.java	Wed Oct 29 17:25:23 2014 -0700
@@ -104,11 +104,12 @@
             }
         };
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> units = fm.getJavaFileObjects(files);
-        JavacTask t = (JavacTask) c.getTask(null, fm, dl, Arrays.asList(opts), null, units);
-        t.parse();
-        t.analyze();
+        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> units = fm.getJavaFileObjects(files);
+            JavacTask t = (JavacTask) c.getTask(null, fm, dl, Arrays.asList(opts), null, units);
+            t.parse();
+            t.analyze();
+        }
     }
 
     static void test_javac_cmd(String[] opts, File[] files) {
--- a/test/tools/javac/processing/model/util/elements/doccomments/TestPackageInfoComments.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/model/util/elements/doccomments/TestPackageInfoComments.java	Wed Oct 29 17:25:23 2014 -0700
@@ -60,11 +60,12 @@
             }
         };
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> units = fm.getJavaFileObjects(files);
-        JavacTask t = (JavacTask) c.getTask(null, fm, dl, Arrays.asList(opts), null, units);
-        t.parse();
-        t.analyze();
+        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> units = fm.getJavaFileObjects(files);
+            JavacTask t = (JavacTask) c.getTask(null, fm, dl, Arrays.asList(opts), null, units);
+            t.parse();
+            t.analyze();
+        }
     }
 
     // -- Annotation processor: Check all PackageDecl's have a doc comment
--- a/test/tools/javac/processing/options/testCommandLineClasses/Test.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/options/testCommandLineClasses/Test.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -67,16 +67,17 @@
     void test(List<String> names) throws Exception {
         System.err.println("test: " + names);
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
-        File testClasses = new File(System.getProperty("test.classes"));
-        fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses));
-        JavaCompiler.CompilationTask task = compiler.getTask(
-                null, null, null, Arrays.asList("-proc:only"), names, null);
-        task.setProcessors(Arrays.asList(new Test()));
-        boolean ok = task.call();
-        if (!ok)
-            error("compilation failed");
-        System.err.println();
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            File testClasses = new File(System.getProperty("test.classes"));
+            fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses));
+            JavaCompiler.CompilationTask task = compiler.getTask(
+                    null, null, null, Arrays.asList("-proc:only"), names, null);
+            task.setProcessors(Arrays.asList(new Test()));
+            boolean ok = task.call();
+            if (!ok)
+                error("compilation failed");
+            System.err.println();
+        }
     }
 
     <T> List<T> reverse(List<T> list) {
--- a/test/tools/javac/processing/rounds/BaseClassesNotReRead.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/processing/rounds/BaseClassesNotReRead.java	Wed Oct 29 17:25:23 2014 -0700
@@ -49,19 +49,20 @@
     void run() throws IOException {
         File sources = new File(System.getProperty("test.src"));
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files =
-                fm.getJavaFileObjects(new File(sources, "BaseClassesNotReReadSource.java"));
-        DiagnosticListener<JavaFileObject> noErrors = new DiagnosticListener<JavaFileObject>() {
-            @Override
-            public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
-                throw new IllegalStateException(diagnostic.toString());
-            }
-        };
-        JavaFileManager manager = new OnlyOneReadFileManager(fm);
-        Iterable<String> options = Arrays.asList("-processor", "BaseClassesNotReRead");
-        JavacTask task = (JavacTask) compiler.getTask(null, manager, noErrors, options, null, files);
-        task.analyze();
+        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files =
+                    fm.getJavaFileObjects(new File(sources, "BaseClassesNotReReadSource.java"));
+            DiagnosticListener<JavaFileObject> noErrors = new DiagnosticListener<JavaFileObject>() {
+                @Override
+                public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
+                    throw new IllegalStateException(diagnostic.toString());
+                }
+            };
+            JavaFileManager manager = new OnlyOneReadFileManager(fm);
+            Iterable<String> options = Arrays.asList("-processor", "BaseClassesNotReRead");
+            JavacTask task = (JavacTask) compiler.getTask(null, manager, noErrors, options, null, files);
+            task.analyze();
+        }
     }
 
     int round = 1;
--- a/test/tools/javac/profiles/ProfileOptionTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/profiles/ProfileOptionTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -236,24 +236,28 @@
 
     /** Run all test cases. */
     void run() throws Exception {
-        initTestClasses();
+        try {
+            initTestClasses();
 
-        for (Method m: getClass().getDeclaredMethods()) {
-            Annotation a = m.getAnnotation(Test.class);
-            if (a != null) {
-                System.err.println(m.getName());
-                try {
-                    m.invoke(this, new Object[] { });
-                } catch (InvocationTargetException e) {
-                    Throwable cause = e.getCause();
-                    throw (cause instanceof Exception) ? ((Exception) cause) : e;
+            for (Method m: getClass().getDeclaredMethods()) {
+                Annotation a = m.getAnnotation(Test.class);
+                if (a != null) {
+                    System.err.println(m.getName());
+                    try {
+                        m.invoke(this, new Object[] { });
+                    } catch (InvocationTargetException e) {
+                        Throwable cause = e.getCause();
+                        throw (cause instanceof Exception) ? ((Exception) cause) : e;
+                    }
+                    System.err.println();
                 }
-                System.err.println();
             }
+
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
+        } finally {
+            fm.close();
         }
-
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
     }
 
     void error(String msg) {
--- a/test/tools/javac/resolve/ResolveHarness.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/resolve/ResolveHarness.java	Wed Oct 29 17:25:23 2014 -0700
@@ -71,13 +71,17 @@
     static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
 
     public static void main(String[] args) throws Exception {
-        fm.setLocation(SOURCE_PATH,
-                Arrays.asList(new File(System.getProperty("test.src"), "tests")));
-        for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
-            new ResolveHarness(jfo).check();
-        }
-        if (nerrors > 0) {
-            throw new AssertionError("Errors were found");
+        try {
+            fm.setLocation(SOURCE_PATH,
+                    Arrays.asList(new File(System.getProperty("test.src"), "tests")));
+            for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
+                new ResolveHarness(jfo).check();
+            }
+            if (nerrors > 0) {
+                throw new AssertionError("Errors were found");
+            }
+        } finally {
+            fm.close();
         }
     }
 
--- a/test/tools/javac/tree/ClassTreeTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/ClassTreeTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -41,25 +41,26 @@
 
     void run() throws Exception {
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        List<String> opts = Collections.<String>emptyList();
-        File testSrc = new File(System.getProperty("test.src"));
-        File thisFile = new File(testSrc, ClassTreeTest.class.getSimpleName() + ".java");
-        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile);
-        JavacTask task = tool.getTask(null, fm, null, opts, null, fos);
-        for (CompilationUnitTree cu: task.parse()) {
-            check(cu, "CLASS", Tree.Kind.CLASS);
-            check(cu, "INTERFACE", Tree.Kind.INTERFACE);
-            check(cu, "ENUM", Tree.Kind.ENUM);
-            check(cu, "ANNOTATION_TYPE", Tree.Kind.ANNOTATION_TYPE);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            List<String> opts = Collections.<String>emptyList();
+            File testSrc = new File(System.getProperty("test.src"));
+            File thisFile = new File(testSrc, ClassTreeTest.class.getSimpleName() + ".java");
+            Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile);
+            JavacTask task = tool.getTask(null, fm, null, opts, null, fos);
+            for (CompilationUnitTree cu: task.parse()) {
+                check(cu, "CLASS", Tree.Kind.CLASS);
+                check(cu, "INTERFACE", Tree.Kind.INTERFACE);
+                check(cu, "ENUM", Tree.Kind.ENUM);
+                check(cu, "ANNOTATION_TYPE", Tree.Kind.ANNOTATION_TYPE);
+            }
+
+            int expected = 4;
+            if (checks != expected)
+                error("Unexpected number of checks performed; expected: " + expected + ", found: " + checks);
+
+            if (errors > 0)
+                throw new Exception(errors + " errors found");
         }
-
-        int expected = 4;
-        if (checks != expected)
-            error("Unexpected number of checks performed; expected: " + expected + ", found: " + checks);
-
-        if (errors > 0)
-            throw new Exception(errors + " errors found");
     }
 
     void check(CompilationUnitTree cu, String name, Tree.Kind k) {
--- a/test/tools/javac/tree/DocCommentToplevelTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/DocCommentToplevelTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -90,24 +90,25 @@
     public static void main(String... args) throws Exception {
         //create default shared JavaCompiler - reused across multiple compilations
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
 
-        for (PackageKind pk : PackageKind.values()) {
-            for (ImportKind ik : ImportKind.values()) {
-                for (ModifierKind mk1 : ModifierKind.values()) {
-                    for (ModifierKind mk2 : ModifierKind.values()) {
-                        for (ToplevelDocKind tdk : ToplevelDocKind.values()) {
-                            new DocCommentToplevelTest(pk, ik, mk1, mk2, tdk).run(comp, fm);
+            for (PackageKind pk : PackageKind.values()) {
+                for (ImportKind ik : ImportKind.values()) {
+                    for (ModifierKind mk1 : ModifierKind.values()) {
+                        for (ModifierKind mk2 : ModifierKind.values()) {
+                            for (ToplevelDocKind tdk : ToplevelDocKind.values()) {
+                                new DocCommentToplevelTest(pk, ik, mk1, mk2, tdk).run(comp, fm);
+                            }
                         }
                     }
                 }
             }
+
+            if (errors > 0)
+                throw new AssertionError(errors + " errors found");
+
+            System.out.println(checks + " checks were made");
         }
-
-        if (errors > 0)
-            throw new AssertionError(errors + " errors found");
-
-        System.out.println(checks + " checks were made");
     }
 
     PackageKind pk;
--- a/test/tools/javac/tree/MissingSemicolonTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/MissingSemicolonTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -47,7 +47,7 @@
 import com.sun.tools.javac.util.Context;
 
 public class MissingSemicolonTest {
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         String testSrc = System.getProperty("test.src");
         File baseDir = new File(testSrc);
         boolean ok = new MissingSemicolonTest().run(baseDir, args);
@@ -56,24 +56,28 @@
         }
     }
 
-    boolean run(File baseDir, String... args) {
-        if (args.length == 0) {
-            throw new IllegalStateException("Needs input files.");
+    boolean run(File baseDir, String... args) throws IOException {
+        try {
+            if (args.length == 0) {
+                throw new IllegalStateException("Needs input files.");
+            }
+
+            for (String arg : args) {
+                File file = new File(baseDir, arg);
+                if (file.exists())
+                    test(file);
+                else
+                    error("File not found: " + file);
+            }
+
+            System.err.println(fileCount + " files read");
+            if (errors > 0)
+                System.err.println(errors + " errors");
+
+            return errors == 0;
+        } finally {
+            fm.close();
         }
-
-        for (String arg : args) {
-            File file = new File(baseDir, arg);
-            if (file.exists())
-                test(file);
-            else
-                error("File not found: " + file);
-        }
-
-        System.err.println(fileCount + " files read");
-        if (errors > 0)
-            System.err.println(errors + " errors");
-
-        return errors == 0;
     }
 
     void test(File file) {
--- a/test/tools/javac/tree/PrettySimpleStringTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/PrettySimpleStringTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -46,27 +46,28 @@
         File testSrc = new File(System.getProperty("test.src"));
         File thisFile = new File(testSrc, getClass().getName() + ".java");
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        JavacTask task = tool.getTask(null, fm, null, null, null,
-                fm.getJavaFileObjects(thisFile));
-        Iterable<? extends CompilationUnitTree> trees = task.parse();
-        CompilationUnitTree thisTree = trees.iterator().next();
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            JavacTask task = tool.getTask(null, fm, null, null, null,
+                    fm.getJavaFileObjects(thisFile));
+            Iterable<? extends CompilationUnitTree> trees = task.parse();
+            CompilationUnitTree thisTree = trees.iterator().next();
 
-        {   // test default
-            String thisSrc = Pretty.toSimpleString((JCTree) thisTree);
-            System.err.println(thisSrc);
-            String expect = "import jav[...]} } }";
-            if (!thisSrc.equals(expect)) {
-                throw new Exception("unexpected result");
+            {   // test default
+                String thisSrc = Pretty.toSimpleString((JCTree) thisTree);
+                System.err.println(thisSrc);
+                String expect = "import jav[...]} } }";
+                if (!thisSrc.equals(expect)) {
+                    throw new Exception("unexpected result");
+                }
             }
-        }
 
-        {   // test explicit length
-            String thisSrc = Pretty.toSimpleString((JCTree) thisTree, 32);
-            System.err.println(thisSrc);
-            String expect = "import java.io.Fil[...]; } } } }";
-            if (!thisSrc.equals(expect)) {
-                throw new Exception("unexpected result");
+            {   // test explicit length
+                String thisSrc = Pretty.toSimpleString((JCTree) thisTree, 32);
+                System.err.println(thisSrc);
+                String expect = "import java.io.Fil[...]} } } } }";
+                if (!thisSrc.equals(expect)) {
+                    throw new Exception("unexpected result");
+                }
             }
         }
     }
--- a/test/tools/javac/tree/T6963934.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/T6963934.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -42,17 +42,18 @@
         File testSrc = new File(System.getProperty("test.src"));
         File thisSrc = new File(testSrc, T6963934.class.getSimpleName() + ".java");
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
-        JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null,
-                fileManager.getJavaFileObjects(thisSrc));
-        CompilationUnitTree tree = task.parse().iterator().next();
-        int count = 0;
-        for (ImportTree importTree : tree.getImports()) {
-            System.out.println(importTree);
-            count++;
+        try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
+            JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null,
+                    fileManager.getJavaFileObjects(thisSrc));
+            CompilationUnitTree tree = task.parse().iterator().next();
+            int count = 0;
+            for (ImportTree importTree : tree.getImports()) {
+                System.out.println(importTree);
+                count++;
+            }
+            int expected = 7;
+            if (count != expected)
+                throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected);
         }
-        int expected = 7;
-        if (count != expected)
-            throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected);
     }
 }
--- a/test/tools/javac/tree/T6993305.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/T6993305.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -59,18 +59,19 @@
         File testSrc = new File(System.getProperty("test.src"));
 
         JavacTool tool = JavacTool.create();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
 
-        File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
-        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
-        JavacTask task = tool.getTask(null, fm, null, null, null, fos);
-        Iterable<? extends CompilationUnitTree> cus = task.parse();
+            File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
+            Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
+            JavacTask task = tool.getTask(null, fm, null, null, null, fos);
+            Iterable<? extends CompilationUnitTree> cus = task.parse();
 
-        TestScanner s = new TestScanner();
-        s.scan(cus, task);
+            TestScanner s = new TestScanner();
+            s.scan(cus, task);
 
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
+        }
     }
 
     void error(String msg) {
--- a/test/tools/javac/tree/TestToString.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/TestToString.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -63,12 +63,16 @@
     }
 
     void run() throws Exception {
-        for (String s: statements) {
-            test(s);
+        try {
+            for (String s: statements) {
+                test(s);
+            }
+
+            if (errors > 0)
+                throw new Exception(errors + " errors found");
+        } finally {
+            fm.close();
         }
-
-        if (errors > 0)
-            throw new Exception(errors + " errors found");
     }
 
     void test(String stmt) throws IOException {
--- a/test/tools/javac/tree/TreePosRoundsTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/TreePosRoundsTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -54,18 +54,19 @@
         String testSrc = System.getProperty("test.src");
         String testClasses = System.getProperty("test.classes");
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
-        String thisName = TreePosRoundsTest.class.getName();
-        File thisFile = new File(testSrc, thisName + ".java");
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
-        List<String> options = Arrays.asList(
-                "-proc:only",
-                "-processor", thisName,
-                "-processorpath", testClasses);
-        CompilationTask t = c.getTask(null, fm, null, options, null, files);
-        boolean ok = t.call();
-        if (!ok)
-            throw new Exception("processing failed");
+        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            String thisName = TreePosRoundsTest.class.getName();
+            File thisFile = new File(testSrc, thisName + ".java");
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
+            List<String> options = Arrays.asList(
+                    "-proc:only",
+                    "-processor", thisName,
+                    "-processorpath", testClasses);
+            CompilationTask t = c.getTask(null, fm, null, options, null, files);
+            boolean ok = t.call();
+            if (!ok)
+                throw new Exception("processing failed");
+        }
     }
 
     Filer filer;
@@ -155,6 +156,9 @@
                 //System.err.println("  encl: " +enclKind);
                 if (enclKind == Tree.Kind.CLASS || enclKind == Tree.Kind.BLOCK)
                     expect += ";";
+                // t-w-r- adds implicit final: remove it
+                if (enclKind == Tree.Kind.TRY && expect.startsWith("final "))
+                    expect = expect.substring(6);
             }
             //System.err.println("expect: " + expect);
 
--- a/test/tools/javac/tree/TreePosTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/tree/TreePosTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -113,7 +113,7 @@
      * args is the value of ${test.src}. In jtreg mode, the -r option can be
      * given to change the default base directory to the root test directory.
      */
-    public static void main(String... args) {
+    public static void main(String... args) throws IOException {
         String testSrc = System.getProperty("test.src");
         File baseDir = (testSrc == null) ? null : new File(testSrc);
         boolean ok = new TreePosTest().run(baseDir, args);
@@ -133,61 +133,65 @@
      * @param args command line args
      * @return true if successful or in gui mode
      */
-    boolean run(File baseDir, String... args) {
-        if (args.length == 0) {
-            usage(System.out);
-            return true;
+    boolean run(File baseDir, String... args) throws IOException {
+        try {
+            if (args.length == 0) {
+                usage(System.out);
+                return true;
+            }
+
+            List<File> files = new ArrayList<File>();
+            for (int i = 0; i < args.length; i++) {
+                String arg = args[i];
+                if (arg.equals("-encoding") && i + 1 < args.length)
+                    encoding = args[++i];
+                else if (arg.equals("-gui"))
+                    gui = true;
+                else if (arg.equals("-q"))
+                    quiet = true;
+                else if (arg.equals("-v"))
+                    verbose = true;
+                else if (arg.equals("-t") && i + 1 < args.length)
+                    tags.add(args[++i]);
+                else if (arg.equals("-ef") && i + 1 < args.length)
+                    excludeFiles.add(new File(baseDir, args[++i]));
+                else if (arg.equals("-et") && i + 1 < args.length)
+                    excludeTags.add(args[++i]);
+                else if (arg.equals("-r")) {
+                    if (excludeFiles.size() > 0)
+                        throw new Error("-r must be used before -ef");
+                    File d = baseDir;
+                    while (!new File(d, "TEST.ROOT").exists()) {
+                        d = d.getParentFile();
+                        if (d == null)
+                            throw new Error("cannot find TEST.ROOT");
+                    }
+                    baseDir = d;
+                }
+                else if (arg.startsWith("-"))
+                    throw new Error("unknown option: " + arg);
+                else {
+                    while (i < args.length)
+                        files.add(new File(baseDir, args[i++]));
+                }
+            }
+
+            for (File file: files) {
+                if (file.exists())
+                    test(file);
+                else
+                    error("File not found: " + file);
+            }
+
+            if (fileCount != 1)
+                System.err.println(fileCount + " files read");
+            if (errors > 0)
+                System.err.println(errors + " errors");
+
+            return (gui || errors == 0);
+        } finally {
+            fm.close();
         }
-
-        List<File> files = new ArrayList<File>();
-        for (int i = 0; i < args.length; i++) {
-            String arg = args[i];
-            if (arg.equals("-encoding") && i + 1 < args.length)
-                encoding = args[++i];
-            else if (arg.equals("-gui"))
-                gui = true;
-            else if (arg.equals("-q"))
-                quiet = true;
-            else if (arg.equals("-v"))
-                verbose = true;
-            else if (arg.equals("-t") && i + 1 < args.length)
-                tags.add(args[++i]);
-            else if (arg.equals("-ef") && i + 1 < args.length)
-                excludeFiles.add(new File(baseDir, args[++i]));
-            else if (arg.equals("-et") && i + 1 < args.length)
-                excludeTags.add(args[++i]);
-            else if (arg.equals("-r")) {
-                if (excludeFiles.size() > 0)
-                    throw new Error("-r must be used before -ef");
-                File d = baseDir;
-                while (!new File(d, "TEST.ROOT").exists()) {
-                    d = d.getParentFile();
-                    if (d == null)
-                        throw new Error("cannot find TEST.ROOT");
-                }
-                baseDir = d;
-            }
-            else if (arg.startsWith("-"))
-                throw new Error("unknown option: " + arg);
-            else {
-                while (i < args.length)
-                    files.add(new File(baseDir, args[i++]));
-            }
-        }
-
-        for (File file: files) {
-            if (file.exists())
-                test(file);
-            else
-                error("File not found: " + file);
-        }
-
-        if (fileCount != 1)
-            System.err.println(fileCount + " files read");
-        if (errors > 0)
-            System.err.println(errors + " errors");
-
-        return (gui || errors == 0);
     }
 
     /**
--- a/test/tools/javac/unit/T6198196.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/unit/T6198196.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -28,6 +28,7 @@
  * @author  Peter von der Ah\u00e9
  */
 
+import java.io.IOException;
 import java.util.Arrays;
 import javax.tools.*;
 
@@ -42,21 +43,25 @@
                                      + filename + ") != " + result);
         System.out.format("OK: endsWith(%s, %s) = %s%n", pathname, filename, result);
     }
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
         fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
-        boolean windows = System.getProperty("os.name").startsWith("Windows");
-        test("/x/y/z/package-info.java", pkginf, true);
-        if (windows) {
-            test("\\x\\y\\z\\package-info.java", pkginf, true);
-            test("..\\x\\y\\z\\package-info.java", pkginf, true);
-        } else {
-            test("\\x\\y\\z\\package-info.java", pkginf, false);
-            test("..\\x\\y\\z\\package-info.java", pkginf, false);
+        try {
+            boolean windows = System.getProperty("os.name").startsWith("Windows");
+            test("/x/y/z/package-info.java", pkginf, true);
+            if (windows) {
+                test("\\x\\y\\z\\package-info.java", pkginf, true);
+                test("..\\x\\y\\z\\package-info.java", pkginf, true);
+            } else {
+                test("\\x\\y\\z\\package-info.java", pkginf, false);
+                test("..\\x\\y\\z\\package-info.java", pkginf, false);
+            }
+            test("Package-info.java", pkginf, false);
+            test("../x/y/z/package-info.java", pkginf, true);
+            test("/x/y/z/package-info.java", pkginf, true);
+            test("x/y/z/package-info.java", pkginf, true);
+            test("package-info.java", pkginf, true);
+        } finally {
+            fm.close();
         }
-        test("Package-info.java", pkginf, false);
-        test("../x/y/z/package-info.java", pkginf, true);
-        test("/x/y/z/package-info.java", pkginf, true);
-        test("x/y/z/package-info.java", pkginf, true);
-        test("package-info.java", pkginf, true);
     }
 }
--- a/test/tools/javac/varargs/6199075/T6199075.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/varargs/6199075/T6199075.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -143,20 +143,24 @@
     }
 
     void test() throws Exception {
-        for (TypeKind formal1 : TypeKind.values()) {
-            VarargsMethod m1 = new VarargsMethod(formal1);
-            for (TypeKind formal2 : TypeKind.values()) {
-                VarargsMethod m2 = new VarargsMethod(formal2);
-                for (TypeKind actual : TypeKind.values()) {
-                    for (ArgumentsArity argsArity : ArgumentsArity.values()) {
-                        compileAndCheck(m1, m2, actual, argsArity);
+        try {
+            for (TypeKind formal1 : TypeKind.values()) {
+                VarargsMethod m1 = new VarargsMethod(formal1);
+                for (TypeKind formal2 : TypeKind.values()) {
+                    VarargsMethod m2 = new VarargsMethod(formal2);
+                    for (TypeKind actual : TypeKind.values()) {
+                        for (ArgumentsArity argsArity : ArgumentsArity.values()) {
+                            compileAndCheck(m1, m2, actual, argsArity);
+                        }
                     }
                 }
             }
+
+            System.out.println("Total checks made: " + checkCount);
+            System.out.println("Bytecode checks made: " + bytecodeCheckCount);
+        } finally {
+            fm.close();
         }
-
-        System.out.println("Total checks made: " + checkCount);
-        System.out.println("Bytecode checks made: " + bytecodeCheckCount);
     }
 
     // Create a single file manager and reuse it for each compile to save time.
--- a/test/tools/javac/varargs/7043922/T7043922.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/varargs/7043922/T7043922.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -146,22 +146,26 @@
     static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
 
     public static void main(String... args) throws Exception {
-        for (ClassKind classKind1 : ClassKind.values()) {
-            for (ConstructorKind constrKind1 : ConstructorKind.values()) {
-                if (!classKind1.isConstructorOk(constrKind1)) continue;
-                for (ClassKind classKind2 : ClassKind.values()) {
-                    for (ConstructorKind constrKind2 : ConstructorKind.values()) {
-                        if (!classKind2.isConstructorOk(constrKind2)) continue;
-                        for (ClassKind classKind3 : ClassKind.values()) {
-                            for (ConstructorKind constrKind3 : ConstructorKind.values()) {
-                                if (!classKind3.isConstructorOk(constrKind3)) continue;
-                                new T7043922(new ClassKind[] { classKind1, classKind2, classKind3 },
-                                        new ConstructorKind[] { constrKind1, constrKind2, constrKind3 }).compileAndCheck();
+        try {
+            for (ClassKind classKind1 : ClassKind.values()) {
+                for (ConstructorKind constrKind1 : ConstructorKind.values()) {
+                    if (!classKind1.isConstructorOk(constrKind1)) continue;
+                    for (ClassKind classKind2 : ClassKind.values()) {
+                        for (ConstructorKind constrKind2 : ConstructorKind.values()) {
+                            if (!classKind2.isConstructorOk(constrKind2)) continue;
+                            for (ClassKind classKind3 : ClassKind.values()) {
+                                for (ConstructorKind constrKind3 : ConstructorKind.values()) {
+                                    if (!classKind3.isConstructorOk(constrKind3)) continue;
+                                    new T7043922(new ClassKind[] { classKind1, classKind2, classKind3 },
+                                            new ConstructorKind[] { constrKind1, constrKind2, constrKind3 }).compileAndCheck();
+                                }
                             }
                         }
                     }
                 }
             }
+        } finally {
+            fm.close();
         }
     }
 
--- a/test/tools/javac/versions/Versions.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javac/versions/Versions.java	Wed Oct 29 17:25:23 2014 -0700
@@ -278,22 +278,25 @@
 
     protected boolean compile(String sourceFile, List<String>options) {
         JavaCompiler.CompilationTask jctask;
-        StandardJavaFileManager fm = javacompiler.getStandardFileManager(null, null, null);
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(sourceFile);
+        try (StandardJavaFileManager fm = javacompiler.getStandardFileManager(null, null, null)) {
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(sourceFile);
 
-        jctask = javacompiler.getTask(
-            null,    // Writer
-            fm,      // JavaFileManager
-            null,    // DiagnosticListener
-            options, // Iterable<String>
-            null,    // Iterable<String> classes
-            files);  // Iterable<? extends JavaFileObject>
+            jctask = javacompiler.getTask(
+                null,    // Writer
+                fm,      // JavaFileManager
+                null,    // DiagnosticListener
+                options, // Iterable<String>
+                null,    // Iterable<String> classes
+                files);  // Iterable<? extends JavaFileObject>
 
-        try {
-            return jctask.call();
-        } catch (IllegalStateException e) {
-            System.err.println(e);
-            return false;
+            try {
+                return jctask.call();
+            } catch (IllegalStateException e) {
+                System.err.println(e);
+                return false;
+            }
+        } catch (IOException e) {
+            throw new Error(e);
         }
     }
 
--- a/test/tools/javadoc/CheckResourceKeys.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/CheckResourceKeys.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -140,41 +140,42 @@
     Set<String> getCodeKeys() throws IOException {
         Set<String> results = new TreeSet<String>();
         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
-        JavaFileManager fm = c.getStandardFileManager(null, null, null);
-        JavaFileManager.Location javadocLoc = findJavadocLocation(fm);
-        String[] pkgs = {
-            "com.sun.tools.doclets",
-            "com.sun.tools.javadoc"
-        };
-        for (String pkg: pkgs) {
-            for (JavaFileObject fo: fm.list(javadocLoc,
-                    pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
-                String name = fo.getName();
-                // ignore resource files
-                if (name.matches(".*resources.[A-Za-z_0-9]+\\.class.*"))
-                    continue;
-                scan(fo, results);
+        try (JavaFileManager fm = c.getStandardFileManager(null, null, null)) {
+            JavaFileManager.Location javadocLoc = findJavadocLocation(fm);
+            String[] pkgs = {
+                "com.sun.tools.doclets",
+                "com.sun.tools.javadoc"
+            };
+            for (String pkg: pkgs) {
+                for (JavaFileObject fo: fm.list(javadocLoc,
+                        pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
+                    String name = fo.getName();
+                    // ignore resource files
+                    if (name.matches(".*resources.[A-Za-z_0-9]+\\.class.*"))
+                        continue;
+                    scan(fo, results);
+                }
             }
+
+            // special handling for code strings synthesized in
+            // com.sun.tools.doclets.internal.toolkit.util.Util.getTypeName
+            String[] extras = {
+                "AnnotationType", "Class", "Enum", "Error", "Exception", "Interface"
+            };
+            for (String s: extras) {
+                if (results.contains("doclet." + s))
+                    results.add("doclet." + s.toLowerCase());
+            }
+
+            // special handling for code strings synthesized in
+            // com.sun.tools.javadoc.Messager
+            results.add("javadoc.error.msg");
+            results.add("javadoc.note.msg");
+            results.add("javadoc.note.pos.msg");
+            results.add("javadoc.warning.msg");
+
+            return results;
         }
-
-        // special handling for code strings synthesized in
-        // com.sun.tools.doclets.internal.toolkit.util.Util.getTypeName
-        String[] extras = {
-            "AnnotationType", "Class", "Enum", "Error", "Exception", "Interface"
-        };
-        for (String s: extras) {
-            if (results.contains("doclet." + s))
-                results.add("doclet." + s.toLowerCase());
-        }
-
-        // special handling for code strings synthesized in
-        // com.sun.tools.javadoc.Messager
-        results.add("javadoc.error.msg");
-        results.add("javadoc.note.msg");
-        results.add("javadoc.note.pos.msg");
-        results.add("javadoc.warning.msg");
-
-        return results;
     }
 
     // depending on how the test is run, javadoc may be on bootclasspath or classpath
--- a/test/tools/javadoc/api/basic/DocletPathTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/DocletPathTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -59,34 +59,36 @@
                 createSimpleJavaFileObject("DocletOnDocletPath", docletSrcText);
         File docletDir = getOutDir("classes");
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null);
-        cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(docletDir));
-        Iterable<? extends JavaFileObject> cfiles = Arrays.asList(docletSrc);
-        if (!compiler.getTask(null, cfm, null, null, null, cfiles).call())
-            throw new Exception("cannot compile doclet");
+        try (StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null)) {
+            cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(docletDir));
+            Iterable<? extends JavaFileObject> cfiles = Arrays.asList(docletSrc);
+            if (!compiler.getTask(null, cfm, null, null, null, cfiles).call())
+                throw new Exception("cannot compile doclet");
+        }
 
         JavaFileObject srcFile = createSimpleJavaFileObject();
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir("api");
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        fm.setLocation(DocumentationTool.Location.DOCLET_PATH, Arrays.asList(docletDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        Iterable<String> options = Arrays.asList("-doclet", "DocletOnDocletPath");
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
-        DocumentationTask t = tool.getTask(pw, fm, null, null, options, files);
-        boolean ok = t.call();
-        String out = sw.toString();
-        System.err.println(">>" + out + "<<");
-        if (ok) {
-            if (out.contains(TEST_STRING)) {
-                System.err.println("doclet executed as expected");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir("api");
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            fm.setLocation(DocumentationTool.Location.DOCLET_PATH, Arrays.asList(docletDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            Iterable<String> options = Arrays.asList("-doclet", "DocletOnDocletPath");
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+            DocumentationTask t = tool.getTask(pw, fm, null, null, options, files);
+            boolean ok = t.call();
+            String out = sw.toString();
+            System.err.println(">>" + out + "<<");
+            if (ok) {
+                if (out.contains(TEST_STRING)) {
+                    System.err.println("doclet executed as expected");
+                } else {
+                    error("test string not found in doclet output");
+                }
             } else {
-                error("test string not found in doclet output");
+                error("task failed");
             }
-        } else {
-            error("task failed");
         }
     }
 
--- a/test/tools/javadoc/api/basic/GetTask_DiagListenerTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/GetTask_DiagListenerTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -60,27 +60,28 @@
     public void testDiagListener() throws Exception {
         JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", "package pkg; public error { }");
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
-        DocumentationTask t = tool.getTask(null, fm, dc, null, null, files);
-        if (t.call()) {
-            throw new Exception("task succeeded unexpectedly");
-        } else {
-            List<String> diagCodes = new ArrayList<String>();
-            for (Diagnostic d: dc.getDiagnostics()) {
-                System.err.println(d);
-                diagCodes.add(d.getCode());
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
+            DocumentationTask t = tool.getTask(null, fm, dc, null, null, files);
+            if (t.call()) {
+                throw new Exception("task succeeded unexpectedly");
+            } else {
+                List<String> diagCodes = new ArrayList<String>();
+                for (Diagnostic d: dc.getDiagnostics()) {
+                    System.err.println(d);
+                    diagCodes.add(d.getCode());
+                }
+                List<String> expect = Arrays.asList(
+                        "javadoc.note.msg",         // Loading source file
+                        "compiler.err.expected3",   // class, interface, or enum expected
+                        "javadoc.note.msg");        // 1 error
+                if (!diagCodes.equals(expect))
+                    throw new Exception("unexpected diagnostics occurred");
+                System.err.println("diagnostics received as expected");
             }
-            List<String> expect = Arrays.asList(
-                    "javadoc.note.msg",         // Loading source file
-                    "compiler.err.expected3",   // class, interface, or enum expected
-                    "javadoc.note.msg");        // 1 error
-            if (!diagCodes.equals(expect))
-                throw new Exception("unexpected diagnostics occurred");
-            System.err.println("diagnostics received as expected");
         }
     }
 
--- a/test/tools/javadoc/api/basic/GetTask_DocletClassTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/GetTask_DocletClassTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -70,20 +70,21 @@
                 "pkg/C",
                 "package pkg; /** " + key + "*/ public class C { }");
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        DocumentationTask t = tool.getTask(null, fm, null, TestDoclet.class, null, files);
-        if (t.call()) {
-            System.err.println("task succeeded");
-            if (TestDoclet.lastCaller.equals(String.valueOf(key)))
-                System.err.println("found expected key: " + key);
-            else
-                error("Expected key not found");
-            checkFiles(outDir, Collections.<String>emptySet());
-        } else {
-            throw new Exception("task failed");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            DocumentationTask t = tool.getTask(null, fm, null, TestDoclet.class, null, files);
+            if (t.call()) {
+                System.err.println("task succeeded");
+                if (TestDoclet.lastCaller.equals(String.valueOf(key)))
+                    System.err.println("found expected key: " + key);
+                else
+                    error("Expected key not found");
+                checkFiles(outDir, Collections.<String>emptySet());
+            } else {
+                throw new Exception("task failed");
+            }
         }
     }
 
@@ -115,20 +116,21 @@
     public void testBadDoclet() throws Exception {
         JavaFileObject srcFile = createSimpleJavaFileObject();
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        DocumentationTask t = tool.getTask(null, fm, null, BadDoclet.class, null, files);
-        try {
-            t.call();
-            error("call completed without exception");
-        } catch (RuntimeException e) {
-            Throwable c = e.getCause();
-            if (c.getClass() == UnexpectedError.class)
-                System.err.println("exception caught as expected: " + c);
-            else
-                throw e;
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            DocumentationTask t = tool.getTask(null, fm, null, BadDoclet.class, null, files);
+            try {
+                t.call();
+                error("call completed without exception");
+            } catch (RuntimeException e) {
+                Throwable c = e.getCause();
+                if (c.getClass() == UnexpectedError.class)
+                    System.err.println("exception caught as expected: " + c);
+                else
+                    throw e;
+            }
         }
     }
 
--- a/test/tools/javadoc/api/basic/GetTask_FileObjectsTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/GetTask_FileObjectsTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -54,16 +54,17 @@
         File testSrc = new File(System.getProperty("test.src"));
         File srcFile = new File(testSrc, "pkg/C.java");
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
-        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
-        if (t.call()) {
-            System.err.println("task succeeded");
-            checkFiles(outDir, standardExpectFiles);
-        } else {
-            throw new Exception("task failed");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
+            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
+            if (t.call()) {
+                System.err.println("task succeeded");
+                checkFiles(outDir, standardExpectFiles);
+            } else {
+                throw new Exception("task failed");
+            }
         }
     }
 
@@ -75,16 +76,17 @@
     public void testMemoryFileObject() throws Exception {
         JavaFileObject srcFile = createSimpleJavaFileObject();
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
-        if (t.call()) {
-            System.err.println("task succeeded");
-            checkFiles(outDir, standardExpectFiles);
-        } else {
-            throw new Exception("task failed");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
+            if (t.call()) {
+                System.err.println("task succeeded");
+                checkFiles(outDir, standardExpectFiles);
+            } else {
+                throw new Exception("task failed");
+            }
         }
     }
 
@@ -96,15 +98,16 @@
         File testSrc = new File(System.getProperty("test.src"));
         File srcFile = new File(testSrc, "pkg/C.class");  // unacceptable file kind
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
-        try {
-            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
-            error("getTask succeeded, no exception thrown");
-        } catch (IllegalArgumentException e) {
-            System.err.println("exception caught as expected: " + e);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
+            try {
+                DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
+                error("getTask succeeded, no exception thrown");
+            } catch (IllegalArgumentException e) {
+                System.err.println("exception caught as expected: " + e);
+            }
         }
     }
 
@@ -114,15 +117,16 @@
     @Test
     public void testNull() throws Exception {
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);
-        try {
-            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
-            error("getTask succeeded, no exception thrown");
-        } catch (NullPointerException e) {
-            System.err.println("exception caught as expected: " + e);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);
+            try {
+                DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
+                error("getTask succeeded, no exception thrown");
+            } catch (NullPointerException e) {
+                System.err.println("exception caught as expected: " + e);
+            }
         }
     }
 
--- a/test/tools/javadoc/api/basic/GetTask_OptionsTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/GetTask_OptionsTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -54,19 +54,20 @@
     public void testNoIndex() throws Exception {
         JavaFileObject srcFile = createSimpleJavaFileObject();
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        Iterable<String> options = Arrays.asList("-noindex");
-        DocumentationTask t = tool.getTask(null, fm, null, null, options, files);
-        if (t.call()) {
-            System.err.println("task succeeded");
-            Set<String> expectFiles = new TreeSet<String>(standardExpectFiles);
-            expectFiles.remove("index-all.html");
-            checkFiles(outDir, expectFiles);
-        } else {
-            error("task failed");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            Iterable<String> options = Arrays.asList("-noindex");
+            DocumentationTask t = tool.getTask(null, fm, null, null, options, files);
+            if (t.call()) {
+                System.err.println("task succeeded");
+                Set<String> expectFiles = new TreeSet<String>(standardExpectFiles);
+                expectFiles.remove("index-all.html");
+                checkFiles(outDir, expectFiles);
+            } else {
+                error("task failed");
+            }
         }
     }
 
@@ -77,16 +78,17 @@
     public void testNull() throws Exception {
         JavaFileObject srcFile = createSimpleJavaFileObject();
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<String> options = Arrays.asList((String) null);
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        try {
-            DocumentationTask t = tool.getTask(null, fm, null, null, options, files);
-            error("getTask succeeded, no exception thrown");
-        } catch (NullPointerException e) {
-            System.err.println("exception caught as expected: " + e);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<String> options = Arrays.asList((String) null);
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            try {
+                DocumentationTask t = tool.getTask(null, fm, null, null, options, files);
+                error("getTask succeeded, no exception thrown");
+            } catch (NullPointerException e) {
+                System.err.println("exception caught as expected: " + e);
+            }
         }
     }
 
--- a/test/tools/javadoc/api/basic/GetTask_WriterTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/GetTask_WriterTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -54,25 +54,26 @@
     public void testWriter() throws Exception {
         JavaFileObject srcFile = createSimpleJavaFileObject();
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
-        DocumentationTask t = tool.getTask(pw, fm, null, null, null, files);
-        if (t.call()) {
-            System.err.println("task succeeded");
-            checkFiles(outDir, standardExpectFiles);
-            String out = sw.toString();
-            System.err.println(">>" + out + "<<");
-            for (String f: standardExpectFiles) {
-                String f1 = f.replace('/', File.separatorChar);
-                if (f1.endsWith(".html") && !out.contains(f1))
-                    throw new Exception("expected string not found: " + f1);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+            DocumentationTask t = tool.getTask(pw, fm, null, null, null, files);
+            if (t.call()) {
+                System.err.println("task succeeded");
+                checkFiles(outDir, standardExpectFiles);
+                String out = sw.toString();
+                System.err.println(">>" + out + "<<");
+                for (String f: standardExpectFiles) {
+                    String f1 = f.replace('/', File.separatorChar);
+                    if (f1.endsWith(".html") && !out.contains(f1))
+                        throw new Exception("expected string not found: " + f1);
+                }
+            } else {
+                throw new Exception("task failed");
             }
-        } else {
-            throw new Exception("task failed");
         }
     }
 }
--- a/test/tools/javadoc/api/basic/JavadocTaskImplTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/JavadocTaskImplTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -56,18 +56,19 @@
     public void testRawCall() throws Exception {
         JavaFileObject srcFile = createSimpleJavaFileObject();
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
 
-        @SuppressWarnings("rawtypes")
-        Callable t = tool.getTask(null, fm, null, null, null, files);
+            @SuppressWarnings("rawtypes")
+            Callable t = tool.getTask(null, fm, null, null, null, files);
 
-        if (t.call() == Boolean.TRUE) {
-            System.err.println("task succeeded");
-        } else {
-            throw new Exception("task failed");
+            if (t.call() == Boolean.TRUE) {
+                System.err.println("task succeeded");
+            } else {
+                throw new Exception("task failed");
+            }
         }
     }
 
@@ -77,14 +78,15 @@
         Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
         Context c = new Context();
         Messager.preRegister(c, "javadoc");
-        StandardJavaFileManager fm = new JavacFileManager(c, true, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
-        if (t.call()) {
-            System.err.println("task succeeded");
-        } else {
-            throw new Exception("task failed");
+        try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
+            if (t.call()) {
+                System.err.println("task succeeded");
+            } else {
+                throw new Exception("task failed");
+            }
         }
     }
 
@@ -94,14 +96,15 @@
         Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
         Context c = new Context();
         Messager.preRegister(c, "javadoc");
-        StandardJavaFileManager fm = new JavacFileManager(c, true, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        try {
-            DocumentationTask t = new JavadocTaskImpl(c, null, null, files);;
-            error("getTask succeeded, no exception thrown");
-        } catch (NullPointerException e) {
-            System.err.println("exception caught as expected: " + e);
+        try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            try {
+                DocumentationTask t = new JavadocTaskImpl(c, null, null, files);;
+                error("getTask succeeded, no exception thrown");
+            } catch (NullPointerException e) {
+                System.err.println("exception caught as expected: " + e);
+            }
         }
     }
 }
--- a/test/tools/javadoc/api/basic/TagletPathTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/TagletPathTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -62,38 +62,40 @@
         File tagletSrcFile = new File(testSrc, "taglets/UnderlineTaglet.java");
         File tagletDir = getOutDir("classes");
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null);
-        cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tagletDir));
-        Iterable<? extends JavaFileObject> cfiles = cfm.getJavaFileObjects(tagletSrcFile);
-        if (!compiler.getTask(null, cfm, null, null, null, cfiles).call())
-            throw new Exception("cannot compile taglet");
+        try (StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null)) {
+            cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tagletDir));
+            Iterable<? extends JavaFileObject> cfiles = cfm.getJavaFileObjects(tagletSrcFile);
+            if (!compiler.getTask(null, cfm, null, null, null, cfiles).call())
+                throw new Exception("cannot compile taglet");
+        }
 
         JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", testSrcText);
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir("api");
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        fm.setLocation(DocumentationTool.Location.TAGLET_PATH, Arrays.asList(tagletDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        Iterable<String> options = Arrays.asList("-taglet", "UnderlineTaglet");
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
-        DocumentationTask t = tool.getTask(pw, fm, null, null, options, files);
-        boolean ok = t.call();
-        String out = sw.toString();
-        System.err.println(">>" + out + "<<");
-        if (ok) {
-            File f = new File(outDir, "pkg/C.html");
-            List<String> doc = Files.readAllLines(f.toPath(), Charset.defaultCharset());
-            for (String line: doc) {
-                if (line.contains("<u>" + TEST_STRING + "</u>")) {
-                    System.err.println("taglet executed as expected");
-                    return;
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir("api");
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            fm.setLocation(DocumentationTool.Location.TAGLET_PATH, Arrays.asList(tagletDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            Iterable<String> options = Arrays.asList("-taglet", "UnderlineTaglet");
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+            DocumentationTask t = tool.getTask(pw, fm, null, null, options, files);
+            boolean ok = t.call();
+            String out = sw.toString();
+            System.err.println(">>" + out + "<<");
+            if (ok) {
+                File f = new File(outDir, "pkg/C.html");
+                List<String> doc = Files.readAllLines(f.toPath(), Charset.defaultCharset());
+                for (String line: doc) {
+                    if (line.contains("<u>" + TEST_STRING + "</u>")) {
+                        System.err.println("taglet executed as expected");
+                        return;
+                    }
                 }
+                error("expected text not found in output " + f);
+            } else {
+                error("task failed");
             }
-            error("expected text not found in output " + f);
-        } else {
-            error("task failed");
         }
     }
 
--- a/test/tools/javadoc/api/basic/Task_reuseTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/api/basic/Task_reuseTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -77,16 +77,17 @@
     private DocumentationTask getAndRunTask() throws Exception {
         JavaFileObject srcFile = createSimpleJavaFileObject();
         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
-        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
-        File outDir = getOutDir();
-        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
-        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
-        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
-        if (t.call()) {
-            System.err.println("task succeeded");
-            return t;
-        } else {
-            throw new Exception("task failed");
+        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
+            File outDir = getOutDir();
+            fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
+            Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
+            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
+            if (t.call()) {
+                System.err.println("task succeeded");
+                return t;
+            } else {
+                throw new Exception("task failed");
+            }
         }
     }
 }
--- a/test/tools/javadoc/doclint/DocLintTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javadoc/doclint/DocLintTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -121,60 +121,64 @@
     void run() throws Exception {
         javadoc = ToolProvider.getSystemDocumentationTool();
         fm = javadoc.getStandardFileManager(null, null, null);
-        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
-        file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
-            @Override
-            public CharSequence getCharContent(boolean ignoreEncoding) {
-                return code;
-            }
-        };
+        try {
+            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
+            file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
+                @Override
+                public CharSequence getCharContent(boolean ignoreEncoding) {
+                    return code;
+                }
+            };
 
-        test(Collections.<String>emptyList(),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR9A, Message.DL_WRN12A));
+            test(Collections.<String>emptyList(),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR9A, Message.DL_WRN12A));
 
-        test(Arrays.asList(rawDiags),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
+            test(Arrays.asList(rawDiags),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
 
-        test(Arrays.asList("-Xdoclint:none"),
-                Main.Result.OK,
-                EnumSet.of(Message.JD_WRN10, Message.JD_WRN13));
+            test(Arrays.asList("-Xdoclint:none"),
+                    Main.Result.OK,
+                    EnumSet.of(Message.JD_WRN10, Message.JD_WRN13));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
+            test(Arrays.asList(rawDiags, "-Xdoclint"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.OPT_BADQUAL));
+            test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.OPT_BADQUAL));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:all", "-public"),
-                Main.Result.OK,
-                EnumSet.of(Message.DL_WRN12));
+            test(Arrays.asList(rawDiags, "-Xdoclint:all", "-public"),
+                    Main.Result.OK,
+                    EnumSet.of(Message.DL_WRN12));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
-                Main.Result.OK,
-                EnumSet.of(Message.DL_WRN12));
+            test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
+                    Main.Result.OK,
+                    EnumSet.of(Message.DL_WRN12));
 
-        test(Arrays.asList(rawDiags, "-private"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
+            test(Arrays.asList(rawDiags, "-private"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:syntax", "-private"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
+            test(Arrays.asList(rawDiags, "-Xdoclint:syntax", "-private"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.DL_ERR9));
+            test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.DL_ERR9));
 
-        test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
-                Main.Result.ERROR,
-                EnumSet.of(Message.OPT_BADARG));
+            test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
+                    Main.Result.ERROR,
+                    EnumSet.of(Message.OPT_BADARG));
 
-        if (errors > 0)
-            throw new Exception(errors + " errors occurred");
+            if (errors > 0)
+                throw new Exception(errors + " errors occurred");
+        } finally {
+            fm.close();
+        }
     }
 
     void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
--- a/test/tools/javap/TestSuperclass.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/javap/TestSuperclass.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -77,19 +77,20 @@
 
     public static void main(String... args) throws Exception {
         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-        int errors = 0;
+        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
+            int errors = 0;
 
-        for (ClassKind ck: ClassKind.values()) {
-            for (GenericKind gk: GenericKind.values()) {
-                for (SuperKind sk: SuperKind.values()) {
-                    errors += new TestSuperclass(ck, gk, sk).run(comp, fm);
+            for (ClassKind ck: ClassKind.values()) {
+                for (GenericKind gk: GenericKind.values()) {
+                    for (SuperKind sk: SuperKind.values()) {
+                        errors += new TestSuperclass(ck, gk, sk).run(comp, fm);
+                    }
                 }
             }
+
+            if (errors > 0)
+                throw new Exception(errors + " errors found");
         }
-
-        if (errors > 0)
-            throw new Exception(errors + " errors found");
     }
 
     final ClassKind ck;
--- a/test/tools/sjavac/DependencyCollection.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/test/tools/sjavac/DependencyCollection.java	Wed Oct 29 17:25:23 2014 -0700
@@ -59,59 +59,60 @@
         Path src = Paths.get(ToolBox.testSrc, "test-input", "src");
 
         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
-        StandardJavaFileManager fileManager = javac.getStandardFileManager(null, null, null);
-        SmartFileManager smartFileManager = new SmartFileManager(fileManager);
-        smartFileManager.setSymbolFileEnabled(false);
-        Iterable<? extends JavaFileObject> fileObjects =
-                fileManager.getJavaFileObjectsFromFiles(Arrays.asList(src.resolve("pkg/Test.java").toFile()));
-        JavacTaskImpl task = (JavacTaskImpl) javac.getTask(new PrintWriter(System.out),
-                                                           smartFileManager,
-                                                           null,
-                                                           Arrays.asList("-d", "classes",
-                                                                         "-sourcepath", src.toAbsolutePath().toString()),
-                                                           null,
-                                                           fileObjects);
-        DependencyCollector depsCollector = new DependencyCollector();
-        task.addTaskListener(depsCollector);
-        task.doCall();
+        try (StandardJavaFileManager fileManager = javac.getStandardFileManager(null, null, null)) {
+            SmartFileManager smartFileManager = new SmartFileManager(fileManager);
+            smartFileManager.setSymbolFileEnabled(false);
+            Iterable<? extends JavaFileObject> fileObjects =
+                    fileManager.getJavaFileObjectsFromFiles(Arrays.asList(src.resolve("pkg/Test.java").toFile()));
+            JavacTaskImpl task = (JavacTaskImpl) javac.getTask(new PrintWriter(System.out),
+                                                               smartFileManager,
+                                                               null,
+                                                               Arrays.asList("-d", "classes",
+                                                                             "-sourcepath", src.toAbsolutePath().toString()),
+                                                               null,
+                                                               fileObjects);
+            DependencyCollector depsCollector = new DependencyCollector();
+            task.addTaskListener(depsCollector);
+            task.doCall();
 
-        // Find pkg symbol
-        PackageSymbol pkg = findPkgSymbolWithName(depsCollector.getSourcePackages(), "pkg");
-        Set<PackageSymbol> foundDependencies = depsCollector.getDependenciesForPkg(pkg);
+            // Find pkg symbol
+            PackageSymbol pkg = findPkgSymbolWithName(depsCollector.getSourcePackages(), "pkg");
+            Set<PackageSymbol> foundDependencies = depsCollector.getDependenciesForPkg(pkg);
 
-        // Print dependencies
-        System.out.println("Found dependencies:");
-        foundDependencies.stream()
-                         .sorted(Comparator.comparing(DependencyCollection::extractNumber))
-                         .forEach(p -> System.out.println("    " + p));
+            // Print dependencies
+            System.out.println("Found dependencies:");
+            foundDependencies.stream()
+                             .sorted(Comparator.comparing(DependencyCollection::extractNumber))
+                             .forEach(p -> System.out.println("    " + p));
 
-        // Check result
-        Set<Integer> found = foundDependencies.stream()
-                                              .map(DependencyCollection::extractNumber)
-                                              .collect(Collectors.toSet());
-        found.remove(-1); // Dependencies with no number (java.lang etc)
-        Set<Integer> expected = new HashSet<>();
-        for (int i = 2; i <= 30; i++) {
-            if (i == 15) continue;  // Case 15 correspond to the type of a throw-away return value.
-            expected.add(i);
+            // Check result
+            Set<Integer> found = foundDependencies.stream()
+                                                  .map(DependencyCollection::extractNumber)
+                                                  .collect(Collectors.toSet());
+            found.remove(-1); // Dependencies with no number (java.lang etc)
+            Set<Integer> expected = new HashSet<>();
+            for (int i = 2; i <= 30; i++) {
+                if (i == 15) continue;  // Case 15 correspond to the type of a throw-away return value.
+                expected.add(i);
+            }
+
+            Set<Integer> missing = new HashSet<>(expected);
+            missing.removeAll(found);
+            if (missing.size() > 0) {
+                System.out.println("Missing dependencies:");
+                missing.forEach(i -> System.out.println("    Dependency " + i));
+            }
+
+            Set<Integer> unexpected = new HashSet<>(found);
+            unexpected.removeAll(expected);
+            if (unexpected.size() > 0) {
+                System.out.println("Unexpected dependencies found:");
+                unexpected.forEach(i -> System.out.println("    Dependency " + i));
+            }
+
+            if (missing.size() > 0 || unexpected.size() > 0)
+                throw new AssertionError("Missing and/or unexpected dependencies found.");
         }
-
-        Set<Integer> missing = new HashSet<>(expected);
-        missing.removeAll(found);
-        if (missing.size() > 0) {
-            System.out.println("Missing dependencies:");
-            missing.forEach(i -> System.out.println("    Dependency " + i));
-        }
-
-        Set<Integer> unexpected = new HashSet<>(found);
-        unexpected.removeAll(expected);
-        if (unexpected.size() > 0) {
-            System.out.println("Unexpected dependencies found:");
-            unexpected.forEach(i -> System.out.println("    Dependency " + i));
-        }
-
-        if (missing.size() > 0 || unexpected.size() > 0)
-            throw new AssertionError("Missing and/or unexpected dependencies found.");
     }
 
     private static PackageSymbol findPkgSymbolWithName(Set<PackageSymbol> syms, String name) {