-
Notifications
You must be signed in to change notification settings - Fork 265
Remove unnecessary InputStream.close
call
#1982
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
Conversation
The current code is correct. This change leaves the risk of not closing the input stream. |
What makes you say that, @snazy? Have you found a JDK that behaves that way? Oracle documents Looking at OpenJDK, the |
@eric-maynard you see that a) the |
What function calls? It's created inside a try-with-resources which is visible in the diff here.
That is what the try-with-resources is for |
try (Statement statement = connection.createStatement(); | ||
BufferedReader reader = | ||
new BufferedReader( | ||
new InputStreamReader(Objects.requireNonNull(scriptInputStream), UTF_8))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regardless of the .close()
call, I just realised that runWithinTransaction()
has re-tries... So if this code is called again, the reading of the scriptInputStream
will lead to invalid data. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, to fix that I think we need to go back to having two try-with-resources. Still, the extra close call can be removed. Just pushed a fix.
d3d22a4
to
27e648b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for the fix @eric-maynard ! It LGTM 👍
#1942 changed the way that the bootstrap init script is handled, but it added an extra
InputStream.close
call that shouldn't be needed after the BufferedReader here is closed. This PR removes that extra call.