Merge "Check connection's error stream before reading from it"
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
index 0430b5f..9037834 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
@@ -512,10 +512,14 @@ private IOException error(final String action, final String key,
final HttpURLConnection c) throws IOException {
final IOException err = new IOException(MessageFormat.format(JGitText.get().amazonS3ActionFailed
, action, key, HttpSupport.response(c), c.getResponseMessage()));
+ final InputStream errorStream = c.getErrorStream();
+ if (errorStream == null)
+ return err;
+
final ByteArrayOutputStream b = new ByteArrayOutputStream();
byte[] buf = new byte[2048];
for (;;) {
- final int n = c.getErrorStream().read(buf);
+ final int n = errorStream.read(buf);
if (n < 0)
break;
if (n > 0)