cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vadim Gritsenko <va...@reverycodes.com>
Subject Re: svn commit: r366702 - in /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean: CocoonBean.java helpers/BeanConfigurator.java
Date Mon, 09 Jan 2006 15:17:14 GMT
antonio@apache.org wrote:
> Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonBean.java
> URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonBean.java?rev=366702&r1=366701&r2=366702&view=diff
> ==============================================================================
> --- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonBean.java (original)
> +++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonBean.java Sat
Jan  7 03:11:59 2006
>       */ 
>      private void readChecksumFile() throws Exception {
>          checksums = new HashMap();
> -        
> +        InputStream is = null;
> +        InputStreamReader isr = null;
> +        BufferedReader reader = null;
>          try {
>              Source checksumSource = sourceResolver.resolveURI(checksumsURI);
> -            BufferedReader reader = new BufferedReader(new InputStreamReader(checksumSource.getInputStream()));
> +            is = checksumSource.getInputStream();
> +            isr = new InputStreamReader(is);
> +            reader = new BufferedReader(isr);
>              String line;

<snip/>

>          } catch (SourceNotFoundException e) {
>              // return leaving checksums map empty
> +        } finally {
> +            if (reader != null) reader.close();
> +            if (isr != null) isr.close();
> +            if (is != null) is.close();
>          }
>      }

In situations like these, it is needed to close only reader, and closing isr and 
is has no sense at all. Please change to:

 > +        BufferedReader reader = null;
 >          try {
 >              Source checksumSource = sourceResolver.resolveURI(checksumsURI);
 > -            BufferedReader reader = new BufferedReader(new 
InputStreamReader(checksumSource.getInputStream()));
 >              String line;

<snip/>

 >          } catch (SourceNotFoundException e) {
 >              // return leaving checksums map empty
 > +        } finally {
 > +            if (reader != null) reader.close();
 >          }
 >      }

It is shorter, more readable, and does exactly the same.

Vadim

Mime
View raw message