From 07f80ab482dc3a825769afd9e05be83509f23036 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Fri, 11 Aug 2023 21:21:31 +0200 Subject: [PATCH] Fix directory leak --- .../discovery/projects/JavaSourceInfo.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaSourceInfo.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaSourceInfo.java index a872a7fe..9c8eda94 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaSourceInfo.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaSourceInfo.java @@ -175,16 +175,18 @@ public void analyzeSourceDirectories(MultiStatus result) throws CoreException { try { // when there are declared Java files, expect them to match if (declaredJavaFilesInFolder > 0) { - var javaFilesInParent = Files.list(entryParentLocation).filter(JavaSourceInfo::isJavaFile).count(); - if (javaFilesInParent != declaredJavaFilesInFolder) { - if (potentialSplitPackageOrSubsetFolders.add(potentialSourceRoot)) { - result.add( - Status.warning( - format( - "Folder '%s' contains more Java files then configured in Bazel. This is a split-package scenario which is challenging to support in IDEs! Consider re-structuring your source code into separate folder hierarchies and Bazel packages.", - entryParentLocation))); + try (var files = Files.list(entryParentLocation)) { + var javaFilesInParent = files.filter(JavaSourceInfo::isJavaFile).count(); + if (javaFilesInParent != declaredJavaFilesInFolder) { + if (potentialSplitPackageOrSubsetFolders.add(potentialSourceRoot)) { + result.add( + Status.warning( + format( + "Folder '%s' contains more Java files then configured in Bazel. This is a split-package scenario which is challenging to support in IDEs! Consider re-structuring your source code into separate folder hierarchies and Bazel packages.", + entryParentLocation))); + } + continue; // continue with next so we capture all possible warnings (we could also abort, though) } - continue; // continue with next so we capture all possible warnings (we could also abort, though) } } } catch (IOException e) {