Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
1.1
-
None
-
None
Description
The fix revision 1134539 was aimed to remove resource leak bugs on the BufferedReader object "reader"(created in line 421) in the method "loadFile()", the BufferedReader object "reader" (created in line 1538) of the file "/maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/Verifier.java" , but it is incomplete.
There are some problems:
1. when "reader" is not created successfully at line 427 but the temp FileReader object is created successfully at line 427,the temp FileReader object will be leaked.
2. when "reader" is not created successfully at line 1541 but the temp FileReader object is created successfully at line 1541,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.
The problem still exists in the head revision. The buggy code is copied as bellows (the temp objects created at line 427 and 1541 needs to be closed in the finally clause):
416 public List loadFile( File file, boolean hasCommand )
throws VerificationException
{
List lines = new ArrayList();
BufferedReader reader = null;
if ( file.exists() )
{
try
{
427 reader = new BufferedReader( new FileReader( file ) );
String line = reader.readLine();
while ( line != null )
{
line = line.trim();
if ( !line.startsWith( "#" ) && line.length() != 0 )
{ lines.addAll( replaceArtifacts( line, hasCommand ) ); } line = reader.readLine();
}
reader.close();
}
catch ( FileNotFoundException e )
catch ( IOException e )
{ throw new VerificationException( e ); }
finally
{ 454 IOUtil.close( reader ); }}
return lines;
}
1535 private void displayLogFile()
{
System.out.println( "Log file contents:" );
BufferedReader reader = null;
try
{
1541 reader = new BufferedReader( new FileReader( new File( getBasedir(), getLogFileName
() ) ) );
String line = reader.readLine();
while ( line != null )
reader.close();
}
catch ( FileNotFoundException e )
catch ( IOException e )
{ System.err.println( "Error: " + e ); }finally
{ 1560 IOUtil.close( reader ); }}