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
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.7.1
    • Fix Version/s: 3.0
    • Component/s: PMD
    • Labels:
      None

      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

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Closed Closed
        87d 15h 14m 1 Olivier Lamy (*$^¨%`£) 19/May/12 18:00
        Closed Closed Reopened Reopened
        1d 21h 12m 1 Olivier Lamy (*$^¨%`£) 21/May/12 15:13
        Reopened Reopened Closed Closed
        4m 53s 1 Olivier Lamy (*$^¨%`£) 21/May/12 15:18
        Mark Thomas made changes -
        Workflow jira [ 12960448 ] Default workflow, editable Closed status [ 12997641 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 00:25:00 UTC 2015 [ 1428279900867 ]
        Mark Thomas made changes -
        Workflow jira [ 12722884 ] Default workflow, editable Closed status [ 12756473 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 12:01:39 UTC 2015 [ 1428235299271 ]
        Olivier Lamy (*$^¨%`£) made changes -
        Status Reopened [ 4 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Hide
        Olivier Lamy (*$^¨%`£) added a comment -

        fixed.
        Thanks

        Show
        Olivier Lamy (*$^¨%`£) added a comment - fixed. Thanks
        Olivier Lamy (*$^¨%`£) made changes -
        Affects Version/s 2.7.1 [ 18314 ]
        Affects Version/s 2.8 [ 18287 ]
        Fix Version/s 2.8 [ 18287 ]
        Olivier Lamy (*$^¨%`£) made changes -
        Resolution Duplicate [ 3 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Olivier Lamy (*$^¨%`£) made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Duplicate [ 3 ]
        Assignee Olivier Lamy [ olamy ]
        Hide
        Olivier Lamy (*$^¨%`£) added a comment -

        dupe of MPMD-146

        Show
        Olivier Lamy (*$^¨%`£) added a comment - dupe of MPMD-146
        Andreas Dangel made changes -
        Field Original Value New Value
        Attachment 0001-Close-the-fileoutputstream-in-the-finally-block-too..patch [ 59978 ]
        Guangtai Liang created issue -

          People

          • Assignee:
            Olivier Lamy (*$^¨%`£)
            Reporter:
            Guangtai Liang
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development