You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Jason van Zyl (JIRA)" <ji...@codehaus.org> on 2014/05/18 16:02:10 UTC
[jira] (MPLUGINTESTING-20) An incomplete fix for the resource leak
bugs in TestUtils.java
[ https://jira.codehaus.org/browse/MPLUGINTESTING-20?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jason van Zyl closed MPLUGINTESTING-20.
---------------------------------------
Resolution: Won't Fix
> 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)