# HG changeset patch # User lana # Date 1414702551 25200 # Node ID 14c8294d03a4ef79787f2d56358439d1160b92b2 # Parent 952159eaf30bc2d9a4ecea87138ff04ae092dfa6# Parent c8eceba990bf8a4795a5351c460822ff480a900a Merge diff -r 952159eaf30b -r 14c8294d03a4 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java Thu Oct 30 13:55:51 2014 -0700 @@ -76,6 +76,7 @@ */ public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager { + @SuppressWarnings("cast") public static char[] toArray(CharBuffer buffer) { if (buffer.hasArray()) return ((CharBuffer)buffer.compact().flip()).array(); @@ -129,6 +130,8 @@ if (register) context.put(JavaFileManager.class, this); setContext(context); + if (System.getProperty("show.fm.open.close") != null) + System.err.println("JavacFileManager.open " + this.hashCode()); } /** @@ -570,6 +573,8 @@ */ @DefinedBy(Api.COMPILER) public void close() { + if (System.getProperty("show.fm.open.close") != null) + System.err.println("JavacFileManager.close " + this.hashCode()); for (Iterator i = archives.values().iterator(); i.hasNext(); ) { Archive a = i.next(); i.remove(); diff -r 952159eaf30b -r 14c8294d03a4 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java Thu Oct 30 13:55:51 2014 -0700 @@ -517,6 +517,13 @@ result = sr; } + @Override + public void visitTypeUnion(JCTypeUnion tree) { + SourceRange sr = new SourceRange(startPos(tree), endPos(tree)); + sr.mergeWith(csp(tree.alternatives)); + result = sr; + } + public void visitWildcard(JCWildcard tree) { result = null; } diff -r 952159eaf30b -r 14c8294d03a4 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/BaseFileManager.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/BaseFileManager.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/BaseFileManager.java Thu Oct 30 13:55:51 2014 -0700 @@ -235,6 +235,7 @@ return encName; } + @SuppressWarnings("cast") public CharBuffer decode(ByteBuffer inbuf, boolean ignoreEncodingErrors) { String encodingName = getEncodingName(); CharsetDecoder decoder; @@ -315,6 +316,7 @@ * @return a byte buffer containing the contents of the stream * @throws IOException if an error occurred while reading the stream */ + @SuppressWarnings("cast") public ByteBuffer makeByteBuffer(InputStream in) throws IOException { int limit = in.available(); @@ -343,6 +345,7 @@ /** * A single-element cache of direct byte buffers. */ + @SuppressWarnings("cast") private static class ByteBufferCache { private ByteBuffer cached; ByteBuffer get(int capacity) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java Thu Oct 30 13:55:51 2014 -0700 @@ -88,6 +88,9 @@ */ private boolean apiMode; + private JavaFileManager fileManager; + private boolean closeFileManagerOnExit; + Start(String programName, PrintWriter errWriter, PrintWriter warnWriter, @@ -239,6 +242,12 @@ messager.error(Messager.NOPOS, "main.fatal.exception"); failed = true; } finally { + if (fileManager != null && closeFileManagerOnExit) { + try { + fileManager.close(); + } catch (IOException ignore) { + } + } messager.exitNotice(); messager.flush(); } @@ -270,7 +279,8 @@ } - JavaFileManager fileManager = context.get(JavaFileManager.class); + fileManager = context.get(JavaFileManager.class); + setDocletInvoker(docletClass, fileManager, argv); compOpts = Options.instance(context); @@ -333,6 +343,7 @@ if (fileManager == null) { JavacFileManager.preRegister(context); fileManager = context.get(JavaFileManager.class); + closeFileManagerOnExit = true; } if (fileManager instanceof BaseFileManager) { ((BaseFileManager) fileManager).handleOptions(fileManagerOpts); diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/all/RunCodingRules.java --- a/langtools/test/tools/all/RunCodingRules.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/all/RunCodingRules.java Thu Oct 30 13:55:51 2014 -0700 @@ -77,41 +77,42 @@ } JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null); - DiagnosticListener noErrors = diagnostic -> { - Assert.check(diagnostic.getKind() != Diagnostic.Kind.ERROR, diagnostic.toString()); - }; + try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) { + DiagnosticListener noErrors = diagnostic -> { + Assert.check(diagnostic.getKind() != Diagnostic.Kind.ERROR, diagnostic.toString()); + }; - List 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 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 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 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 sources = sourceDirs.stream() - .flatMap(dir -> silentFilesWalk(dir)) - .filter(entry -> entry.getFileName().toString().endsWith(".java")) - .map(p -> p.toFile()) - .collect(Collectors.toList()); + List 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 options = Arrays.asList("-d", sourceTarget.toString(), - "-processorpath", processorPath, "-Xplugin:coding_rules"); - javaCompiler.getTask(null, fm, noErrors, options, null, - fm.getJavaFileObjectsFromFiles(sources)).call(); + Path sourceTarget = targetDir.resolve("classes"); + Files.createDirectories(sourceTarget); + String processorPath = crulesTarget.toString() + File.pathSeparator + crulesDir.toString(); + List options = Arrays.asList("-d", sourceTarget.toString(), + "-processorpath", processorPath, "-Xplugin:coding_rules"); + javaCompiler.getTask(null, fm, noErrors, options, null, + fm.getJavaFileObjectsFromFiles(sources)).call(); + } } Stream silentFilesWalk(Path dir) throws IllegalStateException { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/6341866/T6341866.java --- a/langtools/test/tools/javac/6341866/T6341866.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/6341866/T6341866.java Thu Oct 30 13:55:51 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 files = fm.getJavaFileObjects(file); - - //System.err.println("compile: " + opts + " " + files); + // Note: class A references class B, so compile A if we want implicit compilation + File file = (implicitType != ImplicitType.NONE) ? a_java : b_java; + Iterable files = fm.getJavaFileObjects(file); - boolean ok = javac.getTask(null, fm, dl, opts, null, files).call(); - if (!ok) { - error("compilation failed"); - return false; - } + //System.err.println("compile: " + opts + " " + files); - // 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; + // 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; } - - 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/6400872/T6400872.java --- a/langtools/test/tools/javac/6400872/T6400872.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/6400872/T6400872.java Thu Oct 30 13:55:51 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 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(); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/6402516/Checker.java --- a/langtools/test/tools/javac/6402516/Checker.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/6402516/Checker.java Thu Oct 30 13:55:51 2014 -0700 @@ -54,25 +54,26 @@ }; JavacTool tool = JavacTool.create(); - StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); - Iterable files = - fm.getJavaFileObjectsFromFiles(getFiles(testSrc, fileNames)); - task = tool.getTask(null, fm, dl, null, null, files); - Iterable units = task.parse(); + try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { + Iterable files = + fm.getJavaFileObjectsFromFiles(getFiles(testSrc, fileNames)); + task = tool.getTask(null, fm, dl, null, null, files); + Iterable 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/6440583/T6440583.java --- a/langtools/test/tools/javac/6440583/T6440583.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/6440583/T6440583.java Thu Oct 30 13:55:51 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 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 files = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java"))); + JavacTask task = tool.getTask(null, fm, null, null, null, files); - Iterable trees = task.parse(); + Iterable trees = task.parse(); - TreeScanner checker = new TreeScanner() { - public Boolean visitErroneous(ErroneousTree tree, Void ignore) { - JCErroneous etree = (JCErroneous) tree; - List 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 checker = new TreeScanner() { + public Boolean visitErroneous(ErroneousTree tree, Void ignore) { + JCErroneous etree = (JCErroneous) tree; + List 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; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/6902720/Test.java --- a/langtools/test/tools/javac/6902720/Test.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/6902720/Test.java Thu Oct 30 13:55:51 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 files = fm.getJavaFileObjects(test); + try (StandardJavaFileManager fm = tool1.getStandardFileManager(null, null, null)) { + Iterable 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 trees = t1.parse(); - for (CompilationUnitTree tree: trees) { - new Pretty(pw, true).printExpr((JCTree) tree); - } - pw.close(); + // 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 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"); + 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"); + // 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"); + File expectedClass = new File(test.getName().replace(".java", ".class")); + if (!expectedClass.exists()) + throw new Exception(expectedClass + " not found"); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/7003595/T7003595.java --- a/langtools/test/tools/javac/7003595/T7003595.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/7003595/T7003595.java Thu Oct 30 13:55:51 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; } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/7079713/TestCircularClassfile.java --- a/langtools/test/tools/javac/7079713/TestCircularClassfile.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/7079713/TestCircularClassfile.java Thu Oct 30 13:55:51 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); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/7142086/T7142086.java --- a/langtools/test/tools/javac/7142086/T7142086.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/7142086/T7142086.java Thu Oct 30 13:55:51 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 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/NoStringToLower.java --- a/langtools/test/tools/javac/NoStringToLower.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/NoStringToLower.java Thu Oct 30 13:55:51 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/Paths/6638501/JarFromManifestFailure.java --- a/langtools/test/tools/javac/Paths/6638501/JarFromManifestFailure.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/Paths/6638501/JarFromManifestFailure.java Thu Oct 30 13:55:51 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 classPath, File... files) { + static void compile(File classOutDir, Iterable classPath, File... files) throws IOException { System.err.println("compile..."); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); - Iterable fileObjects = - fm.getJavaFileObjectsFromFiles(Arrays.asList(files)); + try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { + Iterable fileObjects = + fm.getJavaFileObjectsFromFiles(Arrays.asList(files)); - List options = new ArrayList(); - if (classOutDir != null) { - options.add("-d"); - options.add(classOutDir.getPath()); + List options = new ArrayList(); + 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 classPath, File base, File... files) diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/Paths/TestCompileJARInClassPath.java --- a/langtools/test/tools/javac/Paths/TestCompileJARInClassPath.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/Paths/TestCompileJARInClassPath.java Thu Oct 30 13:55:51 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 diagnostics = new DiagnosticCollector<>(); - StandardJavaFileManager stdFileManager = javac.getStandardFileManager(diagnostics, null, null); + try (StandardJavaFileManager stdFileManager = javac.getStandardFileManager(diagnostics, null, null)) { - List files = new ArrayList<>(); - files.add(clientJarFile); + List files = new ArrayList<>(); + files.add(clientJarFile); - stdFileManager.setLocation(StandardLocation.CLASS_PATH, files); + stdFileManager.setLocation(StandardLocation.CLASS_PATH, files); + + Iterable sourceFiles = stdFileManager.getJavaFileObjects(sourceFileToCompile); - Iterable 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"); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6265400.java --- a/langtools/test/tools/javac/T6265400.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6265400.java Thu Oct 30 13:55:51 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 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 files = + fm.getJavaFileObjectsFromStrings(Arrays.asList("badfile.java")); + javac.getTask(null, fm, dl, null, null, files).call(); + } } catch (RuntimeException e) { Throwable cause = e.getCause(); diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6340549.java --- a/langtools/test/tools/javac/T6340549.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6340549.java Thu Oct 30 13:55:51 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6351767.java --- a/langtools/test/tools/javac/T6351767.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6351767.java Thu Oct 30 13:55:51 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"); - } - catch (NullPointerException e) { - // expected - } + // 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 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"); + // 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; + 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"); } - if (!found) - error("expected file, java/lang/Object.class, not found"); - } static void error(String msg) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6361619.java --- a/langtools/test/tools/javac/T6361619.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6361619.java Thu Oct 30 13:55:51 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 f = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, - self + ".java"))); + try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { + Iterable 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 elems, RoundEnvironment renv) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6395974.java --- a/langtools/test/tools/javac/T6395974.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6395974.java Thu Oct 30 13:55:51 2014 -0700 @@ -44,24 +44,25 @@ String testSrc = System.getProperty("test.src"); JavacTool tool = JavacTool.create(); - StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); - Iterable f = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self + ".java"))); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + Iterable 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6397044.java --- a/langtools/test/tools/javac/T6397044.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6397044.java Thu Oct 30 13:55:51 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 files - = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java"))); - JavacTask task = tool.getTask(null, fm, null, null, null, files); - Iterable trees = task.parse(); - Checker checker = new Checker(); - for (CompilationUnitTree tree: trees) - checker.check(tree); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + Iterable files + = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java"))); + JavacTask task = tool.getTask(null, fm, null, null, null, files); + Iterable trees = task.parse(); + Checker checker = new Checker(); + for (CompilationUnitTree tree: trees) + checker.check(tree); + } } public int x_public; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6397286.java --- a/langtools/test/tools/javac/T6397286.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6397286.java Thu Oct 30 13:55:51 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 files = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + Iterable 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); - } - public void finished(TaskEvent 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"); } - }); - - 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"); } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6403466.java --- a/langtools/test/tools/javac/T6403466.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6403466.java Thu Oct 30 13:55:51 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 files = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + Iterable files = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); + + Iterable options = Arrays.asList("-processorpath", testClassDir, + "-processor", self, + "-s", ".", + "-d", "."); + JavacTask task = tool.getTask(out, fm, null, options, null, files); - Iterable 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 annos, RoundEnvironment rEnv) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6406771.java --- a/langtools/test/tools/javac/T6406771.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6406771.java Thu Oct 30 13:55:51 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 opts = Arrays.asList("-d", ".", "-processorpath", testClasses, "-processor", self, "-proc:only"); + List 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 elems, RoundEnvironment rEnv) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6407066.java --- a/langtools/test/tools/javac/T6407066.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6407066.java Thu Oct 30 13:55:51 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 path = new ArrayList(); - path.add(new File("BadDirectory")); - path.add(new File(testSrc)); - path.add(new File("BadFile.jar")); + List path = new ArrayList(); + 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 path2 = new ArrayList(); - for (File f: jfm.getLocation(StandardLocation.SOURCE_PATH)) - path2.add(f); + List path2 = new ArrayList(); + 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"); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6410706.java --- a/langtools/test/tools/javac/T6410706.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6410706.java Thu Oct 30 13:55:51 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 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 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6458823/T6458823.java --- a/langtools/test/tools/javac/T6458823/T6458823.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6458823/T6458823.java Thu Oct 30 13:55:51 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 diagColl = new DiagnosticCollector(); - StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); - List options = new ArrayList(); - options.add("-processor"); - options.add("MyProcessor"); - options.add("-proc:only"); - List files = new ArrayList(); - 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 diag : diagColl.getDiagnostics()) { - if (diag.getKind() != Diagnostic.Kind.WARNING) { - throw new AssertionError("Only warnings expected"); + try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { + List options = new ArrayList(); + options.add("-processor"); + options.add("MyProcessor"); + options.add("-proc:only"); + List files = new ArrayList(); + 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 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"); } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6665791.java --- a/langtools/test/tools/javac/T6665791.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6665791.java Thu Oct 30 13:55:51 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 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 units = manager.getJavaFileObjects(test_java); + final StringWriter sw = new StringWriter(); + JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null, + null, units); - new TreeScanner() { - @Override - public Boolean visitClass(ClassTree arg0, Void arg1) { - sw.write(arg0.toString()); - return super.visitClass(arg0, arg1); - } - }.scan(task.parse(), null); + new TreeScanner() { + @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"); + 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"); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6705935.java --- a/langtools/test/tools/javac/T6705935.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6705935.java Thu Oct 30 13:55:51 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 (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 (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 == skip) + System.out.println("Warning: all files skipped; no platform classes found in zip files."); + } } private List asList(Iterable items) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6900149.java --- a/langtools/test/tools/javac/T6900149.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6900149.java Thu Oct 30 13:55:51 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 diag = new DiagnosticCollector(); 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"); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6956462/T6956462.java --- a/langtools/test/tools/javac/T6956462/T6956462.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6956462/T6956462.java Thu Oct 30 13:55:51 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 files = new ArrayList(); - 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 files = new ArrayList(); + 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); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T6956638.java --- a/langtools/test/tools/javac/T6956638.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T6956638.java Thu Oct 30 13:55:51 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 compileOptions = Arrays.asList("-d", classesDir.getPath()); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); - StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null); - Iterable 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 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 parsedTrees = javacTask.parse(); - Iterable analyzedTrees = javacTask.analyze(); - Iterable generatedFiles = javacTask.generate(); + Iterable parsedTrees = javacTask.parse(); + Iterable analyzedTrees = javacTask.analyze(); + Iterable 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)); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T7142672/Bug.java --- a/langtools/test/tools/javac/T7142672/Bug.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T7142672/Bug.java Thu Oct 30 13:55:51 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 opts = new ArrayList(); - opts.add("-proc:only"); - opts.add("-processor"); - opts.add("AnnoProcessor"); + List opts = new ArrayList(); + 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); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T7159016.java --- a/langtools/test/tools/javac/T7159016.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T7159016.java Thu Oct 30 13:55:51 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"); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T8003967/DetectMutableStaticFields.java --- a/langtools/test/tools/javac/T8003967/DetectMutableStaticFields.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T8003967/DetectMutableStaticFields.java Thu Oct 30 13:55:51 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())); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/T8010737/ParameterNamesAreNotCopiedToAnonymousInitTest.java --- a/langtools/test/tools/javac/T8010737/ParameterNamesAreNotCopiedToAnonymousInitTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/T8010737/ParameterNamesAreNotCopiedToAnonymousInitTest.java Thu Oct 30 13:55:51 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 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 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); + + task.addTaskListener(new TaskListener() { - BasicJavacTask impl = (BasicJavacTask)task; - Context context = impl.getContext(); - final Names names = Names.instance(context); + @Override + public void started(TaskEvent e) {} - task.addTaskListener(new TaskListener() { + @Override + public void finished(TaskEvent e) { + class TheTreeScanner extends TreeScanner { + boolean foundAndCorrect = false; - @Override - public void started(TaskEvent e) {} + @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 finished(TaskEvent e) { - class TheTreeScanner extends TreeScanner { - boolean foundAndCorrect = false; + int currentParamPos = 0; + int paramArrayIndex = 0; - @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; + List 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++; + } + currentParamPos++; + params = params.tail; + } + foundAndCorrect = paramArrayIndex >= paramsToCheck.size(); + } + super.visitMethodDef(tree); + } + } - List 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++; - } - currentParamPos++; - params = params.tail; - } - foundAndCorrect = paramArrayIndex >= paramsToCheck.size(); + 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; } - super.visitMethodDef(tree); + 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); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/TryWithResources/InterruptedExceptionTest.java --- a/langtools/test/tools/javac/TryWithResources/InterruptedExceptionTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/TryWithResources/InterruptedExceptionTest.java Thu Oct 30 13:55:51 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); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/TryWithResources/UnusedResourcesTest.java --- a/langtools/test/tools/javac/TryWithResources/UnusedResourcesTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/TryWithResources/UnusedResourcesTest.java Thu Oct 30 13:55:51 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(); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.java --- a/langtools/test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.java Thu Oct 30 13:55:51 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.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.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() { - @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() { + @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); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/annotations/repeatingAnnotations/combo/Helper.java --- a/langtools/test/tools/javac/annotations/repeatingAnnotations/combo/Helper.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/combo/Helper.java Thu Oct 30 13:55:51 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 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 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 files) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java --- a/langtools/test/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java Thu Oct 30 13:55:51 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 f = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java"))); - JavacTask task = tool.getTask(out, fm, null, null, null, f); - Iterable trees = task.parse(); - out.flush(); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + File testSrc = new File(System.getProperty("test.src")); + Iterable f = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java"))); + JavacTask task = tool.getTask(out, fm, null, null, null, f); + Iterable 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java --- a/langtools/test/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java Thu Oct 30 13:55:51 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 f = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java"))); - JavacTask task = tool.getTask(out, fm, null, null, null, f); - Iterable trees = task.parse(); - out.flush(); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + File testSrc = new File(System.getProperty("test.src")); + Iterable f = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java"))); + JavacTask task = tool.getTask(out, fm, null, null, null, f); + Iterable 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java --- a/langtools/test/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java Thu Oct 30 13:55:51 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 f = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java"))); - JavacTask task = tool.getTask(out, fm, null, null, null, f); - Iterable trees = task.parse(); - out.flush(); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + File testSrc = new File(System.getProperty("test.src")); + Iterable f = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java"))); + JavacTask task = tool.getTask(out, fm, null, null, null, f); + Iterable 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/annotations/typeAnnotations/failures/CheckErrorsForSource7.java --- a/langtools/test/tools/javac/annotations/typeAnnotations/failures/CheckErrorsForSource7.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/annotations/typeAnnotations/failures/CheckErrorsForSource7.java Thu Oct 30 13:55:51 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.emptyList(), - null, - fm.getJavaFileObjects(testFile)); - final Trees trees = Trees.instance(task); - final CompilationUnitTree cut = task.parse().iterator().next(); - final List typeAnnotationSpans = new ArrayList<>(); + //gather spans of the @TA annotations into typeAnnotationSpans: + JavacTask task = JavacTool.create().getTask(null, + fm, + null, + Collections.emptyList(), + null, + fm.getJavaFileObjects(testFile)); + final Trees trees = Trees.instance(task); + final CompilationUnitTree cut = task.parse().iterator().next(); + final List typeAnnotationSpans = new ArrayList<>(); - new TreePathScanner() { - @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() { + @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); + }.scan(cut, null); - //sort the spans in the reverse order, to simplify removing them from the source: - Collections.sort(typeAnnotationSpans, new Comparator() { - @Override - public int compare(int[] o1, int[] o2) { - return o2[0] - o1[0]; - } - }); + //sort the spans in the reverse order, to simplify removing them from the source: + Collections.sort(typeAnnotationSpans, new Comparator() { + @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(); + //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[] 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; + for (int[] span : typeAnnotationSpans) { + if (span == toKeep) continue; - updated = updated.substring(0, span[0]) + updated.substring(span[1]); - } + updated = updated.substring(0, span[0]) + updated.substring(span[1]); + } - //parse and verify: - JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated); - DiagnosticCollector errors = new DiagnosticCollector<>(); - JavacTask task2 = JavacTool.create().getTask(null, - fm, - errors, - Arrays.asList("-source", "7"), - null, - Arrays.asList(updatedFile)); - task2.parse(); + //parse and verify: + JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated); + DiagnosticCollector errors = new DiagnosticCollector<>(); + JavacTask task2 = JavacTool.create().getTask(null, + fm, + errors, + Arrays.asList("-source", "7"), + null, + Arrays.asList(updatedFile)); + task2.parse(); + + boolean found = false; - boolean found = false; - - for (Diagnostic 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."); + for (Diagnostic 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; } - found = true; } + + if (!found) + throw new IllegalStateException("Did not produce proper errors for: " + updated); } - - if (!found) - throw new IllegalStateException("Did not produce proper errors for: " + updated); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6406133/T6406133.java --- a/langtools/test/tools/javac/api/6406133/T6406133.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6406133/T6406133.java Thu Oct 30 13:55:51 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, 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 @@ -106,6 +106,8 @@ } public static void main(String... args) throws Exception { - new T6406133().test(); + try (T6406133 t = new T6406133()) { + t.test(); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6410643/T6410643.java --- a/langtools/test/tools/javac/api/6410643/T6410643.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6410643/T6410643.java Thu Oct 30 13:55:51 2014 -0700 @@ -31,6 +31,7 @@ * @run main T6410643 */ +import java.io.IOException; import javax.tools.JavaFileObject; import static java.util.Collections.singleton; @@ -68,7 +69,10 @@ testGetTask(s, s, f); System.err.println("Test result: PASSED"); } - public static void main(String... args) { - new T6410643().test(args); + + public static void main(String... args) throws IOException { + try (T6410643 t = new T6410643()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6411310/T6411310.java --- a/langtools/test/tools/javac/api/6411310/T6411310.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6411310/T6411310.java Thu Oct 30 13:55:51 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 @@ -54,6 +54,8 @@ } public static void main(String... args) throws IOException { - new T6411310().test(args); + try (T6411310 t = new T6411310()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6411333/T6411333.java --- a/langtools/test/tools/javac/api/6411333/T6411333.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6411333/T6411333.java Thu Oct 30 13:55:51 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 @@ -82,7 +82,10 @@ testRelativeUri("util/List.java", false); testRelativeUri("/util/List.java", true); } - public static void main(String... args) { - new T6411333().test(args); + + public static void main(String... args) throws IOException { + try (T6411333 t = new T6411333()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6412656/T6412656.java --- a/langtools/test/tools/javac/api/6412656/T6412656.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6412656/T6412656.java Thu Oct 30 13:55:51 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 @@ -31,6 +31,7 @@ * @run main T6412656 */ +import java.io.IOException; import java.util.Set; import java.util.Collections; import javax.lang.model.element.TypeElement; @@ -52,8 +53,10 @@ System.out.println("OK"); } - public static void main(String... args) { - new T6412656().test(args); + public static void main(String... args) throws IOException { + try (T6412656 t = new T6412656()) { + t.test(args); + } } @SupportedAnnotationTypes("*") diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6415780/T6415780.java --- a/langtools/test/tools/javac/api/6415780/T6415780.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6415780/T6415780.java Thu Oct 30 13:55:51 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 @@ -32,6 +32,7 @@ * @run main T6415780 */ +import java.io.IOException; import static javax.tools.StandardLocation.CLASS_PATH; public class T6415780 extends ToolTester { @@ -39,8 +40,9 @@ System.out.println(fm.getClassLoader(CLASS_PATH).toString()); // null-check } - public static void main(String... args) { - T6415780 tester = new T6415780(); - tester.test(); + public static void main(String... args) throws IOException { + try (T6415780 tester = new T6415780()) { + tester.test(); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6418694/T6418694.java --- a/langtools/test/tools/javac/api/6418694/T6418694.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6418694/T6418694.java Thu Oct 30 13:55:51 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 @@ -32,6 +32,7 @@ * @run main T6418694 */ +import java.io.IOException; import javax.tools.StandardLocation; public class T6418694 extends ToolTester { @@ -52,7 +53,9 @@ } } } - public static void main(String... args) { - new T6418694().test(args); + public static void main(String... args) throws IOException { + try (T6418694 t = new T6418694()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6420409/T6420409.java --- a/langtools/test/tools/javac/api/6420409/T6420409.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6420409/T6420409.java Thu Oct 30 13:55:51 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 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 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 path, File file, Location location) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6420464/T6420464.java --- a/langtools/test/tools/javac/api/6420464/T6420464.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6420464/T6420464.java Thu Oct 30 13:55:51 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"); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6421111/T6421111.java --- a/langtools/test/tools/javac/api/6421111/T6421111.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6421111/T6421111.java Thu Oct 30 13:55:51 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 @@ -33,6 +33,7 @@ */ import java.io.File; +import java.io.IOException; import java.net.URI; import java.util.Arrays; import java.util.Collections; @@ -101,8 +102,10 @@ return SourceVersion.latest(); } } - public static void main(String... args) { - new T6421111().test(args); + public static void main(String... args) throws IOException { + try (T6421111 t = new T6421111()) { + t.test(args); + } } public static AssertionError error(String format, Object... args) { return new AssertionError(String.format(format, args)); diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6421756/T6421756.java --- a/langtools/test/tools/javac/api/6421756/T6421756.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6421756/T6421756.java Thu Oct 30 13:55:51 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 @@ -32,6 +32,7 @@ * @run main T6421756 */ +import java.io.IOException; import java.util.Collections; public class T6421756 extends ToolTester { @@ -44,7 +45,9 @@ System.out.println("OK: got expected error " + e.getLocalizedMessage()); } } - public static void main(String... args) { - new T6421756().test(args); + public static void main(String... args) throws IOException { + try (T6421756 t = new T6421756()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6422215/T6422215.java --- a/langtools/test/tools/javac/api/6422215/T6422215.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6422215/T6422215.java Thu Oct 30 13:55:51 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 @@ -46,7 +46,9 @@ System.out.println("OK: caught expected exception: " + e.getLocalizedMessage()); } } - public static void main(String... args) { - new T6422215().test(args); + public static void main(String... args) throws IOException { + try (T6422215 t = new T6422215()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6422327/T6422327.java --- a/langtools/test/tools/javac/api/6422327/T6422327.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6422327/T6422327.java Thu Oct 30 13:55:51 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 @@ -32,6 +32,7 @@ */ import java.io.File; +import java.io.IOException; public class T6422327 extends ToolTester { void test(String... args) { @@ -43,7 +44,9 @@ System.err.println("OK, got expected exception: " + e.getLocalizedMessage()); } } - public static void main(String... args) { - new T6422327().test(args); + public static void main(String... args) throws IOException { + try (T6422327 t = new T6422327()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6423003/T6423003.java --- a/langtools/test/tools/javac/api/6423003/T6423003.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6423003/T6423003.java Thu Oct 30 13:55:51 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 @@ -32,6 +32,7 @@ * @run main T6423003 */ +import java.io.IOException; import java.util.Arrays; public class T6423003 extends ToolTester { @@ -44,7 +45,9 @@ } throw new AssertionError("Expected IllegalStateException not thrown"); } - public static void main(String... args) { - new T6423003().test(args); + public static void main(String... args) throws IOException { + try (T6423003 t = new T6423003()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6431257/T6431257.java --- a/langtools/test/tools/javac/api/6431257/T6431257.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6431257/T6431257.java Thu Oct 30 13:55:51 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 @@ -67,6 +67,8 @@ } public static void main(String... args) throws IOException { - new T6431257().test(args); + try (T6431257 t = new T6431257()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6431435/T6431435.java --- a/langtools/test/tools/javac/api/6431435/T6431435.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6431435/T6431435.java Thu Oct 30 13:55:51 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 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 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6437349/T6437349.java --- a/langtools/test/tools/javac/api/6437349/T6437349.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6437349/T6437349.java Thu Oct 30 13:55:51 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 @@ -51,6 +51,8 @@ throw new AssertionError(); } public static void main(String... args) throws IOException { - new T6437349().test(args); + try (T6437349 t = new T6437349()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6437999/T6437999.java --- a/langtools/test/tools/javac/api/6437999/T6437999.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6437999/T6437999.java Thu Oct 30 13:55:51 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 @@ -86,6 +86,8 @@ throw new AssertionError("Error in UTF-8 mode"); } public static void main(String... args) throws IOException { - new T6437999().test(args); + try (T6437999 t = new T6437999()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6440333/T6440333.java --- a/langtools/test/tools/javac/api/6440333/T6440333.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6440333/T6440333.java Thu Oct 30 13:55:51 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 @@ -50,6 +50,8 @@ } } public static void main(String... args) throws IOException { - new T6440333().test(args); + try (T6440333 t = new T6440333()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6440528/T6440528.java --- a/langtools/test/tools/javac/api/6440528/T6440528.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6440528/T6440528.java Thu Oct 30 13:55:51 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 @@ -66,6 +66,8 @@ } public static void main(String... args) throws Exception { - new T6440528().test(args); + try (T6440528 t = new T6440528()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6468404/T6468404.java --- a/langtools/test/tools/javac/api/6468404/T6468404.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6468404/T6468404.java Thu Oct 30 13:55:51 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 @@ -88,8 +88,10 @@ if (!task.call()) throw new AssertionError(); } - public static void main(String... args) { - new T6468404().test(args); + public static void main(String... args) throws IOException { + try (T6468404 t = new T6468404()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6731573/T6731573.java --- a/langtools/test/tools/javac/api/6731573/T6731573.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6731573/T6731573.java Thu Oct 30 13:55:51 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, 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 @@ -106,6 +106,8 @@ } public static void main(String... args) throws Exception { - new T6731573().test(); + try (T6731573 t = new T6731573()) { + t.test(); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/6733837/T6733837.java --- a/langtools/test/tools/javac/api/6733837/T6733837.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/6733837/T6733837.java Thu Oct 30 13:55:51 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, 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 @@ -31,6 +31,7 @@ * @run main T6733837 */ +import java.io.IOException; import java.io.StringWriter; import java.io.PrintWriter; import java.net.URI; @@ -43,8 +44,10 @@ public class T6733837 extends ToolTester { - public static void main(String... args) { - new T6733837().exec(); + public static void main(String... args) throws IOException { + try (T6733837 t = new T6733837()) { + t.exec(); + } } public void exec() { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/7086261/T7086261.java --- a/langtools/test/tools/javac/api/7086261/T7086261.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/7086261/T7086261.java Thu Oct 30 13:55:51 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/8007344/Test.java --- a/langtools/test/tools/javac/api/8007344/Test.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/8007344/Test.java Thu Oct 30 13:55:51 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 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 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, diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/Sibling.java --- a/langtools/test/tools/javac/api/Sibling.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/Sibling.java Thu Oct 30 13:55:51 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()); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6258271.java --- a/langtools/test/tools/javac/api/T6258271.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6258271.java Thu Oct 30 13:55:51 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 dl = new DiagnosticListener() { public void report(Diagnostic message) { @@ -43,9 +43,10 @@ System.out.println(message); } }; - StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null); - Iterable 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 files = + fm.getJavaFileObjectsFromStrings(Arrays.asList("nofile.java")); + javac.getTask(null, fm, dl, null, null, files).call(); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6265137.java --- a/langtools/test/tools/javac/api/T6265137.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6265137.java Thu Oct 30 13:55:51 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 dl = new DiagnosticListener() { public void report(Diagnostic message) { @@ -45,10 +46,11 @@ System.out.flush(); } }; - StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null); - String srcdir = System.getProperty("test.src"); - Iterable 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 files = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6265137a.java"))); + javac.getTask(null, fm, dl, Arrays.asList("-target","9"), null, files).call(); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6306137.java --- a/langtools/test/tools/javac/api/T6306137.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6306137.java Thu Oct 30 13:55:51 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(); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6345974.java --- a/langtools/test/tools/javac/api/T6345974.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6345974.java Thu Oct 30 13:55:51 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 f = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java"))); - JavacTask task = tool.getTask(out, fm, null, null, null, f); - Iterable trees = task.parse(); - out.flush(); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + File testSrc = new File(System.getProperty("test.src")); + Iterable f = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java"))); + JavacTask task = tool.getTask(out, fm, null, null, null, f); + Iterable 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6357331.java --- a/langtools/test/tools/javac/api/T6357331.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6357331.java Thu Oct 30 13:55:51 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 opts = Arrays.asList("-d", "."); - StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); - File thisFile = new File(System.getProperty("test.src"), "T6357331.java"); - Iterable 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 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 + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6358786.java --- a/langtools/test/tools/javac/api/T6358786.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6358786.java Thu Oct 30 13:55:51 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); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6358955.java --- a/langtools/test/tools/javac/api/T6358955.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6358955.java Thu Oct 30 13:55:51 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(); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6392782.java --- a/langtools/test/tools/javac/api/T6392782.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6392782.java Thu Oct 30 13:55:51 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 files = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java"))); - JavacTask task = tool.getTask(null, fm, null, null, null, files); - Iterable trees = task.parse(); - TreeScanner scanner = new MyScanner(); - check(scanner, 6, scanner.scan(trees, null)); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + Iterable files = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java"))); + JavacTask task = tool.getTask(null, fm, null, null, null, files); + Iterable trees = task.parse(); + TreeScanner 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6397104.java --- a/langtools/test/tools/javac/api/T6397104.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6397104.java Thu Oct 30 13:55:51 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); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6400205.java --- a/langtools/test/tools/javac/api/T6400205.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6400205.java Thu Oct 30 13:55:51 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."); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6400207.java --- a/langtools/test/tools/javac/api/T6400207.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6400207.java Thu Oct 30 13:55:51 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 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 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."); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6412669.java --- a/langtools/test/tools/javac/api/T6412669.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6412669.java Thu Oct 30 13:55:51 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 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 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 annotations, RoundEnvironment roundEnv) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6419926.java --- a/langtools/test/tools/javac/api/T6419926.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6419926.java Thu Oct 30 13:55:51 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(), 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(), 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()); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6430241.java --- a/langtools/test/tools/javac/api/T6430241.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6430241.java Thu Oct 30 13:55:51 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 files = fm.getJavaFileObjects(testFile); + Iterable 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6431879.java --- a/langtools/test/tools/javac/api/T6431879.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6431879.java Thu Oct 30 13:55:51 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 files = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6431879.class.getName()+".java"))); - JavacTask task = tool.getTask(null, fm, null, null, null, files); - Iterable trees = task.parse(); - TreeScanner 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 files = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6431879.class.getName()+".java"))); + JavacTask task = tool.getTask(null, fm, null, null, null, files); + Iterable trees = task.parse(); + TreeScanner 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 extends TreePathScanner { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6483788.java --- a/langtools/test/tools/javac/api/T6483788.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6483788.java Thu Oct 30 13:55:51 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/T6501502.java --- a/langtools/test/tools/javac/api/T6501502.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/T6501502.java Thu Oct 30 13:55:51 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestClientCodeWrapper.java --- a/langtools/test/tools/javac/api/TestClientCodeWrapper.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestClientCodeWrapper.java Thu Oct 30 13:55:51 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: getMethodsExcept(FileObject.class, "delete")) { + test(m); + } - for (Method m: getMethods(JavaFileObject.class)) { - test(m); - } + for (Method m: getMethods(JavaFileObject.class)) { + test(m); + } - for (Method m: getMethodsExcept(Processor.class, "getCompletions")) { - test(m); - } + for (Method m: getMethodsExcept(Processor.class, "getCompletions")) { + test(m); + } - for (Method m: DiagnosticListener.class.getDeclaredMethods()) { - 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: 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. */ diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestDocComments.java --- a/langtools/test/tools/javac/api/TestDocComments.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestDocComments.java Thu Oct 30 13:55:51 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); - - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - Iterable fileObjects = fm.getJavaFileObjects(file); - JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects); - Iterable units = task.parse(); - Trees trees = Trees.instance(task); + try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + Iterable fileObjects = fm.getJavaFileObjects(file); + JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects); + Iterable 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"); + } } /** diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestGetElementReference.java --- a/langtools/test/tools/javac/api/TestGetElementReference.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestGetElementReference.java Thu Oct 30 13:55:51 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 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 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 d : diagnostics.getDiagnostics()) { - if (d.getKind() == Diagnostic.Kind.ERROR) { - throw new IllegalStateException("Should have been attributed without errors: " + diagnostics.getDiagnostics()); + for (Diagnostic 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) : ""; + 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) : ""; - if (!expected.equals(actual)) { - throw new IllegalStateException("expected=" + expected + "; actual=" + actual); + if (!expected.equals(actual)) { + throw new IllegalStateException("expected=" + expected + "; actual=" + actual); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestGetScope.java --- a/langtools/test/tools/javac/api/TestGetScope.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestGetScope.java Thu Oct 30 13:55:51 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 opts = Arrays.asList("-proc:only", "-doe"); - Iterable 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 opts = Arrays.asList("-proc:only", "-doe"); + Iterable 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestJavacTask.java --- a/langtools/test/tools/javac/api/TestJavacTask.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestJavacTask.java Thu Oct 30 13:55:51 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 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(); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestJavacTaskScanner.java --- a/langtools/test/tools/javac/api/TestJavacTaskScanner.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestJavacTaskScanner.java Thu Oct 30 13:55:51 2014 -0700 @@ -115,7 +115,9 @@ public static void main(String... args) throws IOException { String srcdir = System.getProperty("test.src"); - new TestJavacTaskScanner(new File(srcdir, args[0])).run(); + try (TestJavacTaskScanner t = new TestJavacTaskScanner(new File(srcdir, args[0]))) { + t.run(); + } } private void testGetAllMembers(TypeElement clazz) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestJavacTask_Lock.java --- a/langtools/test/tools/javac/api/TestJavacTask_Lock.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestJavacTask_Lock.java Thu Oct 30 13:55:51 2014 -0700 @@ -67,15 +67,18 @@ void run() throws Exception { comp = ToolProvider.getSystemJavaCompiler(); fm = comp.getStandardFileManager(null, null, null); - - for (MethodKind first: MethodKind.values()) { - for (MethodKind second: MethodKind.values()) { - test(first, second); + try { + 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestJavacTask_Multiple.java --- a/langtools/test/tools/javac/api/TestJavacTask_Multiple.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestJavacTask_Multiple.java Thu Oct 30 13:55:51 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); + int expect = TestKind.values().length * MAX_TASKS; + if (count != expect) { + throw new Exception("Unexpected number of tests completed: " + count + + ", expected: " + expect); + } + } finally { + fm.close(); } - } void test(JavaCompiler comp, StandardJavaFileManager fm, TestKind tk) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestJavacTask_ParseAttrGen.java --- a/langtools/test/tools/javac/api/TestJavacTask_ParseAttrGen.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestJavacTask_ParseAttrGen.java Thu Oct 30 13:55:51 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(); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestResolveError.java --- a/langtools/test/tools/javac/api/TestResolveError.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestResolveError.java Thu Oct 30 13:55:51 2014 -0700 @@ -51,7 +51,9 @@ */ public class TestResolveError extends ToolTester { public static void main(String... args) throws Exception { - new TestResolveError().run(); + try (TestResolveError t = new TestResolveError()) { + t.run(); + } } void run() throws Exception { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestSearchPaths.java --- a/langtools/test/tools/javac/api/TestSearchPaths.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestSearchPaths.java Thu Oct 30 13:55:51 2014 -0700 @@ -76,30 +76,33 @@ void run() throws Exception { compiler = ToolProvider.getSystemJavaCompiler(); fileManager = compiler.getStandardFileManager(null, null, null); - - // basic output path - testClassOutput(); + try { + // 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(); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestTreePath.java --- a/langtools/test/tools/javac/api/TestTreePath.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestTreePath.java Thu Oct 30 13:55:51 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 tests - = fileManager.getJavaFileObjects(writeTestFile()); + try (StandardJavaFileManager fileManager + = compiler.getStandardFileManager(null, null, null)) { + Iterable 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/TestTrees.java --- a/langtools/test/tools/javac/api/TestTrees.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/TestTrees.java Thu Oct 30 13:55:51 2014 -0700 @@ -74,29 +74,30 @@ } }; - StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); - Iterable files = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); + try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { + Iterable files = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); - Iterable opts = Arrays.asList("-d", ".", "-XDcompilePolicy=simple"); + Iterable 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/guide/Test.java --- a/langtools/test/tools/javac/api/guide/Test.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/guide/Test.java Thu Oct 30 13:55:51 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 @@ -80,7 +80,9 @@ } public static void main(String... args) throws Exception { - new Test().test(args); + try (Test t = new Test()) { + t.test(args); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/lib/ToolTester.java --- a/langtools/test/tools/javac/api/lib/ToolTester.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/lib/ToolTester.java Thu Oct 30 13:55:51 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 @@ -31,7 +31,7 @@ import static javax.tools.StandardLocation.SOURCE_PATH; import static javax.tools.StandardLocation.CLASS_OUTPUT; -public class ToolTester { +public class ToolTester implements AutoCloseable { public final File test_src = new File(System.getProperty("test.src", ".")); public final File test_classes = new File(System.getProperty("test.classes", ".")); public final List test_class_path = pathToFiles(System.getProperty("test.class.path"), @@ -77,4 +77,9 @@ result.addAll(b); return result; } + + @Override + public void close() throws IOException { + fm.close(); + } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/taskListeners/CompileEvent.java --- a/langtools/test/tools/javac/api/taskListeners/CompileEvent.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/taskListeners/CompileEvent.java Thu Oct 30 13:55:51 2014 -0700 @@ -73,18 +73,19 @@ assertOutput(out.toString()); JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); - Iterable testFileObjects = fm.getJavaFileObjects(test); + try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { + Iterable testFileObjects = fm.getJavaFileObjects(test); - //test events fired to listeners registered from plugins - //when starting compiler using JavaCompiler.getTask(...).call - List 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 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/taskListeners/EventsBalancedTest.java --- a/langtools/test/tools/javac/api/taskListeners/EventsBalancedTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/taskListeners/EventsBalancedTest.java Thu Oct 30 13:55:51 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/api/taskListeners/TestSimpleAddRemove.java --- a/langtools/test/tools/javac/api/taskListeners/TestSimpleAddRemove.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/api/taskListeners/TestSimpleAddRemove.java Thu Oct 30 13:55:51 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(); diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/cast/intersection/IntersectionTypeParserTest.java --- a/langtools/test/tools/javac/cast/intersection/IntersectionTypeParserTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/cast/intersection/IntersectionTypeParserTest.java Thu Oct 30 13:55:51 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; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/classreader/T7031108.java --- a/langtools/test/tools/javac/classreader/T7031108.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/classreader/T7031108.java Thu Oct 30 13:55:51 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 dc = new DiagnosticCollector(); - compile(comp, fm, dc, getClass().getName(), dummy); - List> diags =dc.getDiagnostics(); + DiagnosticCollector dc = new DiagnosticCollector(); + compile(comp, fm, dc, getClass().getName(), dummy); + List> 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"); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/defaultMethods/DefaultMethodFlags.java --- a/langtools/test/tools/javac/defaultMethods/DefaultMethodFlags.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/defaultMethods/DefaultMethodFlags.java Thu Oct 30 13:55:51 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 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 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java --- a/langtools/test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java Thu Oct 30 13:55:51 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; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/defaultMethods/syntax/TestDefaultMethodsSyntax.java --- a/langtools/test/tools/javac/defaultMethods/syntax/TestDefaultMethodsSyntax.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/defaultMethods/syntax/TestDefaultMethodsSyntax.java Thu Oct 30 13:55:51 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; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/diags/CheckResourceKeys.java --- a/langtools/test/tools/javac/diags/CheckResourceKeys.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/diags/CheckResourceKeys.java Thu Oct 30 13:55:51 2014 -0700 @@ -313,27 +313,28 @@ Set getCodeStrings() throws IOException { Set results = new TreeSet(); 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/doclint/DocLintTest.java --- a/langtools/test/tools/javac/doclint/DocLintTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/doclint/DocLintTest.java Thu Oct 30 13:55:51 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.emptyList(), - Main.Result.OK, - EnumSet.noneOf(Message.class)); + test(Collections.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 opts, Main.Result expectResult, Set expectMessages) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/doctree/DocTreePathScannerTest.java --- a/langtools/test/tools/javac/doctree/DocTreePathScannerTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/doctree/DocTreePathScannerTest.java Thu Oct 30 13:55:51 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 fos = fm.getJavaFileObjectsFromFiles(files); - Iterable 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 units = t.parse(); - Iterable 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/doctree/SimpleDocTreeVisitorTest.java --- a/langtools/test/tools/javac/doctree/SimpleDocTreeVisitorTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/doctree/SimpleDocTreeVisitorTest.java Thu Oct 30 13:55:51 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 fos = fm.getJavaFileObjectsFromFiles(files); + Iterable 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 units = t.parse(); + Iterable units = t.parse(); - Set found = EnumSet.noneOf(DocTree.Kind.class); - DeclScanner ds = new DeclScanner(trees, found); - for (CompilationUnitTree unit: units) { - ds.scan(unit, null); - } + Set 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); + 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"); } - - if (errors > 0) - throw new Exception(errors + " errors occurred"); } void error(String msg) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/file/T7068451.java --- a/langtools/test/tools/javac/file/T7068451.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/file/T7068451.java Thu Oct 30 13:55:51 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/flow/LVTHarness.java --- a/langtools/test/tools/javac/flow/LVTHarness.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/flow/LVTHarness.java Thu Oct 30 13:55:51 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(); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/generics/bridges/BridgeHarness.java --- a/langtools/test/tools/javac/generics/bridges/BridgeHarness.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/generics/bridges/BridgeHarness.java Thu Oct 30 13:55:51 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(); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java --- a/langtools/test/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java Thu Oct 30 13:55:51 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); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/generics/diamond/7030687/ParserTest.java --- a/langtools/test/tools/javac/generics/diamond/7030687/ParserTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/generics/diamond/7030687/ParserTest.java Thu Oct 30 13:55:51 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); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/generics/inference/7086601/T7086601b.java --- a/langtools/test/tools/javac/generics/inference/7086601/T7086601b.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/generics/inference/7086601/T7086601b.java Thu Oct 30 13:55:51 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; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/lambda/BadLambdaExpr.java --- a/langtools/test/tools/javac/lambda/BadLambdaExpr.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/lambda/BadLambdaExpr.java Thu Oct 30 13:55:51 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; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/lambda/TestSelfRef.java --- a/langtools/test/tools/javac/lambda/TestSelfRef.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/lambda/TestSelfRef.java Thu Oct 30 13:55:51 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; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java --- a/langtools/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Thu Oct 30 13:55:51 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 allCastInfo() { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/lambda/methodReference/SamConversionComboTest.java --- a/langtools/test/tools/javac/lambda/methodReference/SamConversionComboTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/lambda/methodReference/SamConversionComboTest.java Thu Oct 30 13:55:51 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); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java --- a/langtools/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/lambdaShapes/org/openjdk/tests/javac/FDTest.java Thu Oct 30 13:55:51 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 fdtest : generateCases()) { runTest(fdtest.fst, fdtest.snd, comp, fm); } + + teardown(); } @Test(dataProvider = "fdCases") diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/nativeHeaders/NativeHeaderTest.java --- a/langtools/test/tools/javac/nativeHeaders/NativeHeaderTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/nativeHeaders/NativeHeaderTest.java Thu Oct 30 13:55:51 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"); } /** diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/options/XjcovUnionTypeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/options/XjcovUnionTypeTest.java Thu Oct 30 13:55:51 2014 -0700 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8059453 + * @summary -Xjcov causes crash with union types + * @compile -Xjcov XjcovUnionTypeTest.java + */ + +public class XjcovUnionTypeTest { + public static void main(String[] args) { + try { + return; + } catch (IllegalStateException | IllegalArgumentException e) { + } + } +} diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/options/xprefer/XPreferTest.java --- a/langtools/test/tools/javac/options/xprefer/XPreferTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/options/xprefer/XPreferTest.java Thu Oct 30 13:55:51 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 dirSubset : SubseqIter.subseqsOf(Dir.values())) { + for (List dirSubset : SubseqIter.subseqsOf(Dir.values())) { + + if (dirSubset.isEmpty()) + continue; - if (dirSubset.isEmpty()) - continue; - - for (ImplicitOption policy : ImplicitOption.values()) { - for (List dirOrder : PermutationIterator.permutationsOf(dirSubset)) { - new TestCase(dirOrder, policy, testCaseCounter++).run(); + for (ImplicitOption policy : ImplicitOption.values()) { + for (List 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."); diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/plugin/showtype/Test.java --- a/langtools/test/tools/javac/plugin/showtype/Test.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/plugin/showtype/Test.java Thu Oct 30 13:55:51 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 ref) throws Exception { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/positions/TreeEndPosTest.java --- a/langtools/test/tools/javac/positions/TreeEndPosTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/positions/TreeEndPosTest.java Thu Oct 30 13:55:51 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 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 options = new ArrayList<>(); + options.add("-cp"); + options.add(tempDir.getPath()); + options.add("-d"); + options.add(tempDir.getPath()); + options.add("-XDshouldStopPolicy=GENERATE"); - List sources = new ArrayList<>(); - sources.add(src); - JavaCompiler.CompilationTask task = - compiler.getTask(writer, javaFileManager, - dc, options, null, - sources); - task.call(); - for (Diagnostic diagnostic : (List) 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 sources = new ArrayList<>(); + sources.add(src); + JavaCompiler.CompilationTask task = + compiler.getTask(writer, javaFileManager, + dc, options, null, + sources); + task.call(); + for (Diagnostic diagnostic : (List) 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"); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/6348193/T6348193.java --- a/langtools/test/tools/javac/processing/6348193/T6348193.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/6348193/T6348193.java Thu Oct 30 13:55:51 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 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 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/6348499/T6348499.java --- a/langtools/test/tools/javac/processing/6348499/T6348499.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/6348499/T6348499.java Thu Oct 30 13:55:51 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 files = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java"))); - Iterable 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 files = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java"))); + Iterable 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/6378728/T6378728.java --- a/langtools/test/tools/javac/processing/6378728/T6378728.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/6378728/T6378728.java Thu Oct 30 13:55:51 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"); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/6414633/T6414633.java --- a/langtools/test/tools/javac/processing/6414633/T6414633.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/6414633/T6414633.java Thu Oct 30 13:55:51 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 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 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 pathToFiles(String path) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/6430209/T6430209.java --- a/langtools/test/tools/javac/processing/6430209/T6430209.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/6430209/T6430209.java Thu Oct 30 13:55:51 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 files = fm.getJavaFileObjectsFromFiles(Arrays.asList( - new File(testSrc, "test0.java"), new File(testSrc, "test1.java"))); - Iterable 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 files = fm.getJavaFileObjectsFromFiles(Arrays.asList( + new File(testSrc, "test0.java"), new File(testSrc, "test1.java"))); + Iterable 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/T6439826.java --- a/langtools/test/tools/javac/processing/T6439826.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/T6439826.java Thu Oct 30 13:55:51 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 files = - fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6439826.class.getName()+".java"))); - Iterable 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 files = + fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6439826.class.getName()+".java"))); + Iterable 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 annotations, diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/errors/TestSuppression.java --- a/langtools/test/tools/javac/processing/errors/TestSuppression.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/errors/TestSuppression.java Thu Oct 30 13:55:51 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 args = new ArrayList(); -// args.add("-XprintProcessorInfo"); - args.add("-XprintRounds"); - args.add("-Agen=" + gen); - if (wk == WarningKind.YES) - args.add("-Xlint:serial"); - Iterable 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 args = new ArrayList(); + // args.add("-XprintProcessorInfo"); + args.add("-XprintRounds"); + args.add("-Agen=" + gen); + if (wk == WarningKind.YES) + args.add("-Xlint:serial"); + Iterable 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/loader/testClose/TestClose.java --- a/langtools/test/tools/javac/processing/loader/testClose/TestClose.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/loader/testClose/TestClose.java Thu Oct 30 13:55:51 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 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 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 files = Arrays.asList( - new MemFile("my://dummy", "class Dummy { }")); - List 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 files = Arrays.asList( + new MemFile("my://dummy", "class Dummy { }")); + List 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()")); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/model/testgetallmembers/Main.java --- a/langtools/test/tools/javac/processing/model/testgetallmembers/Main.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/model/testgetallmembers/Main.java Thu Oct 30 13:55:51 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.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.emptyList()); + JavacTask javac = (JavacTask)tool.getTask(null, fm, null, null, null, null); + Elements elements = javac.getElements(); - final Set packages = new LinkedHashSet(); + final Set packages = new LinkedHashSet(); - 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++; - type = null; + 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; + } 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/model/type/BoundsTest.java --- a/langtools/test/tools/javac/processing/model/type/BoundsTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/model/type/BoundsTest.java Thu Oct 30 13:55:51 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/model/type/IntersectionPropertiesTest.java --- a/langtools/test/tools/javac/processing/model/type/IntersectionPropertiesTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/model/type/IntersectionPropertiesTest.java Thu Oct 30 13:55:51 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/model/util/elements/doccomments/TestDocComments.java --- a/langtools/test/tools/javac/processing/model/util/elements/doccomments/TestDocComments.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/model/util/elements/doccomments/TestDocComments.java Thu Oct 30 13:55:51 2014 -0700 @@ -104,11 +104,12 @@ } }; JavaCompiler c = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); - Iterable 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 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/model/util/elements/doccomments/TestPackageInfoComments.java --- a/langtools/test/tools/javac/processing/model/util/elements/doccomments/TestPackageInfoComments.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/model/util/elements/doccomments/TestPackageInfoComments.java Thu Oct 30 13:55:51 2014 -0700 @@ -60,11 +60,12 @@ } }; JavaCompiler c = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); - Iterable 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 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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/options/testCommandLineClasses/Test.java --- a/langtools/test/tools/javac/processing/options/testCommandLineClasses/Test.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/options/testCommandLineClasses/Test.java Thu Oct 30 13:55:51 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 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(); + } } List reverse(List list) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/processing/rounds/BaseClassesNotReRead.java --- a/langtools/test/tools/javac/processing/rounds/BaseClassesNotReRead.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/processing/rounds/BaseClassesNotReRead.java Thu Oct 30 13:55:51 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 files = - fm.getJavaFileObjects(new File(sources, "BaseClassesNotReReadSource.java")); - DiagnosticListener noErrors = new DiagnosticListener() { - @Override - public void report(Diagnostic diagnostic) { - throw new IllegalStateException(diagnostic.toString()); - } - }; - JavaFileManager manager = new OnlyOneReadFileManager(fm); - Iterable 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 files = + fm.getJavaFileObjects(new File(sources, "BaseClassesNotReReadSource.java")); + DiagnosticListener noErrors = new DiagnosticListener() { + @Override + public void report(Diagnostic diagnostic) { + throw new IllegalStateException(diagnostic.toString()); + } + }; + JavaFileManager manager = new OnlyOneReadFileManager(fm); + Iterable options = Arrays.asList("-processor", "BaseClassesNotReRead"); + JavacTask task = (JavacTask) compiler.getTask(null, manager, noErrors, options, null, files); + task.analyze(); + } } int round = 1; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/profiles/ProfileOptionTest.java --- a/langtools/test/tools/javac/profiles/ProfileOptionTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/profiles/ProfileOptionTest.java Thu Oct 30 13:55:51 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/resolve/ResolveHarness.java --- a/langtools/test/tools/javac/resolve/ResolveHarness.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/resolve/ResolveHarness.java Thu Oct 30 13:55:51 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(); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/ClassTreeTest.java --- a/langtools/test/tools/javac/tree/ClassTreeTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/ClassTreeTest.java Thu Oct 30 13:55:51 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 opts = Collections.emptyList(); - File testSrc = new File(System.getProperty("test.src")); - File thisFile = new File(testSrc, ClassTreeTest.class.getSimpleName() + ".java"); - Iterable 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 opts = Collections.emptyList(); + File testSrc = new File(System.getProperty("test.src")); + File thisFile = new File(testSrc, ClassTreeTest.class.getSimpleName() + ".java"); + Iterable 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/DocCommentToplevelTest.java --- a/langtools/test/tools/javac/tree/DocCommentToplevelTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/DocCommentToplevelTest.java Thu Oct 30 13:55:51 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"); + if (errors > 0) + throw new AssertionError(errors + " errors found"); - System.out.println(checks + " checks were made"); + System.out.println(checks + " checks were made"); + } } PackageKind pk; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/MissingSemicolonTest.java --- a/langtools/test/tools/javac/tree/MissingSemicolonTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/MissingSemicolonTest.java Thu Oct 30 13:55:51 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); + 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(); } - - System.err.println(fileCount + " files read"); - if (errors > 0) - System.err.println(errors + " errors"); - - return errors == 0; } void test(File file) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/PrettySimpleStringTest.java --- a/langtools/test/tools/javac/tree/PrettySimpleStringTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/PrettySimpleStringTest.java Thu Oct 30 13:55:51 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 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 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"); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/T6963934.java --- a/langtools/test/tools/javac/tree/T6963934.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/T6963934.java Thu Oct 30 13:55:51 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); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/T6993305.java --- a/langtools/test/tools/javac/tree/T6993305.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/T6993305.java Thu Oct 30 13:55:51 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 fos = fm.getJavaFileObjects(f); + JavacTask task = tool.getTask(null, fm, null, null, null, fos); + Iterable cus = task.parse(); - File f = new File(testSrc, T6993305.class.getSimpleName() + ".java"); - Iterable fos = fm.getJavaFileObjects(f); - JavacTask task = tool.getTask(null, fm, null, null, null, fos); - Iterable 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) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/TestToString.java --- a/langtools/test/tools/javac/tree/TestToString.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/TestToString.java Thu Oct 30 13:55:51 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 { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/TreePosRoundsTest.java --- a/langtools/test/tools/javac/tree/TreePosRoundsTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/TreePosRoundsTest.java Thu Oct 30 13:55:51 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 files = fm.getJavaFileObjects(thisFile); - List 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 files = fm.getJavaFileObjects(thisFile); + List 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); diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/tree/TreePosTest.java --- a/langtools/test/tools/javac/tree/TreePosTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/tree/TreePosTest.java Thu Oct 30 13:55:51 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 files = new ArrayList(); - 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"); + List files = new ArrayList(); + 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; } - baseDir = d; + else if (arg.startsWith("-")) + throw new Error("unknown option: " + arg); + else { + while (i < args.length) + files.add(new File(baseDir, args[i++])); + } } - 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); - } + 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"); + if (fileCount != 1) + System.err.println(fileCount + " files read"); + if (errors > 0) + System.err.println(errors + " errors"); - return (gui || errors == 0); + return (gui || errors == 0); + } finally { + fm.close(); + } } /** diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/unit/T6198196.java --- a/langtools/test/tools/javac/unit/T6198196.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/unit/T6198196.java Thu Oct 30 13:55:51 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); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/varargs/6199075/T6199075.java --- a/langtools/test/tools/javac/varargs/6199075/T6199075.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/varargs/6199075/T6199075.java Thu Oct 30 13:55:51 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. diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/varargs/7043922/T7043922.java --- a/langtools/test/tools/javac/varargs/7043922/T7043922.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/varargs/7043922/T7043922.java Thu Oct 30 13:55:51 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(); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javac/versions/Versions.java --- a/langtools/test/tools/javac/versions/Versions.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javac/versions/Versions.java Thu Oct 30 13:55:51 2014 -0700 @@ -278,22 +278,25 @@ protected boolean compile(String sourceFile, Listoptions) { JavaCompiler.CompilationTask jctask; - StandardJavaFileManager fm = javacompiler.getStandardFileManager(null, null, null); - Iterable files = fm.getJavaFileObjects(sourceFile); + try (StandardJavaFileManager fm = javacompiler.getStandardFileManager(null, null, null)) { + Iterable files = fm.getJavaFileObjects(sourceFile); - jctask = javacompiler.getTask( - null, // Writer - fm, // JavaFileManager - null, // DiagnosticListener - options, // Iterable - null, // Iterable classes - files); // Iterable + jctask = javacompiler.getTask( + null, // Writer + fm, // JavaFileManager + null, // DiagnosticListener + options, // Iterable + null, // Iterable classes + files); // Iterable - 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); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/CheckResourceKeys.java --- a/langtools/test/tools/javadoc/CheckResourceKeys.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/CheckResourceKeys.java Thu Oct 30 13:55:51 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 getCodeKeys() throws IOException { Set results = new TreeSet(); 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.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.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 diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/DocletPathTest.java --- a/langtools/test/tools/javadoc/api/basic/DocletPathTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/DocletPathTest.java Thu Oct 30 13:55:51 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 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 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 files = Arrays.asList(srcFile); - Iterable 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 files = Arrays.asList(srcFile); + Iterable 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"); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/GetTask_DiagListenerTest.java --- a/langtools/test/tools/javadoc/api/basic/GetTask_DiagListenerTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/GetTask_DiagListenerTest.java Thu Oct 30 13:55:51 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 files = Arrays.asList(srcFile); - DiagnosticCollector dc = new DiagnosticCollector(); - DocumentationTask t = tool.getTask(null, fm, dc, null, null, files); - if (t.call()) { - throw new Exception("task succeeded unexpectedly"); - } else { - List diagCodes = new ArrayList(); - 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 files = Arrays.asList(srcFile); + DiagnosticCollector dc = new DiagnosticCollector(); + DocumentationTask t = tool.getTask(null, fm, dc, null, null, files); + if (t.call()) { + throw new Exception("task succeeded unexpectedly"); + } else { + List diagCodes = new ArrayList(); + for (Diagnostic d: dc.getDiagnostics()) { + System.err.println(d); + diagCodes.add(d.getCode()); + } + List 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 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"); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/GetTask_DocletClassTest.java --- a/langtools/test/tools/javadoc/api/basic/GetTask_DocletClassTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/GetTask_DocletClassTest.java Thu Oct 30 13:55:51 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 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.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 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.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 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 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; + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/GetTask_FileObjectsTest.java --- a/langtools/test/tools/javadoc/api/basic/GetTask_FileObjectsTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/GetTask_FileObjectsTest.java Thu Oct 30 13:55:51 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 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 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 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 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 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 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 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 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); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/GetTask_OptionsTest.java --- a/langtools/test/tools/javadoc/api/basic/GetTask_OptionsTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/GetTask_OptionsTest.java Thu Oct 30 13:55:51 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 files = Arrays.asList(srcFile); - Iterable options = Arrays.asList("-noindex"); - DocumentationTask t = tool.getTask(null, fm, null, null, options, files); - if (t.call()) { - System.err.println("task succeeded"); - Set expectFiles = new TreeSet(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 files = Arrays.asList(srcFile); + Iterable options = Arrays.asList("-noindex"); + DocumentationTask t = tool.getTask(null, fm, null, null, options, files); + if (t.call()) { + System.err.println("task succeeded"); + Set expectFiles = new TreeSet(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 options = Arrays.asList((String) null); - Iterable 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 options = Arrays.asList((String) null); + Iterable 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); + } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/GetTask_WriterTest.java --- a/langtools/test/tools/javadoc/api/basic/GetTask_WriterTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/GetTask_WriterTest.java Thu Oct 30 13:55:51 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 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 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"); } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/JavadocTaskImplTest.java --- a/langtools/test/tools/javadoc/api/basic/JavadocTaskImplTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/JavadocTaskImplTest.java Thu Oct 30 13:55:51 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 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 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 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 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); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/TagletPathTest.java --- a/langtools/test/tools/javadoc/api/basic/TagletPathTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/TagletPathTest.java Thu Oct 30 13:55:51 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 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 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 files = Arrays.asList(srcFile); - Iterable 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 doc = Files.readAllLines(f.toPath(), Charset.defaultCharset()); - for (String line: doc) { - if (line.contains("" + TEST_STRING + "")) { - 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 files = Arrays.asList(srcFile); + Iterable 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 doc = Files.readAllLines(f.toPath(), Charset.defaultCharset()); + for (String line: doc) { + if (line.contains("" + TEST_STRING + "")) { + 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"); } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/api/basic/Task_reuseTest.java --- a/langtools/test/tools/javadoc/api/basic/Task_reuseTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/api/basic/Task_reuseTest.java Thu Oct 30 13:55:51 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 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 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"); + } } } } diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javadoc/doclint/DocLintTest.java --- a/langtools/test/tools/javadoc/doclint/DocLintTest.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javadoc/doclint/DocLintTest.java Thu Oct 30 13:55:51 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.emptyList(), - Main.Result.ERROR, - EnumSet.of(Message.DL_ERR9A, Message.DL_WRN12A)); + test(Collections.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 opts, Main.Result expectResult, Set expectMessages) { diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/javap/TestSuperclass.java --- a/langtools/test/tools/javap/TestSuperclass.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/javap/TestSuperclass.java Thu Oct 30 13:55:51 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; diff -r 952159eaf30b -r 14c8294d03a4 langtools/test/tools/sjavac/DependencyCollection.java --- a/langtools/test/tools/sjavac/DependencyCollection.java Thu Oct 30 08:35:04 2014 -0700 +++ b/langtools/test/tools/sjavac/DependencyCollection.java Thu Oct 30 13:55:51 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 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 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 foundDependencies = depsCollector.getDependenciesForPkg(pkg); + // Find pkg symbol + PackageSymbol pkg = findPkgSymbolWithName(depsCollector.getSourcePackages(), "pkg"); + Set 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 found = foundDependencies.stream() - .map(DependencyCollection::extractNumber) - .collect(Collectors.toSet()); - found.remove(-1); // Dependencies with no number (java.lang etc) - Set 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 found = foundDependencies.stream() + .map(DependencyCollection::extractNumber) + .collect(Collectors.toSet()); + found.remove(-1); // Dependencies with no number (java.lang etc) + Set 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 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 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 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)); + Set 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."); } - - if (missing.size() > 0 || unexpected.size() > 0) - throw new AssertionError("Missing and/or unexpected dependencies found."); } private static PackageSymbol findPkgSymbolWithName(Set syms, String name) {