Uploaded image for project: 'Spring Web Flow'
  1. Spring Web Flow
  2. SWF-1389

MessageContextErrors doesn't obey the Errors contract

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.2.0.RC1
    • Component/s: None
    • Labels:
      None

      Description

      As explained in the above forum thread, MessageContextErrors throws a runtime exception when any class-level JSR-303 @Constraints are violated. The bug is in the rejectValue method:

      MessageContextErrors#rejectValue(String, String, Object[], String)
      public void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage) {
      	field = fixedField(field);
      	Class fieldType;
      	if (expressionParser != null) {
      		FluentParserContext parserContext = new FluentParserContext().evaluate(boundObject.getClass());
                      // Bug! Next line assumes field is not blank; Errors contract says it CAN be blank
      		fieldType = expressionParser.parseExpression(field, parserContext).getValueType(boundObject);
      	} else {
      		...
      	}
      	...
      }

      As indicated in the comment marked "Bug!", the problem is that the above method expects the "field" argument not to be blank, even though the Errors contract says that it can be (to indicate a global error).

      One (the only?) effect of this bug is that class-level JSR-303 constraints do not work properly in Spring Web Flow applications that perform validation by delegating to the Spring JSR-303 validation logic.

      Anyone experiencing this bug can work around it by subclassing SpringValidatorAdapter (or LocalValidatorFactoryBean if that's what you're currently using) and overriding validate(Object target, Errors errors) it so that it calls Errors#reject(String errorCode, Object[] errorArgs, String defaultMessage) in the case of any class-level violations (i.e. where the field name is blank). I'll provide some sample code in the forum thread.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              aswan Andrew Swan
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: