Skip to content
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

Convert various try blocks to try-with-resources #385

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

Conversation

tim-hoffman
Copy link
Contributor

No description provided.

if (is != null) {
is.close();
return con.getURL();
try (InputStream is = con.getInputStream()) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The try-with-resources will automatically close the stream just prior to the return. Thus, to my knowledge, the only differences between these versions are (1) closing after the getURL call vs before which should be fine from what I can tell and (2) the new version ensure the stream is closed no matter what where the old version could allow a scenario where the stream is not closed if the current thread is interrupted by an asynchronous exception before the close method is called.

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

Successfully merging this pull request may close these issues.

None yet

2 participants