8137075: Sjavac tests are leaking file managers
Summary: Closing sjavac file managers.
Reviewed-by: jjg
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/JavacState.java Tue Nov 03 17:54:36 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/JavacState.java Tue Nov 03 21:29:46 2015 +0100
@@ -527,7 +527,7 @@
* Compare the javac_state recorded public apis of packages on the classpath
* with the actual public apis on the classpath.
*/
- public void taintPackagesDependingOnChangedClasspathPackages() {
+ public void taintPackagesDependingOnChangedClasspathPackages() throws IOException {
// 1. Collect fully qualified names of all interesting classpath dependencies
Set<String> fqDependencies = new HashSet<>();
@@ -549,6 +549,7 @@
for (String cpDep : fqDependencies) {
onDiskPubApi.put(cpDep, pubApiExtractor.getPubApi(cpDep));
}
+ pubApiExtractor.close();
// 3. Compare them with the public APIs as of last compilation (loaded from javac_state)
nextPkg:
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/PubApiExtractor.java Tue Nov 03 17:54:36 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/PubApiExtractor.java Tue Nov 03 21:29:46 2015 +0100
@@ -25,6 +25,7 @@
package com.sun.tools.sjavac;
+import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
@@ -46,8 +47,10 @@
public class PubApiExtractor {
// Setup a compiler context for finding classes in the classpath
// and to execute annotation processors.
- Context context;
- CompilationTask task;
+ final Context context;
+ final CompilationTask task;
+
+ final SmartFileManager fileManager;
/**
* Setup a compilation context, used for reading public apis of classes on the classpath
@@ -55,7 +58,7 @@
*/
public PubApiExtractor(Options options) {
JavacTool compiler = com.sun.tools.javac.api.JavacTool.create();
- SmartFileManager fileManager = new SmartFileManager(compiler.getStandardFileManager(null, null, null));
+ fileManager = new SmartFileManager(compiler.getStandardFileManager(null, null, null));
context = new com.sun.tools.javac.util.Context();
String[] args = options.prepJavacArgs();
task = compiler.getTask(new PrintWriter(System.err),
@@ -82,4 +85,8 @@
v.visit(cs);
return v.getCollectedPubApi();
}
+
+ public void close() throws IOException {
+ fileManager.close();
+ }
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SjavacImpl.java Tue Nov 03 17:54:36 2015 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SjavacImpl.java Tue Nov 03 21:29:46 2015 +0100
@@ -209,21 +209,20 @@
// Go through all sources and taint all packages that miss artifacts.
javac_state.taintPackagesThatMissArtifacts();
- // Check recorded classpath public apis. Taint packages that depend on
- // classpath classes whose public apis have changed.
- javac_state.taintPackagesDependingOnChangedClasspathPackages();
+ try {
+ // Check recorded classpath public apis. Taint packages that depend on
+ // classpath classes whose public apis have changed.
+ javac_state.taintPackagesDependingOnChangedClasspathPackages();
- // Now clean out all known artifacts belonging to tainted packages.
- javac_state.deleteClassArtifactsInTaintedPackages();
- // Copy files, for example property files, images files, xml files etc etc.
- javac_state.performCopying(Util.pathToFile(options.getDestDir()), suffixRules);
- // Translate files, for example compile properties or compile idls.
- javac_state.performTranslation(Util.pathToFile(gensrc), suffixRules);
- // Add any potentially generated java sources to the tobe compiled list.
- // (Generated sources must always have a package.)
- Map<String,Source> generated_sources = new HashMap<>();
-
- try {
+ // Now clean out all known artifacts belonging to tainted packages.
+ javac_state.deleteClassArtifactsInTaintedPackages();
+ // Copy files, for example property files, images files, xml files etc etc.
+ javac_state.performCopying(Util.pathToFile(options.getDestDir()), suffixRules);
+ // Translate files, for example compile properties or compile idls.
+ javac_state.performTranslation(Util.pathToFile(gensrc), suffixRules);
+ // Add any potentially generated java sources to the tobe compiled list.
+ // (Generated sources must always have a package.)
+ Map<String,Source> generated_sources = new HashMap<>();
Source.scanRoot(Util.pathToFile(options.getGenSrcDir()), Util.set(".java"), null, null, null, null,
generated_sources, modules, current_module, false, true, false);
--- a/langtools/test/tools/sjavac/ApiExtraction.java Tue Nov 03 17:54:36 2015 +0100
+++ b/langtools/test/tools/sjavac/ApiExtraction.java Tue Nov 03 21:29:46 2015 +0100
@@ -92,6 +92,7 @@
Options options = Options.parseArgs("-d", "bin", "--state-dir=bin", "-cp", ".");
PubApiExtractor pubApiExtr = new PubApiExtractor(options);
PubApi actualApi = pubApiExtr.getPubApi("TestClass");
+ pubApiExtr.close();
// Validate result
PubApi expectedApi = getExpectedPubApi();