I'm committing the attached patch which fixes a couple
of issues with our implementation of java.net.HttpURLConnection:

* Fixes a null pointer exception thrown in connect()
  for 304 responses.
* Fixes an invalid exception thrown on 404 return codes.
* Prevents attempts to read a non-existant body for 304
responses.  This caused a long unnecessary pause in
the connect() method.

Changelog:

2005-05-26  Andrew John Hughes  <[EMAIL PROTECTED]>

        * gnu/java/net/protocol/http/HTTPURLConnection.java:
        (connect()): Fixed a null pointer exception with 304
        responses and an inappropriate exception with 404s.
        * gnu/java/net/protocol/http/Request.java:
        (readResponse(java.io.LineInputStream)): Fixed a
        fruitless attempt to read the non-existant body
        of a 304 response.
-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

No software patents in Europe -- http://nosoftwarepatents.com

"Value your freedom, or you will lose it, teaches history. 
`Don't bother us with politics' respond those who don't want to learn." 
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: gnu/java/net/protocol/http/HTTPURLConnection.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java,v
retrieving revision 1.8
diff -u -3 -p -u -r1.8 HTTPURLConnection.java
--- gnu/java/net/protocol/http/HTTPURLConnection.java   27 Apr 2005 08:55:56 
-0000      1.8
+++ gnu/java/net/protocol/http/HTTPURLConnection.java   26 May 2005 16:39:57 
-0000
@@ -233,82 +233,82 @@ public class HTTPURLConnection
           {
             // Follow redirect
             String location = response.getHeader("Location");
-            String connectionUri = connection.getURI();
-            int start = connectionUri.length();
-            if (location.startsWith(connectionUri) &&
-                location.charAt(start) == '/')
-              {
-                file = location.substring(start);
-                retry = true;
-              }
-            else if (location.startsWith("http:"))
-              {
-                connection.close();
-                connection = null;
-                secure = false;
-                start = 7;
-                int end = location.indexOf('/', start);
-                host = location.substring(start, end);
-                int ci = host.lastIndexOf(':');
-                if (ci != -1)
-                  {
-                    port = Integer.parseInt(host.substring (ci + 1));
-                    host = host.substring(0, ci);
-                  }
-                else
-                  {
-                    port = HTTPConnection.HTTP_PORT;
-                  }
-                file = location.substring(end);
-                retry = true;
-              }
-            else if (location.startsWith("https:"))
-              {
-                connection.close();
-                connection = null;
-                secure = true;
-                start = 8;
-                int end = location.indexOf('/', start);
-                host = location.substring(start, end);
-                int ci = host.lastIndexOf(':');
-                if (ci != -1)
-                  {
-                    port = Integer.parseInt(host.substring (ci + 1));
-                    host = host.substring(0, ci);
-                  }
-                else
-                  {
-                    port = HTTPConnection.HTTPS_PORT;
-                  }
-                file = location.substring(end);
-                retry = true;
-              }
-           else if (location.length() > 0)
+           if (location != null)
              {
-               // Malformed absolute URI, treat as file part of URI
-               if (location.charAt(0) == '/')
+               String connectionUri = connection.getURI();
+               int start = connectionUri.length();
+               if (location.startsWith(connectionUri) &&
+                   location.charAt(start) == '/')
+                 {
+                   file = location.substring(start);
+                   retry = true;
+                 }
+               else if (location.startsWith("http:"))
+                 {
+                   connection.close();
+                   connection = null;
+                   secure = false;
+                   start = 7;
+                   int end = location.indexOf('/', start);
+                   host = location.substring(start, end);
+                   int ci = host.lastIndexOf(':');
+                   if (ci != -1)
+                     {
+                       port = Integer.parseInt(host.substring (ci + 1));
+                       host = host.substring(0, ci);
+                     }
+                   else
+                     {
+                       port = HTTPConnection.HTTP_PORT;
+                     }
+                   file = location.substring(end);
+                   retry = true;
+                 }
+               else if (location.startsWith("https:"))
                  {
-                   // Absolute path
-                   file = location;
+                   connection.close();
+                   connection = null;
+                   secure = true;
+                   start = 8;
+                   int end = location.indexOf('/', start);
+                   host = location.substring(start, end);
+                   int ci = host.lastIndexOf(':');
+                   if (ci != -1)
+                     {
+                       port = Integer.parseInt(host.substring (ci + 1));
+                       host = host.substring(0, ci);
+                     }
+                   else
+                     {
+                       port = HTTPConnection.HTTPS_PORT;
+                     }
+                   file = location.substring(end);
+                   retry = true;
                  }
-               else
+               else if (location.length() > 0)
                  {
-                   // Relative path
-                   int lsi = file.lastIndexOf('/');
-                   file = (lsi == -1) ? "/" : file.substring(0, lsi + 1);
+                   // Malformed absolute URI, treat as file part of URI
+                   if (location.charAt(0) == '/')
+                     {
+                       // Absolute path
+                       file = location;
+                     }
+                   else
+                     {
+                       // Relative path
+                       int lsi = file.lastIndexOf('/');
+                       file = (lsi == -1) ? "/" : file.substring(0, lsi + 1);
                    file += location;
+                     }
+                   retry = true;
                  }
-               retry = true;
              }
           }
         else
           {
             responseSink = new ByteArrayInputStream(reader.toByteArray ());
             if (response.getCode() == 404)
-              {
-                errorSink = responseSink;
-                throw new FileNotFoundException(url.toString());
-              }
+             errorSink = responseSink;
           }
       }
     while (retry);
Index: gnu/java/net/protocol/http/Request.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/net/protocol/http/Request.java,v
retrieving revision 1.3
diff -u -3 -p -u -r1.3 Request.java
--- gnu/java/net/protocol/http/Request.java     2 Mar 2005 17:29:09 -0000       
1.3
+++ gnu/java/net/protocol/http/Request.java     26 May 2005 16:39:57 -0000
@@ -448,6 +448,7 @@ public class Request
       {
       case 204:
       case 205:
+      case 304:
         break;
       default:
         // Does response body reader want body?

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to