You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Karl Heinz Marbaise (JIRA)" <ji...@codehaus.org> on 2014/02/27 17:32:59 UTC

[jira] (MVERIFIER-12) An incomplete fix for the resource leak bugs in Verifier.java

     [ https://jira.codehaus.org/browse/MVERIFIER-12?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Karl Heinz Marbaise closed MVERIFIER-12.
----------------------------------------

    Resolution: Fixed

Issue is solve in the shared component.

> An incomplete fix for the resource leak bugs in Verifier.java
> -------------------------------------------------------------
>
>                 Key: MVERIFIER-12
>                 URL: https://jira.codehaus.org/browse/MVERIFIER-12
>             Project: Maven Verifier Plugin
>          Issue Type: Bug
>    Affects Versions: 1.1
>            Reporter: Guangtai Liang
>            Priority: Critical
>
> 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 );
>         }
>     }



--
This message was sent by Atlassian JIRA
(v6.1.6#6162)