ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <peter.kitt.rei...@gmail.com>
Subject Re: svn commit: r518896 - /ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
Date Fri, 16 Mar 2007 10:07:33 GMT
Please rollback this change.
It is a misuse of reflection.

Peter

On 3/16/07, kevj@apache.org <kevj@apache.org> wrote:
> Author: kevj
> Date: Fri Mar 16 02:14:06 2007
> New Revision: 518896
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=518896
> Log:
> -use reflection to avoid duplicated code for close (various things that can be closed)
>
> Modified:
>     ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
>
> Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
> URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java?view=diff&rev=518896&r1=518895&r2=518896
> ==============================================================================
> --- ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java (original)
> +++ ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java Fri Mar 16 02:14:06
2007
> @@ -22,10 +22,11 @@
>  import java.io.IOException;
>  import java.io.InputStream;
>  import java.io.InputStreamReader;
> +import java.io.OutputStream;
>  import java.io.Reader;
>  import java.io.UnsupportedEncodingException;
>  import java.io.Writer;
> -import java.io.OutputStream;
> +import java.lang.reflect.Method;
>  import java.net.MalformedURLException;
>  import java.net.URL;
>  import java.text.DecimalFormat;
> @@ -37,13 +38,14 @@
>  import java.util.Stack;
>  import java.util.StringTokenizer;
>  import java.util.Vector;
> +
>  import org.apache.tools.ant.BuildException;
>  import org.apache.tools.ant.PathTokenizer;
>  import org.apache.tools.ant.Project;
> +import org.apache.tools.ant.launch.Locator;
>  import org.apache.tools.ant.taskdefs.condition.Os;
>  import org.apache.tools.ant.types.FilterSetCollection;
>  import org.apache.tools.ant.types.resources.FileResource;
> -import org.apache.tools.ant.launch.Locator;
>
>  /**
>   * This class also encapsulates methods which allow Files to be
> @@ -1299,35 +1301,34 @@
>          return isUpToDate(sourceTime, destTime, getFileTimestampGranularity());
>      }
>
> +
> +    private static void closeQuietly(Object o) {
> +        try {
> +            if(ReflectUtil.respondsTo(o, "close")) {
> +                ReflectUtil.invoke(o, "close");
> +            }
> +        } catch(Exception e) {
> +            //ignore
> +        }
> +    }
> +
>      /**
>       * Close a Writer without throwing any exception if something went wrong.
>       * Do not attempt to close it if the argument is null.
>       * @param device output writer, can be null.
>       */
>      public static void close(Writer device) {
> -        if (device != null) {
> -            try {
> -                device.close();
> -            } catch (IOException ioex) {
> -                //ignore
> -            }
> -        }
> +        closeQuietly(device);
>      }
>
>      /**
> -     * Close a stream without throwing any exception if something went wrong.
> +     * Close a Reader without throwing any exception if something went wrong.
>       * Do not attempt to close it if the argument is null.
>       *
>       * @param device Reader, can be null.
>       */
>      public static void close(Reader device) {
> -        if (device != null) {
> -            try {
> -                device.close();
> -            } catch (IOException ioex) {
> -                //ignore
> -            }
> -        }
> +        closeQuietly(device);
>      }
>
>      /**
> @@ -1337,13 +1338,7 @@
>       * @param device stream, can be null.
>       */
>      public static void close(OutputStream device) {
> -        if (device != null) {
> -            try {
> -                device.close();
> -            } catch (IOException ioex) {
> -                //ignore
> -            }
> -        }
> +        closeQuietly(device);
>      }
>
>      /**
> @@ -1353,13 +1348,7 @@
>       * @param device stream, can be null.
>       */
>      public static void close(InputStream device) {
> -        if (device != null) {
> -            try {
> -                device.close();
> -            } catch (IOException ioex) {
> -                //ignore
> -            }
> -        }
> +        closeQuietly(device);
>      }
>
>      /**
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message