Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
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:
/** * 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()); } }
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:
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(); } }
Notice the null-check with null-return.