You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2021/10/05 16:36:17 UTC

[activemq-artemis] 02/03: ARTEMIS-3457 Dealing with String conversions

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 557506140fa2bb2df68b6a1905b201c84da811ed
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Mon Oct 4 19:00:43 2021 -0400

    ARTEMIS-3457 Dealing with String conversions
    
    The test I wrote for ARTEMIS-3513 is throwing a few convert exceptions
    because of SimpleString versus String conversion
    
    This commit is addressing the issue,
    The previous commit (the one addressing ARTEMIS-3513) should provide the test for this change.
---
 .../artemis/core/protocol/openwire/OpenWireMessageConverter.java   | 7 ++++++-
 .../artemis/tests/integration/openwire/CompactingOpenWireTest.java | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireMessageConverter.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireMessageConverter.java
index 66a8d66..d8b00c1 100644
--- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireMessageConverter.java
+++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireMessageConverter.java
@@ -710,7 +710,12 @@ public final class OpenWireMessageConverter {
    private static <T> T getObjectProperty(ICoreMessage message, Class<T> type, SimpleString property) {
       if (message.getPropertyNames().contains(property)) {
          try {
-            return type.cast(message.getObjectProperty(property));
+            Object value = message.getObjectProperty(property);
+            if (type == String.class && value != null) {
+               return (T)value.toString();
+            } else {
+               return type.cast(value);
+            }
          } catch (ClassCastException e) {
             ActiveMQServerLogger.LOGGER.failedToDealWithObjectProperty(property, e.getMessage());
          }
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/CompactingOpenWireTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/CompactingOpenWireTest.java
index b01c5df..cffea50 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/CompactingOpenWireTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/CompactingOpenWireTest.java
@@ -153,6 +153,7 @@ public class CompactingOpenWireTest extends BasicOpenWireTest {
          Assert.assertEquals(0, errors.get());
          Assert.assertFalse(AssertionLoggerHandler.findText("AMQ144003")); // error compacting
          Assert.assertFalse(AssertionLoggerHandler.findText("AMQ222055")); // records not found
+         Assert.assertFalse(AssertionLoggerHandler.findText("AMQ222302")); // string conversion issue
       } finally {
          AssertionLoggerHandler.stopCapture();
          running.set(false);