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

When binding directly to fields (binder.initDirectFieldAccess()), @DateTimeFormat fails [SPR-6396] #11062

Closed
spring-projects-issues opened this issue Nov 19, 2009 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Ronald Tetsuo Miura opened SPR-6396 and commented

When binding directly to fields (binder.initDirectFieldAccess()), @DateTimeFormat fails.

It works fine when binding to bean properties.

Stack trace:

java.lang.IllegalArgumentException: Invalid format: "10/10/2005" is too short
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:673)
at org.springframework.format.datetime.joda.DateTimeParser.parse(DateTimeParser.java:43)
at org.springframework.format.datetime.joda.DateTimeParser.parse(DateTimeParser.java:1)
at org.springframework.format.support.FormattingConversionService$ParserConverter.convert(FormattingConversionService.java:193)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:32)
at org.springframework.core.convert.support.CollectionToObjectConverter.convert(CollectionToObjectConverter.java:101)
at org.springframework.core.convert.support.ArrayToObjectConverter.convert(ArrayToObjectConverter.java:38)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:32)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:182)
at org.springframework.format.support.FormattingConversionService.convert(FormattingConversionService.java:133)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:179)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:121)
at org.springframework.beans.DirectFieldAccessor.setPropertyValue(DirectFieldAccessor.java:126)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:50)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:635)
at org.springframework.validation.DataBinder.doBind(DataBinder.java:540)
at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:190)
at org.springframework.web.bind.support.WebRequestDataBinder.bind(WebRequestDataBinder.java:105)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:744)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:293)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:161)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:378)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:366)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.initDirectFieldAccess(); // works if I comment this line
}
public static class Param {
    public String descricao;
    @DateTimeFormat(pattern = "dd/MM/yyyy")
    public Date dataCriacao;
    public String getDescricao() {
        return descricao;
    }
    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }
    public Date getDataCriacao() {
        return dataCriacao;
    }
    public void setDataCriacao(Date dataCriacao) {
        this.dataCriacao = dataCriacao;
    }
}

Affects: 3.0 RC2

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Thanks for raising this! We had a gap in our annotation introspection for the direct field access scenario there... Sorted out for 3.0 final.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants