activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Timothy Bish (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (AMQ-5632) MapMessage.getBytes crashes with NPE if no value present
Date Tue, 03 Mar 2015 21:19:05 GMT

     [ https://issues.apache.org/jira/browse/AMQ-5632?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Timothy Bish resolved AMQ-5632.
-------------------------------
       Resolution: Fixed
    Fix Version/s: 5.12.0
         Assignee: Timothy Bish

Added check for null and return null if so.  

> MapMessage.getBytes crashes with NPE if no value present
> --------------------------------------------------------
>
>                 Key: AMQ-5632
>                 URL: https://issues.apache.org/jira/browse/AMQ-5632
>             Project: ActiveMQ
>          Issue Type: Bug
>            Reporter: Endre StĂžlsvik
>            Assignee: Timothy Bish
>             Fix For: 5.12.0
>
>
> Compare to AMQ-5628 and AMQ-5629
> Read up on http://docs.oracle.com/javaee/1.4/api/javax/jms/MapMessage.html
> Notice the wording "if there is no item by this name, a null value is returned."
> ActiveMqMapMessage, line ~494:
> {code}
>     /**
>      * Returns the byte array value with the specified name.
>      *
>      * @param name the name of the byte array
>      * @return a copy of the byte array value with the specified name; if there
>      *         is no item by this name, a null value is returned.
>      * @throws JMSException if the JMS provider fails to read the message due to
>      *                 some internal error.
>      * @throws MessageFormatException if this type conversion is invalid.
>      */
>     @Override
>     public byte[] getBytes(String name) throws JMSException {
>         initializeReading();
>         Object value = map.get(name);
>         if (value instanceof byte[]) {
>             return (byte[])value;
>         } else {
>             throw new MessageFormatException(" cannot read a byte[] from " + value.getClass().getName());
>         }
>     }
> {code}
> Notice how the "else"-block will kick in on null value, whereby we get the "value.getClass()"
executed when inside the constructor argument creation of the wrongly thrown MessageFormatException,
resulting in NPE.
> Instead, a code block like every other getter has should be employed, here from getString
right above:
> {code}
>     public String getString(String name) throws JMSException {
>         initializeReading();
>         Object value = map.get(name);
>         if (value == null) {
>             return null;
>         }
>         if (value instanceof byte[]) {
>             throw new MessageFormatException("Use getBytes to read a byte array");
>         } else {
>             return value.toString();
>         }
>     }
> {code}
> Notice the null-check with null-return.



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

Mime
View raw message