aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki <kevin@github.com>2012-03-05 17:22:22 -0800
committerKevin Sawicki <kevin@github.com>2012-03-05 17:22:22 -0800
commit2c6187697c700654adc193d040e803a5438400f8 (patch)
tree71d13be2cdb153166310bbab57b3e4c0fcf84dea
parenteedd77a97b3eb5c404ac8464ea3a59498a121c72 (diff)
downloadjgit-2c6187697c700654adc193d040e803a5438400f8.tar.gz
jgit-2c6187697c700654adc193d040e803a5438400f8.zip
Check connection's error stream before reading from it
HttpURLConnection.getErrorStream can return null which is currently not guarded against and will throw an NPE preventing the actual error response code from bubbling up. Change-Id: I04fb8dbda16b7df3b82fc579088a303b2fd21e87
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java6
1 files changed, 5 insertions, 1 deletions
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 0430b5fdca..90378344d6 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 @@ public class AmazonS3 {
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)