@@ -803,18 +803,28 @@ private void checkHasValue(ValidationSettings settings, StringField field) {
803
803
}
804
804
}
805
805
806
- /** Check if group count matches number of groups in **/
806
+ /**
807
+ * Check if group count matches number of groups in message. *
808
+ */
807
809
private void checkGroupCount (StringField field , FieldMap fieldMap , String msgType ) {
808
810
final int fieldNum = field .getField ();
809
811
if (isGroup (msgType , fieldNum )) {
810
- if (fieldMap .getGroupCount (fieldNum ) != Integer .parseInt (field .getValue ())) {
811
- throw new FieldException (
812
- SessionRejectReason .INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP ,
813
- fieldNum );
812
+ try {
813
+ if (fieldMap .getGroupCount (fieldNum ) != IntConverter .convert (field .getValue ())) {
814
+ throwNewFieldException (fieldNum );
815
+ }
816
+ } catch (FieldConvertError ex ) {
817
+ throwNewFieldException (fieldNum );
814
818
}
815
819
}
816
820
}
817
821
822
+ private void throwNewFieldException (final int fieldNum ) throws FieldException {
823
+ throw new FieldException (
824
+ SessionRejectReason .INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP ,
825
+ fieldNum );
826
+ }
827
+
818
828
/** Check if a message has all required fields. **/
819
829
void checkHasRequired (FieldMap header , FieldMap body , FieldMap trailer , String msgType ,
820
830
boolean bodyOnly ) {
@@ -972,7 +982,12 @@ private void load(InputStream inputStream, DocumentBuilderFactory factory) throw
972
982
throw new ConfigError ("<field> " + name + " does not have a number attribute" );
973
983
}
974
984
975
- final int num = Integer .parseInt (number );
985
+ int num = 0 ;
986
+ try {
987
+ num = IntConverter .convert (number );
988
+ } catch (FieldConvertError ex ) {
989
+ throw new ConfigError (ex );
990
+ }
976
991
977
992
final String type = getAttribute (fieldNode , "type" );
978
993
if (type == null ) {
@@ -1068,8 +1083,8 @@ private void load(InputStream inputStream, DocumentBuilderFactory factory) throw
1068
1083
private int getIntegerAttributeIfDefined (final Element documentElement , final String attribute ) throws ConfigError {
1069
1084
try {
1070
1085
return documentElement .hasAttribute (attribute )
1071
- ? Integer . parseInt (documentElement .getAttribute (attribute )) : 0 ;
1072
- } catch (NumberFormatException e ) {
1086
+ ? IntConverter . convert (documentElement .getAttribute (attribute )) : 0 ;
1087
+ } catch (FieldConvertError e ) {
1073
1088
throw new ConfigError ("Attribute " + attribute + " could not be parsed as Integer." , e );
1074
1089
}
1075
1090
}
0 commit comments