This is an automated email from the ASF dual-hosted git repository.
tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
The following commit(s) were added to refs/heads/main by this push:
new dc9bf077 PROTON-2869 Fix smallint decoding of negative values
dc9bf077 is described below
commit dc9bf077806b6420ddf9774e98bdbd906c6ee403
Author: Timothy Bish <[email protected]>
AuthorDate: Thu Feb 13 14:24:27 2025 -0500
PROTON-2869 Fix smallint decoding of negative values
Fix decodng handlers and add tests for negative small int values
---
.../protonj2/codec/decoders/ProtonDecoder.java | 4 ++--
.../decoders/primitives/Integer8TypeDecoder.java | 2 +-
.../codec/primitives/IntegerTypeCodecTest.java | 25 +++++++++++++++++-----
3 files changed, 23 insertions(+), 8 deletions(-)
diff --git
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/ProtonDecoder.java
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/ProtonDecoder.java
index bb30aba7..912b3247 100644
---
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/ProtonDecoder.java
+++
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/ProtonDecoder.java
@@ -535,7 +535,7 @@ public final class ProtonDecoder implements Decoder {
switch (encodingCode) {
case EncodingCodes.SMALLINT:
- return buffer.readByte() & 0xff;
+ return (int) buffer.readByte();
case EncodingCodes.INT:
return buffer.readInt();
case EncodingCodes.NULL:
@@ -551,7 +551,7 @@ public final class ProtonDecoder implements Decoder {
switch (encodingCode) {
case EncodingCodes.SMALLINT:
- return buffer.readByte() & 0xff;
+ return buffer.readByte();
case EncodingCodes.INT:
return buffer.readInt();
case EncodingCodes.NULL:
diff --git
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/Integer8TypeDecoder.java
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/Integer8TypeDecoder.java
index 274fad22..d92e8133 100644
---
a/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/Integer8TypeDecoder.java
+++
b/protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/Integer8TypeDecoder.java
@@ -80,7 +80,7 @@ public final class Integer8TypeDecoder extends
AbstractPrimitiveTypeDecoder<Inte
@Override
public Integer readValue(ProtonBuffer buffer, DecoderState state) throws
DecodeException {
- return buffer.readByte() & 0xff;
+ return Integer.valueOf(buffer.readByte());
}
@Override
diff --git
a/protonj2/src/test/java/org/apache/qpid/protonj2/codec/primitives/IntegerTypeCodecTest.java
b/protonj2/src/test/java/org/apache/qpid/protonj2/codec/primitives/IntegerTypeCodecTest.java
index 68f93be8..2836e14d 100644
---
a/protonj2/src/test/java/org/apache/qpid/protonj2/codec/primitives/IntegerTypeCodecTest.java
+++
b/protonj2/src/test/java/org/apache/qpid/protonj2/codec/primitives/IntegerTypeCodecTest.java
@@ -91,12 +91,15 @@ public class IntegerTypeCodecTest extends CodecTestSupport {
buffer.writeInt(44);
buffer.writeByte(EncodingCodes.SMALLINT);
buffer.writeByte((byte) 43);
+ buffer.writeByte(EncodingCodes.SMALLINT);
+ buffer.writeByte((byte) -2);
buffer.writeByte(EncodingCodes.NULL);
buffer.writeByte(EncodingCodes.NULL);
assertEquals(42, decoder.readInteger(buffer, decoderState).intValue());
assertEquals(44, decoder.readInteger(buffer, decoderState, 42));
assertEquals(43, decoder.readInteger(buffer, decoderState, 42));
+ assertEquals(-2, decoder.readInteger(buffer, decoderState, 42));
assertNull(decoder.readInteger(buffer, decoderState));
assertEquals(42, decoder.readInteger(buffer, decoderState, 42));
}
@@ -111,6 +114,8 @@ public class IntegerTypeCodecTest extends CodecTestSupport {
buffer.writeInt(44);
buffer.writeByte(EncodingCodes.SMALLINT);
buffer.writeByte((byte) 43);
+ buffer.writeByte(EncodingCodes.SMALLINT);
+ buffer.writeByte((byte) -43);
buffer.writeByte(EncodingCodes.NULL);
buffer.writeByte(EncodingCodes.NULL);
@@ -119,6 +124,7 @@ public class IntegerTypeCodecTest extends CodecTestSupport {
assertEquals(42, streamDecoder.readInteger(stream,
streamDecoderState).intValue());
assertEquals(44, streamDecoder.readInteger(stream, streamDecoderState,
42));
assertEquals(43, streamDecoder.readInteger(stream, streamDecoderState,
42));
+ assertEquals(-43, streamDecoder.readInteger(stream,
streamDecoderState, 42));
assertNull(streamDecoder.readInteger(stream, streamDecoderState));
assertEquals(42, streamDecoder.readInteger(stream, streamDecoderState,
42));
}
@@ -152,8 +158,11 @@ public class IntegerTypeCodecTest extends CodecTestSupport
{
buffer.writeByte(EncodingCodes.SMALLINT);
buffer.writeByte((byte) 42);
+ buffer.writeByte(EncodingCodes.SMALLINT);
+ buffer.writeByte((byte) -1);
assertEquals(42, decoder.readInteger(buffer, decoderState).intValue());
+ assertEquals(-1, decoder.readInteger(buffer, decoderState).intValue());
}
@Test
@@ -174,10 +183,13 @@ public class IntegerTypeCodecTest extends
CodecTestSupport {
buffer.writeByte(EncodingCodes.SMALLINT);
buffer.writeByte((byte) 42);
+ buffer.writeByte(EncodingCodes.SMALLINT);
+ buffer.writeByte((byte) -1);
InputStream stream = new ProtonBufferInputStream(buffer);
assertEquals(42, streamDecoder.readInteger(stream,
streamDecoderState).intValue());
+ assertEquals(-1, streamDecoder.readInteger(stream,
streamDecoderState).intValue());
}
@Test
@@ -341,18 +353,20 @@ public class IntegerTypeCodecTest extends
CodecTestSupport {
if (encoding == EncodingCodes.INT) {
buffer.writeByte(EncodingCodes.ARRAY32);
- buffer.writeInt(17); // Size
- buffer.writeInt(2); // Count
+ buffer.writeInt(21); // Size
+ buffer.writeInt(3); // Count
buffer.writeByte(EncodingCodes.INT);
buffer.writeInt(1); // [0]
buffer.writeInt(2); // [1]
+ buffer.writeInt(-1); // [2]
} else if (encoding == EncodingCodes.SMALLINT) {
buffer.writeByte(EncodingCodes.ARRAY32);
- buffer.writeInt(11); // Size
- buffer.writeInt(2); // Count
+ buffer.writeInt(12); // Size
+ buffer.writeInt(3); // Count
buffer.writeByte(EncodingCodes.SMALLINT);
buffer.writeByte((byte) 1); // [0]
buffer.writeByte((byte) 2); // [1]
+ buffer.writeByte((byte) -1); // [2]
}
final Object result;
@@ -369,9 +383,10 @@ public class IntegerTypeCodecTest extends CodecTestSupport
{
int[] array = (int[]) result;
- assertEquals(2, array.length);
+ assertEquals(3, array.length);
assertEquals(1, array[0]);
assertEquals(2, array[1]);
+ assertEquals(-1, array[2]);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]