From b8ac926f0aba3807d43fd30e6c3b336bd310a45f Mon Sep 17 00:00:00 2001 From: mjpt777 Date: Thu, 18 Jan 2024 17:21:20 +0000 Subject: [PATCH] Captured types in IR should be for the minimum version used in a schema. Issue #967. --- .../main/java/uk/co/real_logic/sbe/ir/Ir.java | 9 ++++++- .../sbe/ir/SinceVersionValidationTest.java | 19 ++++++++++++++ sbe-tool/src/test/resources/issue967.xml | 25 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 sbe-tool/src/test/resources/issue967.xml diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Ir.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Ir.java index 0485f9a903..3587a8a05f 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Ir.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Ir.java @@ -328,7 +328,14 @@ private int captureType( while (endSignal != token.signal() || !name.equals(token.name())); updateComponentTokenCounts(typeTokens); - typesByNameMap.put(null == referencedName ? name : referencedName, typeTokens); + + final String typeName = null == referencedName ? name : referencedName; + final List existingTypeTokens = typesByNameMap.get(typeName); + + if (null == existingTypeTokens || existingTypeTokens.get(0).version() > typeTokens.get(0).version()) + { + typesByNameMap.put(typeName, typeTokens); + } return i; } diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/ir/SinceVersionValidationTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/ir/SinceVersionValidationTest.java index d0bf85fb41..a2223ced19 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/ir/SinceVersionValidationTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/ir/SinceVersionValidationTest.java @@ -16,10 +16,15 @@ package uk.co.real_logic.sbe.ir; import org.junit.jupiter.api.Test; +import uk.co.real_logic.sbe.xml.IrGenerator; +import uk.co.real_logic.sbe.xml.MessageSchema; import uk.co.real_logic.sbe.xml.ParserOptions; import java.io.InputStream; +import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.lessThan; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; import static uk.co.real_logic.sbe.Tests.getLocalResource; @@ -43,4 +48,18 @@ void shouldErrorOnTypeWithGreaterSinceVersion() throws Exception fail("expected IllegalStateException"); } + + @Test + void shouldApplySinceVersionOnComposites() throws Exception + { + try (InputStream in = getLocalResource("issue967.xml")) + { + final MessageSchema schema = parse(in, ParserOptions.DEFAULT); + final IrGenerator irg = new IrGenerator(); + final Ir ir = irg.generate(schema); + + final List priceNull9Tokens = ir.getType("PRICENULL9"); + assertThat(priceNull9Tokens.get(0).version(), lessThan(13)); + } + } } diff --git a/sbe-tool/src/test/resources/issue967.xml b/sbe-tool/src/test/resources/issue967.xml new file mode 100644 index 0000000000..2190821b61 --- /dev/null +++ b/sbe-tool/src/test/resources/issue967.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + -9 + + + + + + + \ No newline at end of file