[ 
http://issues.apache.org/jira/browse/HTTPCORE-12?page=comments#action_12433369 
] 
            
Gabriel Klein commented on HTTPCORE-12:
---------------------------------------

Here is a sample class that show the bug.

public class Test {
        public static void main(String[] args) {
                {
                        System.out.println("Test 1");
                        boolean dontClose = false;
                        try {
                                if (!dontClose) {
                                        System.out.println("First close");
                                } else {
                                        System.out.println("Connection kept 
alive...");
                                }

                        } finally {
                                System.out.println("Finally close");
                        }
                }

                {
                        System.out.println("Test 2");
                        boolean dontClose = true;
                        try {
                                if (!dontClose) {
                                        System.out.println("First close");
                                } else {
                                        System.out.println("Connection kept 
alive...");
                                }

                        } finally {
                                System.out.println("Finally close");
                        }
                }
        }
}

And what is shown:
Test 1
First close
Finally close <<<< ???
Test 2
Connection kept alive...
Finally close <<<< ???

I think what you expect is:
Test 1
First close
Test 2
Connection kept alive...


> "finally" bug in samples
> ------------------------
>
>                 Key: HTTPCORE-12
>                 URL: http://issues.apache.org/jira/browse/HTTPCORE-12
>             Project: HttpComponents Core
>          Issue Type: Bug
>          Components: Examples
>         Environment: All
>            Reporter: Gabriel Klein
>
> In code
> http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java
> and
> http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java
> You have
>       {
>           .....
>                 if (!connStrategy.keepAlive(response, context)) {
>                     conn.close();
>                 } else {
>                     System.out.println("Connection kept alive...");
>                 }
>             }
>         } finally {
>             conn.close();
>         }   
> The problem is that "conn.close();" is called everytime... even if you 
> "System.out.println("Connection kept alive...");".

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to