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

Catches IOException in DownloadUtils::isJenkinsAvailable #437

Merged
merged 2 commits into from
Jun 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,10 @@ public static boolean isJenkinsAvailable() {
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
logger.trace("Jenkins is available at {}", JENKINS_URL);
return true;
} else {
throw new ConnectException();
}
}
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

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

I had a closer look at what exceptions can occur for what reason:

  • MalformedURLException in case our static string is not a valid URL - should never happen, and is caught by Exception anyways
  • IOException can occur for multiple reasons (.openConnection(), .getResponseCode(), …)
  • Exception due to AutoClosable interface - we have to catch this

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you. Note that MalformedURLException is a child of IOException, so the first block will handle it actually. The catch(Exception) block is present exclusively due to the AutoCloseable object, and it'll be triggered only when HttpURLConnection::disconnect goes wrong (which itself throws IOException).

logger.warn("Could not connect to Jenkins at {}", JENKINS_URL);
logger.warn("Could not connect to Jenkins at {} - {}", JENKINS_URL, e.getMessage());
}
return false;
}
Expand Down