PROTON-2059: handle the char type during array decoding
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java
index 7d4de49..3104486 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java
@@ -1112,6 +1112,10 @@
{
return decodeDoubleArray((DoubleType.DoubleEncoding)constructor, count);
}
+ else if(constructor instanceof CharacterType.CharacterEncoding)
+ {
+ return decodeCharArray((CharacterType.CharacterEncoding)constructor, count);
+ }
else
{
throw new ClassCastException("Unexpected class " + constructor.getClass().getName());
@@ -1206,5 +1210,17 @@
return array;
}
+
+ private static char[] decodeCharArray(CharacterType.CharacterEncoding constructor, final int count)
+ {
+ char[] array = new char[count];
+
+ for(int i = 0; i < count; i++)
+ {
+ array[i] = constructor.readPrimitiveValue();
+ }
+
+ return array;
+ }
}
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/ArrayTypeCodecTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/ArrayTypeCodecTest.java
index c82ecb7..9a85216 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/ArrayTypeCodecTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/codec/ArrayTypeCodecTest.java
@@ -1023,24 +1023,24 @@
}
@Test
- public void testEncodeCharArray25() throws Throwable {
+ public void testEncodeDecodeCharArray25() throws Throwable {
// char array8 less than 128 bytes
- doEncodeCharArrayTestImpl(25);
+ doEncodeDecodeCharArrayTestImpl(25);
}
@Test
- public void testEncodeCharArray50() throws Throwable {
+ public void testEncodeDecodeCharArray50() throws Throwable {
// char array8 greater than 128 bytes
- doEncodeCharArrayTestImpl(50);
+ doEncodeDecodeCharArrayTestImpl(50);
}
@Test
- public void testEncodeCharArray384() throws Throwable {
+ public void testEncodeDecodeCharArray384() throws Throwable {
// char array32
- doEncodeCharArrayTestImpl(384);
+ doEncodeDecodeCharArrayTestImpl(384);
}
- private void doEncodeCharArrayTestImpl(int count) throws Throwable {
+ private void doEncodeDecodeCharArrayTestImpl(int count) throws Throwable {
char[] source = createPayloadArrayChars(count);
try {
@@ -1084,6 +1084,16 @@
assertFalse("Should have drained the encoder buffer contents", buffer.hasRemaining());
assertArrayEquals("Unexpected actual array encoding", expectedEncoding, actualEncoding);
+
+ // Now verify against the decoding
+ buffer.flip();
+ Object decoded = decoder.readObject();
+ assertNotNull(decoded);
+ assertTrue(decoded.getClass().isArray());
+ assertTrue(decoded.getClass().getComponentType().isPrimitive());
+ assertEquals(char.class, decoded.getClass().getComponentType());
+
+ assertArrayEquals("Unexpected decoding", source, (char[]) decoded);
}
catch (Throwable t) {
System.err.println("Error during test, source array: " + Arrays.toString(source));