Guangtai Liang created MPTEST-79: ------------------------------------ Summary: An incomplete fix for the resource leak bugs in TestUtils.java Key: MPTEST-79 URL: https://jira.codehaus.org/browse/MPTEST-79 Project: Maven 1.x Test Plugin Issue Type: Bug Affects Versions: 1.8.3 Reporter: Guangtai Liang Priority: Critical
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 is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira