Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ public static void removeFileFromRepo(Path repoPath, Path filePath) throws IOExc
* @throws IOException If an I/O error occurs.
*/
public static void deleteRepo(Path directoryPath) throws IOException {
try (var stream = Files.walk(directoryPath)) {
stream
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}
Files.walk(directoryPath)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
Comment on lines +81 to +84

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/util/dataset/GitVersionControlLocalFileStorage.java"
sed -n '73,90p' "$file"
rg -n -C 6 'Files\.walk\(' --glob '*.java'

Repository: sshiv012/texera

Length of output: 738


🏁 Script executed:

#!/bin/bash
set -euo pipefail
file="common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/util/dataset/GitVersionControlLocalFileStorage.java"

printf '%s\n' '--- method and imports ---'
sed -n '1,110p' "$file"

printf '%s\n' '--- Stream imports and call sites ---'
rg -n -C 5 'java\.util\.stream\.Stream|deleteRepo\(' --glob '*.java' --glob '*.scala' common/workflow-core

printf '%s\n' '--- Java/tooling availability ---'
command -v java || true
java -version 2>&1 || true

Repository: sshiv012/texera

Length of output: 9816


🌐 Web query:

Oracle Java Files.walk API documentation stream must be closed try-with-resources

💡 Result:

Yes, the Stream returned by the Files.walk API must be closed using a try-with-resources statement or a similar control structure [1][2]. The official Oracle documentation explicitly states that Files.walk returns a stream that encapsulates one or more DirectoryStream objects [3]. Because these streams hold open file system resources (such as directory handles), they must be closed to ensure those resources are released promptly [1][3]. Failing to close the stream can lead to resource leaks and may eventually exhaust the operating system's file descriptor limits [4]. According to the API documentation, you should use the try-with-resources construct to ensure the stream's close method is invoked after operations are completed [1][2]. Example of correct usage: try (Stream stream = Files.walk(startPath)) { stream.filter(Files::isRegularFile).forEach(System.out::println); } catch (IOException e) { // Handle potential IO exceptions during stream opening or traversal } While most Java streams do not require manual closing, Streams backed by I/O channels—such as those returned by Files.walk or Files.lines—are important exceptions that necessitate this resource management [5].

Citations:


Restore try-with-resources for Files.walk.

Files.walk(directoryPath) holds open directory resources. Close the stream on normal and exceptional completion to prevent file-descriptor exhaustion during repeated repository deletions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/util/dataset/GitVersionControlLocalFileStorage.java`
around lines 81 - 84, Update the repository deletion flow around Files.walk in
GitVersionControlLocalFileStorage to use try-with-resources, ensuring the
returned stream is closed on both normal and exceptional completion while
preserving the reverse-order deletion behavior.

}

/**
Expand Down