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

        Andreas Dangel made changes -
        Field Original Value New Value
        Attachment 0001-Close-the-fileoutputstream-in-the-finally-block-too..patch [ 59978 ]
        Hide
        Olivier Lamy added a comment -

        dupe of MPMD-146

        Show
        Olivier Lamy added a comment - dupe of MPMD-146
        Olivier Lamy made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Olivier Lamy [ olamy ]
        Resolution Duplicate [ 3 ]
        Olivier Lamy made changes -
        Resolution Duplicate [ 3 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Olivier Lamy made changes -
        Fix Version/s 2.8 [ 18287 ]
        Affects Version/s 2.7.1 [ 18314 ]
        Affects Version/s 2.8 [ 18287 ]
        Hide
        Olivier Lamy added a comment -

        fixed.
        Thanks

        Show
        Olivier Lamy added a comment - fixed. Thanks
        Olivier Lamy made changes -
        Status Reopened [ 4 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: