[ 
https://issues.apache.org/jira/browse/AMQCPP-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14105369#comment-14105369
 ] 

Pawel Remiszewski commented on AMQCPP-551:
------------------------------------------

After analysis I found rootcause. In Java the size of "char" type 2 bytes 
(Unicode) and in c++ 1 byte, that’s why the exception was thrown. After 
applying below changes it started to work correctly. Not sure if it is final 
solution, as probably wchar should be returned by getChar() method.

{noformat}
diff --git activemq-cpp/src/main/decaf/io/DataInputStream.cpp 
activemq-cpp/src/main/decaf/io/DataInputStream.cpp
index 4913f99..9d96e88 100644
--- activemq-cpp/src/main/decaf/io/DataInputStream.cpp
+++ activemq-cpp/src/main/decaf/io/DataInputStream.cpp
@@ -82,8 +82,8 @@ unsigned char DataInputStream::readUnsignedByte() {
 char DataInputStream::readChar() {
 
     try {
-        readAllData(buffer, sizeof(unsigned char));
-        return (char) (buffer[0]);
+        readAllData(buffer, sizeof(unsigned char)*2);
+        return (char) (buffer[1]);
     }
     DECAF_CATCH_RETHROW(EOFException)
     DECAF_CATCH_RETHROW(IOException)
diff --git activemq-cpp/src/main/decaf/io/DataOutputStream.cpp 
activemq-cpp/src/main/decaf/io/DataOutputStream.cpp
index 7cdf301..9985d9e 100644
--- activemq-cpp/src/main/decaf/io/DataOutputStream.cpp
+++ activemq-cpp/src/main/decaf/io/DataOutputStream.cpp
@@ -126,9 +126,9 @@ void DataOutputStream::writeChar(char value) {
         if (outputStream == NULL) {
             throw IOException(__FILE__, __LINE__, "DataOutputStream::write - 
Base stream is Null");
         }
-
+        outputStream->write('\0');
         outputStream->write(value);
-        written++;
+        written+=2;
     }
     DECAF_CATCH_RETHROW(IOException)
     DECAF_CATCHALL_THROW(IOException)
{noformat}

> EOFException when sending char in MapMessage between Java and C++
> -----------------------------------------------------------------
>
>                 Key: AMQCPP-551
>                 URL: https://issues.apache.org/jira/browse/AMQCPP-551
>             Project: ActiveMQ C++ Client
>          Issue Type: Bug
>    Affects Versions: 3.8.3
>         Environment: Ubuntu 12.04, Windows Server 2008, Java 1.7
>            Reporter: Pawel Remiszewski
>            Assignee: Timothy Bish
>            Priority: Critical
>
> Char values in MapMessage cause EOFException when sending message between 
> Java and C++ (both ways).
> When sending messages with char values between Java <=> Java and c++ <=> c++ 
> it works without errors.
> Don't know if the issue is in Java or c++ part, so I create 2 issues (one for 
> Java ActiveMQ and one for C++)
> ActiveMQ version used: 5.10.0
> ActiveMQ-CPP version used: 3.8.3
> Also tried with older (3.7.0) and the newest (master from GIT) version of 
> ActiveMQ-CPP and the same error is thrown.
> Scenario 1 (send message from Java to c++):
> 1. when MapMessage contains only one char value, no exception is thrown on 
> c++ side, but value is always equals to 0.
> 2. when MapMessage contains char value and some additional values (no matter 
> what type) EOF exception is thrown on c++ side.
> Scenario 2 (send message from c++ to Java):
> 1. when MapMessage contains at lease one char value, EOF exception is thrown 
> on Java side.
> Java stacktrace:
> {noformat}
> javax.jms.JMSException: java.io.EOFException
>       at 
> org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:62)
>       at 
> org.apache.activemq.command.ActiveMQMapMessage.loadContent(ActiveMQMapMessage.java:178)
>       at 
> org.apache.activemq.command.ActiveMQMapMessage.initializeReading(ActiveMQMapMessage.java:795)
>       at 
> org.apache.activemq.command.ActiveMQMapMessage.getMapNames(ActiveMQMapMessage.java:537)
>       at activemq.test.TestConsumer.onMessage(TestConsumer.java:59)
>       at activemq.test.TestConsumer.<init>(TestConsumer.java:39)
>       at activemq.test.App.main(App.java:12)
> Caused by: java.io.EOFException
>       at java.io.DataInputStream.readChar(DataInputStream.java:365)
>       at 
> org.apache.activemq.util.MarshallingSupport.unmarshalPrimitive(MarshallingSupport.java:175)
>       at 
> org.apache.activemq.util.MarshallingSupport.unmarshalPrimitiveMap(MarshallingSupport.java:98)
>       at 
> org.apache.activemq.util.MarshallingSupport.unmarshalPrimitiveMap(MarshallingSupport.java:78)
>       at 
> org.apache.activemq.util.MarshallingSupport.unmarshalPrimitiveMap(MarshallingSupport.java:70)
>       at 
> org.apache.activemq.command.ActiveMQMapMessage.loadContent(ActiveMQMapMessage.java:174)
>       ... 5 more
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to