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

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

    Details

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

      Description

      The fix revision 729532 was aimed to remove an resource leak bug on the BufferedReader object "in" (created in line 240) in the method "readFile()" of the file "/maven/plugins/trunk/maven-pmd-
      plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java" , but it is incomplete.

      There are some problems:
      1. when "in" is not created successfully but the temp FileReader object is created successfully at line 240,the temp FileReader object 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:

      private String readFile( File file )
      throws IOException
      {
      String strTmp;
      StringBuffer str = new StringBuffer( (int) file.length() );
      246 BufferedReader in = new BufferedReader( new FileReader( file ) );

      while ( ( strTmp = in.readLine() ) != null )

      { str.append( ' ' ); str.append( strTmp ); }

      253 in.close();

      return str.toString();
      }

        Activity

        Hide
        Olivier Lamy added a comment -

        fixed.
        Thanks !

        Show
        Olivier Lamy added a comment - fixed. Thanks !

          People

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

            Dates

            • Created:
              Updated:
              Resolved: