Maven PMD Plugin
  1. Maven PMD Plugin
  2. MPMD-144

An incomplete fix for the resource leak bugs in PmdReport.java

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.7.1
    • Fix Version/s: 3.0
    • Component/s: PMD
    • Labels:
      None
    • Number of attachments :
      1

      Description

      The fix revision 935344 was aimed to remove an resource leak bug on the OutputStreamWriter object "writer" (created in line 323) in the method "execute()" of the file "/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java" , but it is incomplete.

      There are some problems:
      1. when "writer" is not created successfully but the FileOutputStream object "tStream" is created successfully at line 322,"tStream" 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:

      try

      { targetDirectory.mkdirs(); File targetFile = new File( targetDirectory, "pmd." + format ); 357 FileOutputStream tStream = new FileOutputStream( targetFile ); 358 writer = new OutputStreamWriter( tStream, getOutputEncoding() ); r.setWriter( writer ); r.start(); r.renderFileReport( report ); r.end(); writer.close(); File siteDir = getReportOutputDirectory(); siteDir.mkdirs(); FileUtils.copyFile( targetFile, new File( siteDir, "pmd." + format ) ); }

      catch ( IOException ioe )

      { throw new MavenReportException( ioe.getMessage(), ioe ); }

      finally

      { 376 IOUtil.close( writer ); }

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Olivier Lamy
            Reporter:
            Guangtai Liang
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: