Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

squid:S2095 - Resources should be closed #198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

georgekankava
Copy link

This pull request is focused on resolving occurrences of Sonar rule
squid:S2095 - Resources should be closed.
You can find more information about the issue here:
https://dev.eclipse.org/sonar/coding_rules#q=squid%3AS2095
Please let me know if you have any questions.
George Kankava

try(Stream<Path> stream = Files.list(logDir)) {
return stream.filter(path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS))
.sorted(Collections.reverseOrder());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We're returning a Stream here -- it is kind of important that we don't close it prematurely. The javadoc also notes that the caller is responsible for closing it, and most importantly, no (non-fatal) exception can occur that leaves the file stream open. The IOException can only occur during the initial Files.list, and if it does, then it handles that cleanup internally.

@tea-dragon
Copy link
Contributor

I made some notes on the code I am most familiar with, but from what I saw in other bits, there are some very reasonable changes. Certainly that AssetsResource class was definitely neglecting that FileInputStream. I'll see if I can get the respective authors to review the other changes, but you might end up having to make do with me again :)

Once again, we really appreciate the contribution. I hope my comments don't come off the wrong way.

@georgekankava
Copy link
Author

Hi Ian,

Thank you for the PRs review and sorry that it took some time for you to
add comments.
With this PR you can just let me know which portions should be reverted and
I will leave only necessary ones.
I am looking forward to create some more PRs, maybe more simple ones for
this time.

Regards,
George

On Wed, Feb 10, 2016 at 11:48 AM, Ian Barfield [email protected]
wrote:

I made some notes on the code I am most familiar with, but from what I saw
in other bits, there are some very reasonable changes. Certainly that
AssetsResource class was definitely neglecting that FileInputStream. I'll
see if I can get the respective authors to review the other changes, but
you might end up having to make do with me again :)

Once again, we really appreciate the contribution. I hope my comments
don't come off the wrong way.


Reply to this email directly or view it on GitHub
#198 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants