From 1c47c43cc5350850301a209c366c1d50e7965a83 Mon Sep 17 00:00:00 2001 From: jonfreedman Date: Tue, 31 Jul 2018 10:39:31 +0100 Subject: [PATCH 1/2] do not throw IncorrectDataFormat exception if value is empty and ValidateFieldsHaveValues=N --- .../main/java/quickfix/DataDictionary.java | 3 +++ .../java/quickfix/DataDictionaryTest.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/quickfixj-core/src/main/java/quickfix/DataDictionary.java b/quickfixj-core/src/main/java/quickfix/DataDictionary.java index d41d9ffbf0..6fd4e3f535 100644 --- a/quickfixj-core/src/main/java/quickfix/DataDictionary.java +++ b/quickfixj-core/src/main/java/quickfix/DataDictionary.java @@ -697,6 +697,9 @@ private void checkValidFormat(StringField field) throws IncorrectDataFormat { if (fieldType == null) { return; } + if (field.getValue().length() == 0 && !checkFieldsHaveValues) { + return; + } try { switch (fieldType) { case STRING: diff --git a/quickfixj-core/src/test/java/quickfix/DataDictionaryTest.java b/quickfixj-core/src/test/java/quickfix/DataDictionaryTest.java index 520361d94d..eb73d9f279 100644 --- a/quickfixj-core/src/test/java/quickfix/DataDictionaryTest.java +++ b/quickfixj-core/src/test/java/quickfix/DataDictionaryTest.java @@ -27,6 +27,7 @@ import quickfix.field.BodyLength; import quickfix.field.CheckSum; import quickfix.field.ClOrdID; +import quickfix.field.EffectiveTime; import quickfix.field.HandlInst; import quickfix.field.LastMkt; import quickfix.field.MsgSeqNum; @@ -781,6 +782,29 @@ public void testGroupWithReqdComponentWithReqdFieldValidation() throws Exception dictionary.validate(quoteRequest, true); } + /** + * Field EffectiveTime(168) is defined as UTCTIMESTAMP so an empty string value is invalid but if we allow blank values that should not fail + * validation + * @throws Exception + */ + @Test + public void testAllowingBlankValuesDisablesFieldValidation() throws Exception { + final DataDictionary dictionary = getDictionary(); + dictionary.setCheckFieldsHaveValues(false); + final quickfix.fix44.NewOrderSingle newSingle = new quickfix.fix44.NewOrderSingle( + new ClOrdID("123"), new Side(Side.BUY), new TransactTime(), new OrdType(OrdType.LIMIT) + ); + newSingle.setField(new OrderQty(42)); + newSingle.setField(new Price(42.37)); + newSingle.setField(new HandlInst()); + newSingle.setField(new Symbol("QFJ")); + newSingle.setField(new HandlInst(HandlInst.MANUAL_ORDER_BEST_EXECUTION)); + newSingle.setField(new TimeInForce(TimeInForce.DAY)); + newSingle.setField(new Account("testAccount")); + newSingle.setField(new StringField(EffectiveTime.FIELD)); + dictionary.validate(newSingle, true); + } + // // Group Validation Tests in RepeatingGroupTest // From e45dc2a626efc6b307e8337c6f384e2619624467 Mon Sep 17 00:00:00 2001 From: Christoph John Date: Tue, 31 Jul 2018 14:04:25 +0200 Subject: [PATCH 2/2] micro-optimization Flipped operands of if-clause to avoid testing each field's length when checkFieldsHaveValues is enabled (should be the normal case) (length has already been tested before in checkHasValue()). --- quickfixj-core/src/main/java/quickfix/DataDictionary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickfixj-core/src/main/java/quickfix/DataDictionary.java b/quickfixj-core/src/main/java/quickfix/DataDictionary.java index 6fd4e3f535..f9579064ca 100644 --- a/quickfixj-core/src/main/java/quickfix/DataDictionary.java +++ b/quickfixj-core/src/main/java/quickfix/DataDictionary.java @@ -697,7 +697,7 @@ private void checkValidFormat(StringField field) throws IncorrectDataFormat { if (fieldType == null) { return; } - if (field.getValue().length() == 0 && !checkFieldsHaveValues) { + if (!checkFieldsHaveValues && field.getValue().length() == 0) { return; } try {