From f83f986794cbdba8e0c33d36a9c3bd3fd66abb17 Mon Sep 17 00:00:00 2001 From: Zach Bray Date: Thu, 26 Sep 2024 23:33:24 +0100 Subject: [PATCH] [Java] Fix bug in DTO `decodeFrom` signature. It was using `short` for `actingVersion` and `blockLength`, but the inner call to `Decoder#wrap` expects an `int` (in the `uint16` range) for both arguments. There were a bunch of down/narrowing casts in tests, which I should have spotted when doing the port and have now been removed. --- .../co/real_logic/sbe/generation/java/JavaDtoGenerator.java | 2 +- .../uk/co/real_logic/sbe/properties/DtosPropertyTest.java | 6 +++--- .../java/uk/co/real_logic/sbe/generation/java/DtoTest.java | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaDtoGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaDtoGenerator.java index 9b22f240f6..b922bd14ed 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaDtoGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaDtoGenerator.java @@ -470,7 +470,7 @@ private static void generateDecodeFrom( .append("\n") .append(indent).append("public static ").append(dtoClassName).append(" decodeFrom(") .append("DirectBuffer buffer, int offset, ") - .append("short actingBlockLength, short actingVersion)\n") + .append("int actingBlockLength, int actingVersion)\n") .append(indent).append("{\n") .append(indent).append(INDENT).append(decoderClassName).append(" decoder = new ") .append(decoderClassName).append("();\n") diff --git a/sbe-tool/src/propertyTest/java/uk/co/real_logic/sbe/properties/DtosPropertyTest.java b/sbe-tool/src/propertyTest/java/uk/co/real_logic/sbe/properties/DtosPropertyTest.java index 93508ad709..8df61fe2b3 100644 --- a/sbe-tool/src/propertyTest/java/uk/co/real_logic/sbe/properties/DtosPropertyTest.java +++ b/sbe-tool/src/propertyTest/java/uk/co/real_logic/sbe/properties/DtosPropertyTest.java @@ -101,7 +101,7 @@ void javaDtoEncodeShouldBeTheInverseOfDtoDecode( generatedClassLoader.loadClass(packageName + ".TestMessageDto"); final Method decodeFrom = - dtoClass.getMethod("decodeFrom", DirectBuffer.class, int.class, short.class, short.class); + dtoClass.getMethod("decodeFrom", DirectBuffer.class, int.class, int.class, int.class); final Method encodeWith = dtoClass.getMethod("encodeWithHeaderWith", dtoClass, MutableDirectBuffer.class, int.class); @@ -109,8 +109,8 @@ void javaDtoEncodeShouldBeTheInverseOfDtoDecode( final int inputLength = encodedMessage.length(); final ExpandableArrayBuffer inputBuffer = encodedMessage.buffer(); final MessageHeaderDecoder header = new MessageHeaderDecoder().wrap(inputBuffer, 0); - final short blockLength = (short)header.blockLength(); - final short actingVersion = (short)header.version(); + final int blockLength = header.blockLength(); + final int actingVersion = header.version(); final Object dto = decodeFrom.invoke(null, encodedMessage.buffer(), MessageHeaderDecoder.ENCODED_LENGTH, blockLength, actingVersion); outputBuffer.setMemory(0, outputBuffer.capacity(), (byte)0); diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/DtoTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/DtoTest.java index a28b0ac374..68b2fdce83 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/DtoTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/DtoTest.java @@ -56,8 +56,7 @@ void shouldRoundTripCar2() final ExpandableArrayBuffer inputBuffer = new ExpandableArrayBuffer(); final int inputLength = encodeCar(inputBuffer, 0); - final CarDto dto = - CarDto.decodeFrom(inputBuffer, 0, (short)CarDecoder.BLOCK_LENGTH, (short)CarDecoder.SCHEMA_VERSION); + final CarDto dto = CarDto.decodeFrom(inputBuffer, 0, CarDecoder.BLOCK_LENGTH, CarDecoder.SCHEMA_VERSION); final ExpandableArrayBuffer outputBuffer = new ExpandableArrayBuffer(); final int outputLength = CarDto.encodeWith(dto, outputBuffer, 0);