Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenericConversionService.convert() throws IllegalArgumentException after updating to Spring 3.2.1 [SPR-10243] #14876

Closed
spring-projects-issues opened this issue Jan 30, 2013 · 3 comments
Assignees
Labels
type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jan 30, 2013

Phil Webb opened SPR-10243 and commented

After updating Spring from 3.2.0.RELEASE to 3.2.1.RELEASE I've got following error:

[skip]
java.lang.IllegalArgumentException: The source to convert from must be an instance of @org.hibernate.validator.constraints.NotEmpty @javax.validation.constraints.Size @javax.validation.constraints.Pattern java.lang.String; instead it was a ru.mystamps.web.model.ActivateAccountForm
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:164)
    at org.springframework.validation.AbstractPropertyBindingResult.formatFieldValue(AbstractPropertyBindingResult.java:125)
    at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:222)
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)
    at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:130)
    at org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:120)
    at org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:90)
    at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:103)
    at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
    at org.apache.jsp.WEB_002dINF.tiles.body.account.activate_jsp._jspx_meth_form_label_2(activate_jsp.java:667)
    at org.apache.jsp.WEB_002dINF.tiles.body.account.activate_jsp._jspService(activate_jsp.java:224)
[skip]

JSP code:

<form:form method="post" action="${activateUrl}" modelAttribute="activateAccountForm">
    <form:label path="login">
        <spring:message code="t_login" />
    </form:label>
    ...
</form:form>

Model declaration:

public class ActivateAccountForm implements ActivateAccountDto {                                    

    @NotEmpty(groups = Login1Checks.class)                                                          
    @Size.List({                                                                                    
        @Size(                                                                                      
            min = ValidationRules.LOGIN_MIN_LENGTH,                                                 
            message = "{value.too-short}",                                                          
            groups = Login2Checks.class                                                             
        ),                                                                                          
        @Size(                                                                                      
            max = ValidationRules.LOGIN_MAX_LENGTH,                                                 
            message = "{value.too-long}",                                                           
            groups = Login2Checks.class                                                             
        )                                                                                           
    })                                                                                              
    @Pattern(                                                                                       
        regexp = ValidationRules.LOGIN_REGEXP,                                                      
        message = "{login.invalid}",                                                                
        groups = Login3Checks.class                                                                 
    )                                                                                               
    @UniqueLogin(groups = Login4Checks.class)                                                       
    private String login;

    ...
}

Controller:

@RequestMapping(value = Url.ACTIVATE_ACCOUNT_PAGE, method = RequestMethod.POST)                 
public String processActivationForm(                                                            
    @Validated({                                                                                
        LoginChecks.class, NameChecks.class, PasswordChecks.class,                              
        PasswordConfirmationChecks.class, ActKeyChecks.class, FormChecks.class                  
    }) ActivateAccountForm form, BindingResult result) {                                        

    if (result.hasErrors()) {                                                                   
        return null;                                                                            
    }                                                                                           

    userService.registerUser(form);                                                             

    return "redirect:" + Url.SUCCESSFUL_ACTIVATION_PAGE;                                        
}

Affects: 3.2.1

Reference URL: http://stackoverflow.com/questions/14522260/genericconversionservice-convert-throws-illegalargumentexception-after-updatin

Issue Links:

  • #13970 SpringValidatorAdapter is incorrectly resolving rejected value for bean based field level constraints
  • #14979 SpringValidationAdapter cannot handle disabled default constraint violation
  • #19648 Spring validation crashes with Hibernate Validation 5 style list constraint violations
  • #20725 NumberFormatException caused by property paths from JSR-303 based validation with no index into a collection

Referenced from: commits cef9781, 19eecb1

0 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 30, 2013

Phil Webb commented

I am having trouble replicating the issue. There is a sample project here https://github.com/SpringSource/spring-framework-issues/tree/master/SPR-10243 that does not appear to fail.

Does the original project include any additional validation on the ActivateAccountForm class? What does the LoginChecks class look like?

If possible could you take a look at the sample project and try to get it to replicate the issue.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 10, 2013

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 11, 2013

Juergen Hoeller commented

Fixed through applying both checks for retrieving the raw field value now: the previous one that we had in 3.2 GA and the new one from 3.2.1 (#13970).

In both cases, Bean Validation doesn't expose the right value to us, so we need to fall back to manually retrieving the raw field value from the target bean.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

2 participants