Guangtai Liang created MVERIFIER-12:
---------------------------------------
Summary: An incomplete fix for the resource leak bugs in
Verifier.java
Key: MVERIFIER-12
URL: https://jira.codehaus.org/browse/MVERIFIER-12
Project: Maven 2.x Verifier Plugin
Issue Type: Bug
Affects Versions: 1.4
Reporter: Guangtai Liang
Priority: Critical
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 )
{
throw new VerificationException( 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 )
{
System.out.println( line );
line = reader.readLine();
}
reader.close();
}
catch ( FileNotFoundException e )
{
System.err.println( "Error: " + e );
}
catch ( IOException e )
{
System.err.println( "Error: " + e );
}
finally
{
1560 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