From e2bae7856d414a6c8012eee20197451f378fd389 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Fri, 6 Jul 2018 10:14:48 -0500 Subject: [PATCH] ARTEMIS-1941 fix failing tests --- .../protocol/amqp/converter/CoreAmqpConverter.java | 9 ++++++--- .../message/JMSMappingOutboundTransformerTest.java | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/CoreAmqpConverter.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/CoreAmqpConverter.java index eb20219641..b287d0c137 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/CoreAmqpConverter.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/CoreAmqpConverter.java @@ -451,9 +451,12 @@ public class CoreAmqpConverter { // this will represent a readOnly buffer for the message ActiveMQBuffer buffer = internalMessage.getDataBuffer(); try { - Object s = buffer.readNullableSimpleString(); - if (s != null) { - body = new AmqpValue(s.toString()); + // the buffer may be completely empty (e.g. if the original AMQP message had a null body) + if (buffer.readableBytes() > 0) { + Object s = buffer.readNullableSimpleString(); + if (s != null) { + body = new AmqpValue(s.toString()); + } } } catch (Throwable ignored) { logger.debug("Exception ignored during conversion", ignored.getMessage(), ignored); diff --git a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformerTest.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformerTest.java index f1cd588cb0..565f67b147 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformerTest.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformerTest.java @@ -341,11 +341,11 @@ public class JMSMappingOutboundTransformerTest { Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage(); assertNotNull(amqp.getBody()); - assertTrue(amqp.getBody() instanceof Data); - assertTrue(((Data) amqp.getBody()).getValue() instanceof Binary); - assertFalse(0 == ((Binary) ((Data) amqp.getBody()).getValue()).getLength()); + assertTrue(amqp.getBody() instanceof AmqpValue); + assertTrue(((AmqpValue) amqp.getBody()).getValue() instanceof Binary); + assertFalse(0 == ((Binary) ((AmqpValue) amqp.getBody()).getValue()).getLength()); - Object value = deserialize((((Data) amqp.getBody()).getValue()).getArray()); + Object value = deserialize(((Binary) ((AmqpValue) amqp.getBody()).getValue()).getArray()); assertNotNull(value); assertTrue(value instanceof UUID); } @@ -361,7 +361,7 @@ public class JMSMappingOutboundTransformerTest { assertNotNull(amqp.getBody()); assertTrue(amqp.getBody() instanceof AmqpValue); assertTrue(((AmqpValue) amqp.getBody()).getValue() instanceof Binary); - assertEquals(0, ((Binary) ((AmqpValue) amqp.getBody()).getValue()).getLength()); + assertEquals(5, ((Binary) ((AmqpValue) amqp.getBody()).getValue()).getLength()); } // ----- TextMessage type tests -------------------------------------------//