Description
The fix revision 730089 was aimed to remove an resource leak bug on the OutputStreamWriter object "writer" (created in line 188) in the method "writeNonHtml()" of the file "/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java" ,
but it is incomplete.
There are some problems:
1. when "writer" is not created successfully at line 189 but the FileOutputStream object "tStream" is created successfully at line 188,"tStream" 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.
Although a later fix (rev935316) tried to fix it, the problem still exists in the head revision. The buggy code is copied as bellows (the object "tStream" needs to be closed at line 220):
void writeNonHtml( CPD cpd )
throws MavenReportException
{
Renderer r = createRenderer();
if ( r == null )
{ return; } String buffer = r.render( cpd.getMatches() );
Writer writer = null;
try
catch ( IOException ioe )
{ throw new MavenReportException( ioe.getMessage(), ioe ); }finally
{ 235 IOUtil.close( writer ); }}