]> source.dussan.org Git - jgit.git/commitdiff
Check connection's error stream before reading from it 55/5255/3
authorKevin Sawicki <kevin@github.com>
Tue, 6 Mar 2012 01:22:22 +0000 (17:22 -0800)
committerKevin Sawicki <kevin@github.com>
Tue, 6 Mar 2012 01:22:22 +0000 (17:22 -0800)
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

org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java

index 0430b5fdca47ea6bd222b730b053263d79bc91c6..90378344d6de30514f5c1a28a6213e871c70bfc2 100644 (file)
@@ -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)