Nonexistent Properties
If a JMS client attempts to access a nonexistent property using
getObjectProperty(), null is returned. The rest of the property
methods attempt to convert the null
value to the requested type using the valueOf() operations. This results in some
interesting behavior. The getStringProperty() returns a null or possibly an empty String ("") depending on the
implementation. The getBooleanProperty() method returns false for null values, while the other primitive
property methods throw the java.lang.NumberFormatException.
The propertyExists() method can
be used to avoid erroneous values or exceptions for properties that have
not been set on the message. Here is an example of how it’s used:
if (message.propertyExists("Age"))
age = message.getIntProperty("Age");
}Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access