@@ -803,18 +803,28 @@ private void checkHasValue(ValidationSettings settings, StringField field) {
803803 }
804804 }
805805
806- /** Check if group count matches number of groups in **/
806+ /**
807+ * Check if group count matches number of groups in message. *
808+ */
807809 private void checkGroupCount (StringField field , FieldMap fieldMap , String msgType ) {
808810 final int fieldNum = field .getField ();
809811 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 );
814818 }
815819 }
816820 }
817821
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+
818828 /** Check if a message has all required fields. **/
819829 void checkHasRequired (FieldMap header , FieldMap body , FieldMap trailer , String msgType ,
820830 boolean bodyOnly ) {
@@ -972,7 +982,12 @@ private void load(InputStream inputStream, DocumentBuilderFactory factory) throw
972982 throw new ConfigError ("<field> " + name + " does not have a number attribute" );
973983 }
974984
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+ }
976991
977992 final String type = getAttribute (fieldNode , "type" );
978993 if (type == null ) {
@@ -1068,8 +1083,8 @@ private void load(InputStream inputStream, DocumentBuilderFactory factory) throw
10681083 private int getIntegerAttributeIfDefined (final Element documentElement , final String attribute ) throws ConfigError {
10691084 try {
10701085 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 ) {
10731088 throw new ConfigError ("Attribute " + attribute + " could not be parsed as Integer." , e );
10741089 }
10751090 }
0 commit comments