Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close Files streams using try-with-resources #840

Merged
merged 2 commits into from
Oct 4, 2023

Conversation

mattirn
Copy link
Collaborator

@mattirn mattirn commented Mar 31, 2023

No description provided.

.map(Path::toString)
.forEach(engine.classLoader::addClasspath);
try (Stream<Path> pathStream =
Files.walk(Paths.get(arg)).filter(matcher::matches)) {

This comment was marked as off-topic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sonatype-lift ignoreall

Copy link

Choose a reason for hiding this comment

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

The ignoreall command is active on this PR, all the existing Lift issues are ignored.

@gnodet
Copy link
Member

gnodet commented Mar 31, 2023

@sonatype-lift ignoreall

(path, f) -> pathMatcher.matches(path))
.forEach(syntaxFiles::add);
try (Stream<Path> pathStream = Files.find(
Paths.get(new File(parameter).getParent()),
Copy link

Choose a reason for hiding this comment

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

5% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;) reads a file whose location might be specified by user input


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sonatype-lift ignoreall

Copy link

Choose a reason for hiding this comment

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

The ignoreall command is active on this PR, all the existing Lift issues are ignored.

(path, f) -> pathMatcher.matches(path))
.forEach(p -> out.println(p.getFileName()));
try (Stream<Path> pathStream = Files.find(
Paths.get(new File(parameter).getParent()),
Copy link

Choose a reason for hiding this comment

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

5% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;) reads a file whose location might be specified by user input

❗❗ 2 similar findings have been found in this PR

🔎 Expand here to view all instances of this finding
File Path Line Number
builtins/src/main/java/org/jline/builtins/Source.java 51
builtins/src/main/java/org/jline/builtins/Commands.java 1682

Visit the Lift Web Console to find more details in your report.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@gnodet
Copy link
Member

gnodet commented Aug 3, 2023

@mattirn I pushed a subsequent commit that replaces Files.find(x, Integer.MAX_VALUE, (s, f) -> matcher.matches(s)) with Files.walk(x).filter(matcher::matches).
Can you have a look ?

(path, f) -> pathMatcher.matches(path))
.findFirst()
.ifPresent(path -> syntaxFiles.add(0, path));
try (Stream<Path> pathStream = Files.walk(Paths.get(new File(parameter).getParent()))) {
Copy link

Choose a reason for hiding this comment

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

8% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;) reads a file whose location might be specified by user input

❗❗ 4 similar findings have been found in this PR

🔎 Expand here to view all instances of this finding
File Path Line Number
builtins/src/main/java/org/jline/builtins/Commands.java 1681
console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java 241
groovy/src/main/java/org/jline/script/GroovyCommand.java 292
builtins/src/main/java/org/jline/builtins/Commands.java 1681

Visit the Lift Web Console to find more details in your report.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

@mattirn
Copy link
Collaborator Author

mattirn commented Aug 9, 2023

@mattirn I pushed a subsequent commit that replaces Files.find(x, Integer.MAX_VALUE, (s, f) -> matcher.matches(s)) with Files.walk(x).filter(matcher::matches).
Can you have a look ?

@gnodet, looks good to me, thanks!

Copy link
Member

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

LGTM

groovy/src/main/java/org/jline/script/GroovyEngine.java Outdated Show resolved Hide resolved
groovy/src/main/java/org/jline/script/GroovyEngine.java Outdated Show resolved Hide resolved
@gnodet gnodet added this to the 3.24.0 milestone Oct 4, 2023
@gnodet gnodet merged commit 2f02183 into jline:master Oct 4, 2023
8 checks passed
@gnodet gnodet mentioned this pull request Oct 25, 2023
@mattirn mattirn deleted the stream-resouce-leak branch May 7, 2024 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants