changeset 8100:64d2b6d3a2a3 8u40-b07

RT-36449: [WebView] URLLoader throws an exception on 401 HTTP error with no body Reviewed-by: kcr, lepopov
author ant <anton.tarasov@oracle.com>
date Mon, 22 Sep 2014 10:53:05 +0400
parents 8a674e9f9438
children 3104530d2374 8030031af819 6719035236ad
files modules/web/src/main/java/com/sun/webkit/network/URLLoader.java
diffstat 1 files changed, 43 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/modules/web/src/main/java/com/sun/webkit/network/URLLoader.java	Fri Sep 19 14:26:45 2014 -0400
+++ b/modules/web/src/main/java/com/sun/webkit/network/URLLoader.java	Mon Sep 22 10:53:05 2014 +0400
@@ -487,8 +487,17 @@
             return null;
         }
 
-        InputStream inputStream = errorStream == null
+        InputStream inputStream = null;
+        try {
+            inputStream = errorStream == null
                 ? c.getInputStream() : errorStream;
+        } catch (IOException e) {
+            if (logger.isLoggable(Level.FINE)) {
+                logger.log(Level.FINE, String.format("Exception caught: [%s], %s",
+                    e.getClass().getSimpleName(),
+                    e.getMessage()));
+            }
+        }
         String encoding = c.getContentEncoding();
         if ("gzip".equalsIgnoreCase(encoding)) {
             inputStream = new GZIPInputStream(inputStream);
@@ -500,42 +509,44 @@
                 byteBufferPool.newAllocator(MAX_BUF_COUNT);
         ByteBuffer byteBuffer = null;
         try {
-            // 8192 is the default size of a BufferedInputStream used in
-            // most URLConnections, by using the same size, we avoid quite
-            // a few System.arrayCopy() calls
-            byte[] buffer = new byte[8192];
-            while (!canceled) {
-                int count;
-                try {
-                    count = inputStream.read(buffer);
-                } catch (EOFException ex) {
-                    // can be thrown by GZIPInputStream signaling
-                    // the end of the stream
-                    count = -1;
-                }
+            if (inputStream != null) {
+                // 8192 is the default size of a BufferedInputStream used in
+                // most URLConnections, by using the same size, we avoid quite
+                // a few System.arrayCopy() calls
+                byte[] buffer = new byte[8192];
+                while (!canceled) {
+                    int count;
+                    try {
+                        count = inputStream.read(buffer);
+                    } catch (EOFException ex) {
+                        // can be thrown by GZIPInputStream signaling
+                        // the end of the stream
+                        count = -1;
+                    }
 
-                if (count == -1) {
-                    break;
-                }
+                    if (count == -1) {
+                        break;
+                    }
 
-                if (byteBuffer == null) {
-                    byteBuffer = allocator.allocate();
-                }
+                    if (byteBuffer == null) {
+                        byteBuffer = allocator.allocate();
+                    }
 
-                int remaining = byteBuffer.remaining();
-                if (count < remaining) {
-                    byteBuffer.put(buffer, 0, count);
-                } else {
-                    byteBuffer.put(buffer, 0, remaining);
+                    int remaining = byteBuffer.remaining();
+                    if (count < remaining) {
+                        byteBuffer.put(buffer, 0, count);
+                    } else {
+                        byteBuffer.put(buffer, 0, remaining);
 
-                    byteBuffer.flip();
-                    didReceiveData(byteBuffer, allocator);
-                    byteBuffer = null;
+                        byteBuffer.flip();
+                        didReceiveData(byteBuffer, allocator);
+                        byteBuffer = null;
 
-                    int outstanding = count - remaining;
-                    if (outstanding > 0) {
-                        byteBuffer = allocator.allocate();
-                        byteBuffer.put(buffer, remaining, outstanding);
+                        int outstanding = count - remaining;
+                        if (outstanding > 0) {
+                            byteBuffer = allocator.allocate();
+                            byteBuffer.put(buffer, remaining, outstanding);
+                        }
                     }
                 }
             }