Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 64528 invoked from network); 20 Sep 2006 17:03:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Sep 2006 17:03:02 -0000 Received: (qmail 13755 invoked by uid 500); 20 Sep 2006 17:03:01 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 13430 invoked by uid 500); 20 Sep 2006 17:03:00 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 13419 invoked by uid 99); 20 Sep 2006 17:03:00 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Sep 2006 10:03:00 -0700 Authentication-Results: idunn.apache.osuosl.org header.from=xavier.hanin@gmail.com; domainkeys=good X-ASF-Spam-Status: No, hits=0.4 required=5.0 tests=DNS_FROM_RFC_ABUSE,HTML_60_70,HTML_MESSAGE,RCVD_BY_IP DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 Received: from [64.233.184.231] ([64.233.184.231:62632] helo=wr-out-0506.google.com) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id F9/A7-01963-F3471154 for ; Wed, 20 Sep 2006 10:02:57 -0700 Received: by wr-out-0506.google.com with SMTP id i11so2257wra for ; Wed, 20 Sep 2006 10:02:53 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=UpjI8jY1bxeAT751xH9kMWI9PqKk69k72obp8iVTZxe+S30Thn64scvSFL2bhrUSpAIYU6BJF5prm/o+Lj0v9/3DrPdHHACgmUsqNBlnDwI5X8NRq0QukgzZ/IvSbRSeO0ZX1CaHPlgmNKngxZNysmJIkN9VCeaKHnIn1nassTI= Received: by 10.90.78.1 with SMTP id a1mr6774538agb; Wed, 20 Sep 2006 10:02:53 -0700 (PDT) Received: by 10.90.72.14 with HTTP; Wed, 20 Sep 2006 10:02:52 -0700 (PDT) Message-ID: <635a05060609201002m566d73e4m4bbc75752073344c@mail.gmail.com> Date: Wed, 20 Sep 2006 10:02:52 -0700 From: "Xavier Hanin" To: "Ant Developers List" Subject: Re: svn commit: r448049 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java In-Reply-To: <20060920144502.60876.qmail@web55106.mail.re4.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_130732_30613745.1158771772153" References: <20060920144502.60876.qmail@web55106.mail.re4.yahoo.com> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_130732_30613745.1158771772153 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/20/06, Matt Benson wrote: > > --- Antoine Levy-Lambert wrote: > > > Hello Xavier, > > > > the patch is welcome, but I do not see the > > attachment ? maybe it > > comes from my email reader. > > Nor did I. :) This is weird, I see it in gmail... Is it using some fancy thing to attach files? Anyway, here is the patch in plain text: Index: src/main/org/apache/tools/ant/types/resources/URLResource.java =================================================================== --- src/main/org/apache/tools/ant/types/resources/URLResource.java (revision 448066) +++ src/main/org/apache/tools/ant/types/resources/URLResource.java (working copy) @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.net.MalformedURLException; @@ -145,6 +146,28 @@ * @return true if this resource exists. */ public synchronized boolean isExists() { + return isExists(true); + } + + /** + * Find out whether the URL exists, and close the connection + * opened to the URL if closeConnection is true. + * + * Note that this method does ensure that if: + * - the resource exists (if it returns true) + * - and if the current object is not a reference + * (isReference() returns false) + * - and if it was called with closeConnection to false, + * + * then the connection to the URL (stored in the conn + * private field) will be opened, and require to be closed + * by the caller. + * + * @param closeConnection true if the connection should be closed + * after the call, false if it should stay open. + * @return true if this resource exists. + */ + private synchronized boolean isExists(boolean closeConnection) { if (isReference()) { return ((Resource) getCheckedRef()).isExists(); } @@ -156,9 +179,14 @@ return true; } catch (IOException e) { return false; + } finally { + if (closeConnection) { + close(); + } } } + /** * Tells the modification time in milliseconds since 01.01.1970 . * @@ -169,10 +197,12 @@ if (isReference()) { return ((Resource) getCheckedRef()).getLastModified(); } - if (!isExists()) { + if (!isExists(false)) { return 0L; } try { + // note that this call to connect() is not necessary: + // isExists returned true and isReference returned false connect(); return conn.getLastModified(); } catch (IOException e) { @@ -177,6 +207,8 @@ return conn.getLastModified(); } catch (IOException e) { return 0L; + } finally { + close(); } } @@ -199,16 +231,18 @@ if (isReference()) { return ((Resource) getCheckedRef()).getSize(); } - if (!isExists()) { + if (!isExists(false)) { return 0L; } try { + // note that this call to connect() is not necessary: + // isExists returned true and isReference returned false connect(); - long contentlength = conn.getContentLength(); - close(); - return contentlength; + return conn.getContentLength(); } catch (IOException e) { return UNKNOWN_SIZE; + } finally { + close(); } } @@ -260,7 +294,7 @@ try { return conn.getInputStream(); } finally { - conn = null; + close(); } } @@ -280,7 +314,7 @@ try { return conn.getOutputStream(); } finally { - conn = null; + close(); } } @@ -304,7 +338,15 @@ } } - private void close() { + /** + * Closes the URL connection if: + * - it is opened (i.e. the field conn is not null) + * - this type of URLConnection supports some sort of close mechanism + * + * This method ensures the field conn will be null after the call. + * + */ + private synchronized void close() { if (conn != null) { try { if (conn instanceof JarURLConnection) { @@ -312,6 +354,8 @@ JarFile jf = juc.getJarFile(); jf.close(); jf = null; + } else if (conn instanceof HttpURLConnection) { + ((HttpURLConnection) conn).disconnect(); } } catch (IOException exc) { @@ -327,7 +371,7 @@ */ protected void finalize() throws Throwable { close(); - conn = null; + conn = null; // Note: already done by close(); super.finalize(); } ------=_Part_130732_30613745.1158771772153--