You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2015/10/28 15:43:27 UTC

[jira] [Commented] (AMQ-5959) NullPointerException in finally blocks

    [ https://issues.apache.org/jira/browse/AMQ-5959?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14978526#comment-14978526 ] 

ASF subversion and git services commented on AMQ-5959:
------------------------------------------------------

Commit 6626f9171830bebd85dfa26904f23be71982061f in activemq's branch refs/heads/activemq-5.11.x from [~tabish121]
[ https://git-wip-us.apache.org/repos/asf?p=activemq.git;h=6626f91 ]

https://issues.apache.org/jira/browse/AMQ-5959

Add check to avoid NPE
(cherry picked from commit f58683ea07c49aa567a3dc888b12b7de92918ed6)


> NullPointerException in finally blocks
> --------------------------------------
>
>                 Key: AMQ-5959
>                 URL: https://issues.apache.org/jira/browse/AMQ-5959
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: Broker
>    Affects Versions: 5.8.0, 5.12.0
>            Reporter: William McDonald
>            Priority: Minor
>              Labels: easyfix
>             Fix For: 5.12.1, 5.11.3, 5.13.0
>
>
> Try blocks including a finally block that references a potential null object generating a NullPointerException.
> In The DestinationView.sendTextMessage(java.util.Map, ...) method for example (http://grepcode.com/file/repo1.maven.org/maven2/org.apache.activemq/activemq-broker/5.11.1/org/apache/activemq/broker/jmx/DestinationView.java#DestinationView.sendTextMessage%28java.util.Map%2Cjava.lang.String%2Cjava.lang.String%2Cjava.lang.String%29), I noticed code like the following:  
>         Connection connection = null;
>         try {
>             connection = cf.createConnection(userName, password);
>          ...
>              return msg.getJMSMessageID();
>         } finally {
>             connection.close();
>         }
> There is no catch block and since an exception in the createConnection method could be thrown, connection would be null in the finally block, causing a NPE and masking the real exception.
> There may be other forms of this bad style which a code style checker should be able to locate for you.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)