You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Guangtai Liang (JIRA)" <ji...@codehaus.org> on 2012/02/22 15:09:02 UTC

[jira] (MPTEST-79) An incomplete fix for the resource leak bugs in TestUtils.java

Guangtai Liang created MPTEST-79:
------------------------------------

             Summary: An incomplete fix for the resource leak bugs in TestUtils.java
                 Key: MPTEST-79
                 URL: https://jira.codehaus.org/browse/MPTEST-79
             Project: Maven 1.x Test Plugin
          Issue Type: Bug
    Affects Versions: 1.8.3
            Reporter: Guangtai Liang
            Priority: Critical


The fix revision 1085807 was aimed to remove resource leak bugs on the BufferedReader object "reader" (created in line 79) in the method "readFile"of the file "/maven/plugin-
testing/trunk/maven-test-tools/src/main/java/org/apache/maven/shared/tools/easymock/TestUtils.java" , but it is incomplete.

There are some problems: 
1. when "reader" isn't created successfully but the temp FileReader object is created successfully, 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 and then putting all other code in a try block.

The problem still exists in the head revision. The buggy code is copied as bellows:

 public static String readFile( File file )
        throws IOException
    {
        StringBuffer buffer = new StringBuffer();

        BufferedReader reader = null;

        try
        {
79          reader = new BufferedReader( new FileReader( file ) );

            String line = null;

            while ( ( line = reader.readLine() ) != null )
            {
                if ( buffer.length() > 0 )
                {
                    buffer.append( '\n' );
                }

                buffer.append( line );
            }

            return buffer.toString();
        }
        finally
        {
96          IOUtil.close( reader );
        }
    }


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] (MPLUGINTESTING-20) An incomplete fix for the resource leak bugs in TestUtils.java

Posted by "Dennis Lundberg (JIRA)" <ji...@codehaus.org>.
     [ https://jira.codehaus.org/browse/MPLUGINTESTING-20?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dennis Lundberg moved MPTEST-79 to MPLUGINTESTING-20:
-----------------------------------------------------

    Affects Version/s:     (was: 1.8.3)
             Workflow: Maven New  (was: jira)
                  Key: MPLUGINTESTING-20  (was: MPTEST-79)
              Project: Maven 2.x Plugin Testing  (was: Maven 1.x Test Plugin)
    
> An incomplete fix for the resource leak bugs in TestUtils.java
> --------------------------------------------------------------
>
>                 Key: MPLUGINTESTING-20
>                 URL: https://jira.codehaus.org/browse/MPLUGINTESTING-20
>             Project: Maven 2.x Plugin Testing
>          Issue Type: Bug
>            Reporter: Guangtai Liang
>            Priority: Critical
>   Original Estimate: 10 minutes
>  Remaining Estimate: 10 minutes
>
> The fix revision 1085807 was aimed to remove resource leak bugs on the BufferedReader object "reader" (created in line 79) in the method "readFile"of the file "/maven/plugin-
> testing/trunk/maven-test-tools/src/main/java/org/apache/maven/shared/tools/easymock/TestUtils.java" , but it is incomplete.
> There are some problems: 
> 1. when "reader" isn't created successfully but the temp FileReader object is created successfully, 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 and then putting all other code in a try block.
> The problem still exists in the head revision. The buggy code is copied as bellows:
>  public static String readFile( File file )
>         throws IOException
>     {
>         StringBuffer buffer = new StringBuffer();
>         BufferedReader reader = null;
>         try
>         {
> 79          reader = new BufferedReader( new FileReader( file ) );
>             String line = null;
>             while ( ( line = reader.readLine() ) != null )
>             {
>                 if ( buffer.length() > 0 )
>                 {
>                     buffer.append( '\n' );
>                 }
>                 buffer.append( line );
>             }
>             return buffer.toString();
>         }
>         finally
>         {
> 96          IOUtil.close( reader );
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira