Make sure the vanilla java builder closes its JavaFileManager.
I observed that before this change, large vanilla Java builds could exhaust the file descriptor limit of java builder worker processes.
Closes
@@ -152,16 +152,14 @@ public class VanillaJavaBuilder implements Closeable {
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
StringWriter output = new StringWriter();
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fileManager =
- javaCompiler.getStandardFileManager(diagnosticCollector, ENGLISH, UTF_8);
-
Path tempDir = Paths.get(firstNonNull(optionsParser.getTempDir(), "_tmp"));
Path nativeHeaderDir = tempDir.resolve("native_headers");
Files.createDirectories(nativeHeaderDir);
-
+ boolean ok;
+ try (StandardJavaFileManager fileManager =
+ javaCompiler.getStandardFileManager(diagnosticCollector, ENGLISH, UTF_8)) {
setLocations(optionsParser, fileManager, nativeHeaderDir);
ImmutableList<JavaFileObject> sources = getSources(optionsParser, fileManager);
- boolean ok;
if (sources.isEmpty()) {
ok = true;
} else {
@@ -176,6 +174,7 @@ public class VanillaJavaBuilder implements Closeable {
setProcessors(optionsParser, fileManager, task);
ok = task.call();
}
+ }
if (ok) {
writeOutput(optionsParser);
writeNativeHeaderOutput(optionsParser, nativeHeaderDir);
