You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Andreas Dangel (JIRA)" <ji...@codehaus.org> on 2012/05/18 14:54:02 UTC
[jira] (MPMD-146) An incomplete fix for the resource leak bugs in
CpdReport.java
[ https://jira.codehaus.org/browse/MPMD-146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andreas Dangel updated MPMD-146:
--------------------------------
Attachment: 0001-Close-the-fileoutputstream-in-the-finally-block-too..patch
Simple fix - closes the file output stream in the finally block, too.
> An incomplete fix for the resource leak bugs in CpdReport.java
> --------------------------------------------------------------
>
> Key: MPMD-146
> URL: https://jira.codehaus.org/browse/MPMD-146
> Project: Maven 2.x PMD Plugin
> Issue Type: Bug
> Components: PMD
> Affects Versions: 2.8
> Reporter: Guangtai Liang
> Priority: Critical
> Attachments: 0001-Close-the-fileoutputstream-in-the-finally-block-too..patch
>
>
> 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
> {
> targetDirectory.mkdirs();
> File targetFile = new File( targetDirectory, "cpd." + format );
> 220 FileOutputStream tStream = new FileOutputStream( targetFile );
> 221 writer = new OutputStreamWriter( tStream, getOutputEncoding() );
> writer.write( buffer );
> writer.close();
> File siteDir = getReportOutputDirectory();
> siteDir.mkdirs();
> FileUtils.copyFile( targetFile, new File( siteDir, "cpd." + format ) );
> }
> catch ( IOException ioe )
> {
> throw new MavenReportException( ioe.getMessage(), ioe );
> }
> finally
> {
> 235 IOUtil.close( writer );
> }
> }
--
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