Description
The fix revision 729532 was aimed to remove an resource leak bug on the BufferedReader object "in" (created in line 240) in the method "readFile()" of the file "/maven/plugins/trunk/maven-pmd-
plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java" , but it is incomplete.
There are some problems:
1. when "in" is not created successfully but the temp FileReader object is created successfully at line 240,the temp FileReader object will be leaked.
The best way to close such resource objects is putting such close operations in the finaly block of a try-catch-finally structure.
The problem still exists in the head revision. The buggy code is copied as bellows:
private String readFile( File file )
throws IOException
{
String strTmp;
StringBuffer str = new StringBuffer( (int) file.length() );
246 BufferedReader in = new BufferedReader( new FileReader( file ) );
while ( ( strTmp = in.readLine() ) != null )
{ str.append( ' ' ); str.append( strTmp ); }253 in.close();
return str.toString();
}