ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fernando Padilla <f...@interdimensions.com>
Subject Re: odd code in Get.java
Date Mon, 26 Mar 2001 21:15:01 GMT

I have been away on vacation so I apologize for the late response.

The reason for the catch and retry is that there is a bug/feature with the
URLConnection class in java.  What happens is that if there was a bad
connection, ( like HTTP 404 response.. ), it will throw an IOException on
first attempt to get the IntputStream.  But on second attempt, you will
get it ( such as actually getting the HTML response for a 404 error.. ).

try it and you will see this behavior.  I'm sorry I do not have a url to
the official description of this (from sun), but I believe it does exist.

fern



On Mon, 19 Mar 2001, Steve Loughran wrote:

> While am at it, there is a bit of code in Get.java that I am debating
> whether it makes sense to retain
> 
> If you look at line 148 onwards, you see that the code makes a number of
> attempts to connect to the server before bailing out, eating any IO
> exceptions and retrying. Then there is some followon code which recognises
> that the three attempts failed, and generates a new exception (losing any IO
> exception information in the process)
> 
>             for( int i=0; i< 3 ; i++ ) {
>                 try {
>                     is = connection.getInputStream();
>                     break;
>                 } catch( IOException ex ) {
>                     log( "Error opening connection " + ex );
>                 }
>             }
>             if( is==null ) {
>                 log( "Can't get " + source + " to " + dest);
>                 if(ignoreErrors)
>                     return;
>                 throw new BuildException( "Can't get " + source + " to " +
> dest,
>                                           location);
>             }
> 
> I can only infer that this code is there because somehow the
> connection.getInputStream() call was failing on the first couple of
> attempts. I've never encountered this myself (unless the far end isnt
> actually there).
> 
> Should this code be retained in a rework of Get.java?
> 
> If so, should the number of retries be configurable, and a sleep period
> added between each attempt? That way if the server really is missing then we
> can survive a reboot of the server or some upstream node.
> 
> Personally, I am just as happy dropping it, but people with less reliable
> network connections may want it kept and configurable. If it is retained I
> will save the IOException for use in constructing the BuildException.
> 
> -Steve
> 
> 
> 


Mime
View raw message