Skip to content

Commit d9f5387

Browse files
committed
Add test for negative small long
1 parent 938c2e2 commit d9f5387

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

src/main/qpid/org/apache/qpid/protonj2/codec/decoders/ProtonDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ public Long readLong(ProtonBuffer buffer, DecoderState state) throws DecodeExcep
621621

622622
switch (encodingCode) {
623623
case EncodingCodes.SMALLLONG:
624-
return (long) buffer.readByte() & 0xff;
624+
return (long) buffer.readByte();
625625
case EncodingCodes.LONG:
626626
return buffer.readLong();
627627
case EncodingCodes.NULL:
@@ -637,7 +637,7 @@ public long readLong(ProtonBuffer buffer, DecoderState state, long defaultValue)
637637

638638
switch (encodingCode) {
639639
case EncodingCodes.SMALLLONG:
640-
return (long) buffer.readByte() & 0xff;
640+
return buffer.readByte();
641641
case EncodingCodes.LONG:
642642
return buffer.readLong();
643643
case EncodingCodes.NULL:

src/main/qpid/org/apache/qpid/protonj2/codec/decoders/ProtonStreamDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ public Long readLong(InputStream stream, StreamDecoderState state) throws Decode
645645

646646
switch (encodingCode) {
647647
case EncodingCodes.SMALLLONG:
648-
return Long.valueOf(ProtonStreamUtils.readByte(stream) & 0xffl);
648+
return (long) ProtonStreamUtils.readByte(stream);
649649
case EncodingCodes.LONG:
650650
return ProtonStreamUtils.readLong(stream);
651651
case EncodingCodes.NULL:
@@ -661,7 +661,7 @@ public long readLong(InputStream stream, StreamDecoderState state, long defaultV
661661

662662
switch (encodingCode) {
663663
case EncodingCodes.SMALLLONG:
664-
return ProtonStreamUtils.readByte(stream) & 0xffl;
664+
return ProtonStreamUtils.readByte(stream);
665665
case EncodingCodes.LONG:
666666
return ProtonStreamUtils.readLong(stream);
667667
case EncodingCodes.NULL:

src/main/qpid/org/apache/qpid/protonj2/codec/decoders/primitives/Long8TypeDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class Long8TypeDecoder extends LongTypeDecoder {
3232

3333
@Override
3434
public Long readValue(ProtonBuffer buffer, DecoderState state) throws DecodeException {
35-
return (long) buffer.readByte() & 0xff;
35+
return (long) buffer.readByte() & (byte) 0xff;
3636
}
3737

3838
@Override

src/test/java/com/rabbitmq/client/amqp/impl/AmqpTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,37 @@ void queuePurgeOnNonExistingQueueShouldThrowException(TestInfo info) {
737737
.hasMessageContaining(q);
738738
}
739739

740+
@Test
741+
void types(TestInfo info) {
742+
Management management = connection.management();
743+
String q = TestUtils.name(info);
744+
management.queue(q).exclusive(true).declare();
745+
Sync publishSync = sync();
746+
Publisher.Callback callback =
747+
context -> {
748+
if (context.status() == Publisher.Status.ACCEPTED) {
749+
publishSync.down();
750+
}
751+
};
752+
Publisher publisher = connection.publisherBuilder().queue(q).build();
753+
publisher.publish(publisher.message().property("key1", -1L), callback);
754+
assertThat(publishSync).completes();
755+
AtomicReference<Message> message = new AtomicReference<>();
756+
Sync consumeSync = sync();
757+
connection
758+
.consumerBuilder()
759+
.queue(q)
760+
.messageHandler(
761+
(ctx, msg) -> {
762+
message.set(msg);
763+
ctx.accept();
764+
consumeSync.down();
765+
})
766+
.build();
767+
assertThat(consumeSync).completes();
768+
assertThat(message.get()).hasProperty("key1", -1L);
769+
}
770+
740771
private static String uuid() {
741772
return UUID.randomUUID().toString();
742773
}

0 commit comments

Comments
 (0)