Skip to content

Commit

Permalink
fix an issue where values of required temporal fields would get retained
Browse files Browse the repository at this point in the history
 on decoders after reset

This should rarely be a problem, considering they are required.
  • Loading branch information
wojciech-adaptive committed Jun 12, 2024
1 parent a3991c9 commit 61f23b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ protected boolean hasFlag(final Entry entry, final Field field)

protected String resetTemporalValue(final String name)
{
return resetNothing(name);
return resetStringBasedData(name);
}

protected String resetComponents(final List<Entry> entries, final StringBuilder methods)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,6 @@ protected String hasField(final Entry entry)
String.format(" %2$s boolean has%1$s;\n\n", name, scope);
}

protected String resetNothing(final String name)
{
return String.format(
" public void %1$s()\n" +
" {\n" +
" }\n\n",
nameOfResetMethod(name));
}

private boolean isNotResettableField(final String name)
{
return isDerivedField(name) || isPreCalculatedField(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public final class ExampleDictionary
public static final String INT_ENUM_RF = "IntEnumRF";
public static final String CHAR_ENUM_RF = "CharEnumRF";
public static final String CURRENCY_ENUM_RF = "CurrencyEnumRF";
public static final String UTC_TIMESTAMP_RF = "UtcTimestampRF";

public static final String STRING_ENUM_REQ = "stringEnumReq";
public static final String INT_ENUM_REQ = "intEnumReq";
Expand Down Expand Up @@ -454,7 +455,7 @@ public final class ExampleDictionary

public static final String RF_ALL_FIELDS =
"8=FIX.4.4\0019=0057\00135=Z\001700=one\001701=10\001702=b\001703=123.456\001" +
"704=one\001705=10\001706=b\001707=GBP\00110=209\001";
"704=one\001705=10\001706=b\001707=GBP\001708=20240611-14:35:58.012\00110=209\001";

public static final String RF_NO_FIELDS =
"8=FIX.4.4\0019=0049\00135=Z\00110=209\001";
Expand Down Expand Up @@ -706,6 +707,7 @@ private static Dictionary buildMessageExample()
.addValue("a", "APPLE").addValue("b", "BANANA"));
allReqFieldTypesMessage.requiredEntry(registerField(messageEgFields, 707, CURRENCY_ENUM_RF, CURRENCY)
.addValue("USD", "US_Dollar").addValue("GBP", "Pound"));
allReqFieldTypesMessage.requiredEntry(registerField(messageEgFields, 708, UTC_TIMESTAMP_RF, UTCTIMESTAMP));

final Message anyFieldsMessage = new Message(ANY_FIELDS_MESSAGE_NAME, ANY_FIELDS_MESSAGE_TYPE, "app");
anyFieldsMessage.requiredEntry(registerField(messageEgFields, 5005, "LongField2", LONG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ public void shouldNotRetainStringFromPreviousMessagesForRequiredFieldsWhenReset(
assertEquals("", getMethod(decoder, STRING_RF + "AsString"));
}

@Test
public void shouldNotRetainUtcTimestampFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable
{
final Decoder decoder = createRequiredFieldMessageDecoder();
decode(RF_ALL_FIELDS, decoder);
assertEquals("20240611-14:35:58.012", getMethod(decoder, UTC_TIMESTAMP_RF + "AsString"));

decoder.reset();
decode(RF_NO_FIELDS, decoder);
assertEquals("", getMethod(decoder, UTC_TIMESTAMP_RF + "AsString"));
}

@Test
public void shouldNotRetainIntegerFromPreviousMessagesForRequiredFieldsWhenReset() throws Throwable
{
Expand Down

0 comments on commit 61f23b0

Please sign in to comment.