Skip to content

Conversation

@hansenmc
Copy link
Contributor

Changed test for instanceof File to instanceof FileInputStream, so that
FileInputStreams will be closed.

Currently, this condition always fails and FileInputStreams are not
being closed when they should.

Changed test for instanceof from File to FileInputStream, so that
FileInputStreams will be closed.

Currently, this condition always fails and FileInputStreams are not
being closed.
@sammefford
Copy link
Contributor

@hansenmc I can't merge this without a unit test. I'll keep it so I can add a unit test when I get time. If you beat me to it, I'll be able to merge this.

the try-with-resources immediately preceding will ensure that all
InputStream objects are closed. Above that, a new FileInputStream is
created and assigned to the `content`, so no need to test for File and
close the FileInputStream.
@hansenmc
Copy link
Contributor Author

Actually, now that I take a closer look - the close() is unnecessary and that code block can be removed altogether. So, rather than a possible memory leak, it's unnecessary, closing the already closed FileInputStream.

If a File is passed in, then content is assigned as a new FileInputStream(), which then uses try-with-resources to read with an InputStreamReader, which will automatically invoke close().

So, whether a File or FileInputStream were sent in, they should always be read with the InputStreamReader and automatically closed.

I added a specific test to demonstrate that FileInputStream is indeed being closed automatically and removed that code block. I couldn't think of a way to demonstrate/test File, but if you look at that section of code, it should be apparent.

@sammefford
Copy link
Contributor

Analysis looks perfect to me. merging. Thanks!

@sammefford sammefford merged commit bb97e93 into marklogic:develop Apr 27, 2017
@ehennum ehennum removed the verify label Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants