vert-x3 / vertx-amqp-client

An AMQP client for Vert.x
Apache License 2.0
17 stars 18 forks source link

AmqpMessage.isBodyNull() throws "The body is not an AMQP Value" #53

Closed sebthom closed 3 years ago

sebthom commented 3 years ago

Currently AmqpMessage.isBodyNull() throws an IllegalStateException("The body is not an AMQP Value") if message.getBody() is not null and it's type is not an AmqpValue.

This does not comply to what the javadoc says: This method returns true is the message does not contain a body or if the message contain a null AMQP value as body.

java.lang.IllegalStateException: The body is not an AMQP Value
    at io.vertx.amqp.impl.AmqpMessageImpl.getAmqpValue(AmqpMessageImpl.java:100) ~[vertx-amqp-client-4.0.0.jar:4.0.0]
    at io.vertx.amqp.impl.AmqpMessageImpl.isBodyNull(AmqpMessageImpl.java:95) ~[vertx-amqp-client-4.0.0.jar:4.0.0]
  @Override
  public boolean isBodyNull() {
    return message.getBody() == null || getAmqpValue() == null;
  }

  private Object getAmqpValue() {
    if (message.getBody().getType() != Section.SectionType.AmqpValue) {
      throw new IllegalStateException("The body is not an AMQP Value");
    }
    return ((AmqpValue) message.getBody()).getValue();
  }
vietj commented 3 years ago

what is the type of the underlying value you have ?

sebthom commented 3 years ago

org.apache.qpid.proton.amqp.messaging.Section.SectionType.Data i.e. a byte array.

vietj commented 3 years ago

can you provide a reproducer and possibly a fix @sebthom ?