I have code that has validations like the following.
In the test setup, when i pass a null value to this method, there is an exception.
@Validated
public class MyTestClass {
public String testMethod(@NotNull String testValue){
if (StringUtils.isBlank(testValue)) {
throw new Exception("value is null");
}
}
}
The exception looks like this:
javax.validation.ConstraintViolationException: testMethod.testValue: must not be null
at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:116)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
However, when i run the same test in Spring Boot 2.0.8, the exception looks like this:
.Exception: value is null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:197)
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:180)
I debugged why this is happening, and the only conclusion i could derive is that invoke(MethodValidationInterceptor
is invoked only in case of Spring Boot 2.3.4 and not in Spring Boot 2.0.8.
The version of javax.validation
being used is the same in both the cases.
Can you please help me understand why this happens and if this is an expected change in behavior?
Comment From: snicoll
Unfortunately, without a sample that we can use to replicate the behavior we won't be able to help. Can you please share a small sample we can run ourselves? You can do so by attaching a zip to this issue or pushing the code to a GitHub repository.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.