This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 8bcf2c3 fix: close Files.walk() stream in
getOutputDirectoryPerVersion() (#1071)
8bcf2c3 is described below
commit 8bcf2c3c231343a9b2fbf4f613122e2fdaa4068d
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sun Jul 5 10:59:12 2026 +0000
fix: close Files.walk() stream in getOutputDirectoryPerVersion() (#1071)
Files.walk() returns a Stream that holds a DirectoryStream handle.
Without try-with-resources, the handle is not released until GC,
which can cause 'Too many open files' errors on projects with
many multi-release version directories.
Fixes #1070
---
.../apache/maven/plugin/compiler/CompilerMojo.java | 32 ++++++++++++----------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
index 425f16d..306ac59 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
@@ -347,22 +347,24 @@ public class CompilerMojo extends AbstractCompilerMojo {
return null;
}
final var paths = new TreeMap<SourceVersion, Path>();
- Files.walk(root, 1).forEach((path) -> {
- SourceVersion version;
- if (path.equals(root)) {
- path = outputDirectory;
- version = SourceVersion.RELEASE_0;
- } else {
- try {
- version = SourceVersion.valueOf("RELEASE_" +
path.getFileName());
- } catch (IllegalArgumentException e) {
- throw new CompilationFailureException("Invalid version
number for " + path, e);
+ try (Stream<Path> stream = Files.walk(root, 1)) {
+ stream.forEach((path) -> {
+ SourceVersion version;
+ if (path.equals(root)) {
+ path = outputDirectory;
+ version = SourceVersion.RELEASE_0;
+ } else {
+ try {
+ version = SourceVersion.valueOf("RELEASE_" +
path.getFileName());
+ } catch (IllegalArgumentException e) {
+ throw new CompilationFailureException("Invalid version
number for " + path, e);
+ }
}
- }
- if (paths.put(version, path) != null) {
- throw new CompilationFailureException("Duplicated version
number for " + path);
- }
- });
+ if (paths.put(version, path) != null) {
+ throw new CompilationFailureException("Duplicated version
number for " + path);
+ }
+ });
+ }
return paths;
}