rabbitmq / rabbitmq-jms-client

RabbitMQ JMS client
Other
63 stars 49 forks source link

NPE if a received message is marked as "Redelivered" but no header is given #325

Closed chbriem closed 11 months ago

chbriem commented 11 months ago

Describe the bug

When receiving a message in "amqp mode" with a "Redelivered" flag set, and the given message does not contain any headers, then a NPE is thrown.

Reproduction steps

  1. Initialize the "RMQDestination" with Routing Key and Exchange Name ("amqp mode").
  2. Put a message in the queue, with "relivered" flag set and no headers.
  3. Try to receive the message

Expected behavior

No NPE is thrown, and the code runs into the branch where deliveryCount == null, which sets the JMSXDeliveryCount is set to "2".

Additional context

Stacktrace (shortened):

java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because the return value of "com.rabbitmq.client.AMQP$BasicProperties.getHeaders()" is null
    at com.rabbitmq.jms.client.RMQMessage.handleJmsRedeliveredAndDeliveryCount(RMQMessage.java:886) ~[rabbitmq-jms.jar:2.8.0]
    at com.rabbitmq.jms.client.RMQMessage.convertAmqpMessage(RMQMessage.java:866) ~[rabbitmq-jms.jar:2.8.0]
    at com.rabbitmq.jms.client.RMQMessage.convertMessage(RMQMessage.java:835) ~[rabbitmq-jms.jar:2.8.0]
    at com.rabbitmq.jms.client.RMQMessageConsumer.receive(RMQMessageConsumer.java:358) ~[rabbitmq-jms.jar:2.8.0]
    at com.rabbitmq.jms.client.RMQMessageConsumer.receive(RMQMessageConsumer.java:272) ~[rabbitmq-jms.jar:2.8.0]
lukebakken commented 11 months ago

Thanks for using RabbitMQ.

What would expedite a fix is for us to easily be able to reproduce this issue. I am not a Java or JMS expert, but if you provided a project I could clone, compile, and run to see the issue, I could probably fix it in this code. It would take me at least an hour, probably several, to figure out how to set up a project to reproduce this issue. That's time I could be using to fix the issue.

Or, feel free to submit a PR yourself!

michaelklishin commented 11 months ago

This client assumes that the value is always set because it is always set by RabbitMQ itself (to false by default).

There's no harm in being more defensive, you are welcome to submit a PR. This is open source software after all.