[
https://issues.apache.org/jira/browse/GROOVY-10810?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17720570#comment-17720570
]
Christopher Smith commented on GROOVY-10810:
--------------------------------------------
I ran into this problem again with a similar use case. I believe that the trait
processing should copy property annotations onto the public accessors ({{String
getText()}}) on either or both of the trait interface or the implementing class
instead of onto the synthetic accessors ({{__text$get()}}. [~emilles]
> Spring Validator error when validating trait-added property
> -----------------------------------------------------------
>
> Key: GROOVY-10810
> URL: https://issues.apache.org/jira/browse/GROOVY-10810
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 4.0.6
> Reporter: Christopher Smith
> Priority: Major
>
> I am not certain that this is not a Spring bug, but I'm starting here.
> I have this arrangement:
> {code:groovy}
> class ErrorInfo {
> @NotBlank String code
> @NotNull Instant timestamp
> }
> trait HasErrorInfo {
> @NotNull @Valid ErrorInfo errorInfo
> }
> class ErrorMessage implements HasErrorInfo {
> String text
> }
> {code}
> On a validation failure ({{timestamp}} is null), Spring throws an exception:
> {code}
> java.lang.IllegalStateException: JSR-303 validated property
> 'data.attributes.com_example_HasErrorInfo__errorInfo.timestamp' does not have
> a corresponding accessor for Spring data binding - check your DataBinder's
> configuration (bean property versus direct field access)
> at
> org.springframework.validation.beanvalidation.SpringValidatorAdapter.processConstraintViolations(SpringValidatorAdapter.java:188)
> at
> org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:109)
> at
> org.springframework.boot.autoconfigure.validation.ValidatorAdapter.validate(ValidatorAdapter.java:66)
> at org.springframework.validation.DataBinder.validate(DataBinder.java:933)
> ...
> {code}
> It seems the problem is a result of Spring's introspection of JSR-303 results.
> I note on inspecting javap that although I have a method {{ErrorInfo
> getErrorInfo()}}, the JSR-303 annotations were not applied to that JavaBeans
> getter but instead to the synthetic method {{ErrorInfo
> com_example_HasErrorInfo__errorInfo$get()}}, which seems like a mistargeting.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)