Christopher Smith created GROOVY-10810:
------------------------------------------
Summary: 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
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)