Skip to content

Commit

Permalink
Fix possible NPE in downloader
Browse files Browse the repository at this point in the history
Fixes bazelbuild#2470.

--
PiperOrigin-RevId: 146388739
MOS_MIGRATED_REVID=146388739
  • Loading branch information
kchodorow authored and meteorcloudy committed Feb 3, 2017
1 parent 41aa372 commit ffe3c89
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ URLConnection connect(
// The read timeout is always large because it stays in effect after this method.
connection.setReadTimeout(READ_TIMEOUT_MS);
// Java tries to abstract HTTP error responses for us. We don't want that. So we're going
// to try and undo any IOException that doesn't appepar to be a legitimate I/O exception.
// to try and undo any IOException that doesn't appear to be a legitimate I/O exception.
int code;
try {
connection.connect();
Expand All @@ -121,6 +121,12 @@ URLConnection connect(
// This will happen if the user does something like specify a port greater than 2^16-1.
throw new UnrecoverableHttpException(e.getMessage());
} catch (IOException e) {
// I'm not sure in what cases this happens, but IOException can be thrown with a null
// message.
if (e.getMessage() == null) {
throw new UnrecoverableHttpException(
"Failed to even get an error message from " + url);
}
if (!e.getMessage().startsWith("Server returned")) {
throw e;
}
Expand Down

0 comments on commit ffe3c89

Please sign in to comment.