Close the stream parse(Path) and parse(URL) open on construction failure - #630
Conversation
|
Hello @rootvector2 This one feels wrong to me. In git master, please find the new
It is the responsibility of the code that allocates a resource to close it. If the the resource is managed with a try-with-resources block (see the new tests), the resource is closed for this use case. I switched the PR to draft for this reason. Please let me know how you see it. TY! |
52b48e3 to
c37b2b7
Compare
|
Agreed on caller-supplied readers; the new The case I was after is narrower: |
garydgregory
left a comment
There was a problem hiding this comment.
@rootvector2 On macOS, the test testParsePathClosesInputStreamWhenHeaderIsInvalid passes without changes to main, so it doesn't show anything to fix.
|
@rootvector2 |
|
@rootvector2 ping 🔔 |
The temp file variant only asserted the throw; deleting an open file succeeds on POSIX, so the test passed without the fix. Route Files.newInputStream through a mocked FileSystemProvider so the test records the close and fails when parse(Path) leaks the stream.
c37b2b7 to
3e74b59
Compare
|
Right, the temp file test showed nothing: deleting an open file succeeds on POSIX, so the only observable effect was the throw. Reworked the PR into just a better |
parse(Path)andparse(URL)allocate the input stream themselves and theCSVParserconstructor throws before the caller gets a parser, so the stream the library opened leaked. The fix is in master now (f1bf8cd), so this PR is down to the betterPathtest suggested in review.The temp file test only asserted the throw; deleting an open file succeeds on POSIX, so it passed without the fix.
Files.newInputStream(path)dispatches throughpath.getFileSystem().provider(), so the test now mocks that chain and handsparse(Path)a close-recording stream, mirroring the URL test. It fails on master with the close inparse(IOSupplier)removed and passes as is, on any platform.Full default
mvnbuild is green.mvn; that'smvnon the command line by itself.