[ 
https://jira.codehaus.org/browse/MPLUGINTESTING-20?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=346666#comment-346666
 ] 

Jason van Zyl commented on MPLUGINTESTING-20:
---------------------------------------------

All the testing tools have been deprecated and maven-shared is not used in the 
harness proper.

> An incomplete fix for the resource leak bugs in TestUtils.java
> --------------------------------------------------------------
>
>                 Key: MPLUGINTESTING-20
>                 URL: https://jira.codehaus.org/browse/MPLUGINTESTING-20
>             Project: Maven Plugin Testing
>          Issue Type: Bug
>            Reporter: Guangtai Liang
>            Priority: Critical
>   Original Estimate: 10 minutes
>  Remaining Estimate: 10 minutes
>
> The fix revision 1085807 was aimed to remove resource leak bugs on the 
> BufferedReader object "reader" (created in line 79) in the method 
> "readFile"of the file "/maven/plugin-
> testing/trunk/maven-test-tools/src/main/java/org/apache/maven/shared/tools/easymock/TestUtils.java"
>  , but it is incomplete.
> There are some problems: 
> 1. when "reader" isn't created successfully but the temp FileReader object is 
> created successfully, the temp FileReader object will be leaked. 
> The best way to close such resource objects is putting such close operations 
> for all resource objects in the finaly block of a try-catch-finally structure 
> and then putting all other code in a try block.
> The problem still exists in the head revision. The buggy code is copied as 
> bellows:
>  public static String readFile( File file )
>         throws IOException
>     {
>         StringBuffer buffer = new StringBuffer();
>         BufferedReader reader = null;
>         try
>         {
> 79          reader = new BufferedReader( new FileReader( file ) );
>             String line = null;
>             while ( ( line = reader.readLine() ) != null )
>             {
>                 if ( buffer.length() > 0 )
>                 {
>                     buffer.append( '\n' );
>                 }
>                 buffer.append( line );
>             }
>             return buffer.toString();
>         }
>         finally
>         {
> 96          IOUtil.close( reader );
>         }
>     }



--
This message was sent by Atlassian JIRA
(v6.1.6#6162)

Reply via email to