Hi all, David Daney wrote: > After thinking about it a bit more (and reading Sun's API reference), I > think that the exception should be thrown from getInputStream(). On any > 4??, 5?? response code getInputStream should throw an IOException. On > 404 it should the FileNotFoundException. Any time getInputStream() > throws an exception because of a 4?? or 5?? status code, > getErrorStream() must contain the response body if any. > > connect() should only throw an exception if there are socket level > IOExceptions. > > I will update PR 26081 to reflect my new understanding.
I can confirm this understanding and updated the PR. Its exactly as David states above with the additional special case that also a FileNotFoundException is thrown for HTTP code 410. The fileNotFound mauve test is updated to test the behaviour of connect, getInputStream, getErrorStream for a 404 case. I propose the following revised patch as fix. 2006-02-05 Wolfgang Baer <[EMAIL PROTECTED]> Fixes Bug #26081 * gnu/java/net/protocol/http/HTTPURLConnection.java: (isError): New helper method to see if response is an error. (connect): If error condition redirect responseSink to errorSink. (getInputStream): If error condition throw IOException, for the error codes 404 and 410 throw a FileNotFoundException. Wolfgang
Index: gnu/java/net/protocol/http/HTTPURLConnection.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java,v retrieving revision 1.17 diff -u -r1.17 HTTPURLConnection.java --- gnu/java/net/protocol/http/HTTPURLConnection.java 20 Jan 2006 22:15:58 -0000 1.17 +++ gnu/java/net/protocol/http/HTTPURLConnection.java 5 Feb 2006 17:15:03 -0000 @@ -349,11 +349,8 @@ { responseSink = response.getBody(); - if (response.getCode() == 404) - { - errorSink = responseSink; - throw new FileNotFoundException(url.toString()); - } + if (isError(response)) + errorSink = responseSink; } } while (retry); @@ -365,6 +362,12 @@ int sc = response.getCode(); return (sc != 304 && (sc / 100) == 3); } + + private static boolean isError(Response response) + { + int sc = response.getCodeClass(); + return (sc == 4 || sc == 5); + } /** * Returns a connection, from the pool if necessary. @@ -515,6 +526,17 @@ { throw new ProtocolException("doInput is false"); } + + if (isError(response)) + { + int code = response.getCode(); + if (code == 404 || code == 410) + throw new FileNotFoundException(url.toString()); + + throw new IOException("Server returned HTTP response code " + code + + " for URL " + url.toString()); + } + return responseSink; }