Maven Verifier Plugin
  1. Maven Verifier Plugin
  2. MVERIFIER-12

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

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      The fix revision 1134539 was aimed to remove resource leak bugs on the BufferedReader object "reader"(created in line 421) in the method "loadFile()", the BufferedReader object "reader" (created in line 1538) of the file "/maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/Verifier.java" , but it is incomplete.

      There are some problems:
      1. when "reader" is not created successfully at line 427 but the temp FileReader object is created successfully at line 427,the temp FileReader object will be leaked.
      2. when "reader" is not created successfully at line 1541 but the temp FileReader object is created successfully at line 1541,the temp FileReader object will be leaked.

      The best way to close such resource objects is putting such close operations for all resource objects 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 (the temp objects created at line 427 and 1541 needs to be closed in the finally clause):

      416 public List loadFile( File file, boolean hasCommand )
      throws VerificationException
      {
      List lines = new ArrayList();

      BufferedReader reader = null;

      if ( file.exists() )
      {
      try
      {
      427 reader = new BufferedReader( new FileReader( file ) );

      String line = reader.readLine();

      while ( line != null )
      {
      line = line.trim();

      if ( !line.startsWith( "#" ) && line.length() != 0 )

      { lines.addAll( replaceArtifacts( line, hasCommand ) ); }

      line = reader.readLine();
      }

      reader.close();
      }
      catch ( FileNotFoundException e )

      { throw new VerificationException( e ); }
      catch ( IOException e )
      { throw new VerificationException( e ); }

      finally

      { 454 IOUtil.close( reader ); }

      }

      return lines;
      }

      1535 private void displayLogFile()
      {
      System.out.println( "Log file contents:" );
      BufferedReader reader = null;
      try
      {
      1541 reader = new BufferedReader( new FileReader( new File( getBasedir(), getLogFileName

      () ) ) );
      String line = reader.readLine();
      while ( line != null )

      { System.out.println( line ); line = reader.readLine(); }

      reader.close();
      }
      catch ( FileNotFoundException e )

      { System.err.println( "Error: " + e ); }

      catch ( IOException e )

      { System.err.println( "Error: " + e ); }

      finally

      { 1560 IOUtil.close( reader ); }

      }

        Activity

          People

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

            Dates

            • Created:
              Updated:
              Resolved: