Uploaded image for project: 'Maven PMD Plugin'
  1. Maven PMD Plugin
  2. MPMD-145

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 3.0
    • 3.0
    • PMD
    • None

    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();
      }

      Attachments

        Activity

          People

            olamy Olivier Lamy
            guangtai Guangtai Liang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: