squid:S2095 - Resources should be closed#198
squid:S2095 - Resources should be closed#198georgekankava wants to merge 1 commit intoaddthis:masterfrom
Conversation
| try(Stream<Path> stream = Files.list(logDir)) { | ||
| return stream.filter(path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS)) | ||
| .sorted(Collections.reverseOrder()); | ||
| } |
There was a problem hiding this comment.
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.
|
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 Once again, we really appreciate the contribution. I hope my comments don't come off the wrong way. |
|
Hi Ian, Thank you for the PRs review and sorry that it took some time for you to Regards, On Wed, Feb 10, 2016 at 11:48 AM, Ian Barfield notifications@github.com
|
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