-
Notifications
You must be signed in to change notification settings - Fork 38.5k
@Validated occasionally throws ConstraintDeclarationException from Hibernate Validator on JDK 15 #26149
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
Comments
There seems to be a Hibernate configuration property With respect to your scenario specifically, the JVM could potentially use different method handles for the proxy invocation, e.g. sometimes the interface method handle and sometimes the proxy class method handle. Maybe Hibernate Validator misidentifies a proxy class method handle as a parallel method hierarchy? Might be worth reporting to them as well. |
Thanks for your reply! I will test that configuration property and see how it goes (for some time, to be sure). I'll report back in a few weeks then. In addition, I'll raise an issue with Hibernate Validator. |
Sorry for asking a potentially trivial question, but how could I set that property in my |
At the core level, we got a |
At this time, a custom |
Thanks again to both of you for helping. I was thinking that I'd like to keep the current Boot autoconfiguration (for one, so that the application behaves the same, and also so that any later modifications to the autoconfiguration will automatically become available to the application, too). So I first tried to inject the @Configuration
public class ValidatorConfig
{
@Bean
public LocalValidatorFactoryBean validatorAllowingParallelMethodParameterConstraints()
{
LocalValidatorFactoryBean defaultValidator = ValidationAutoConfiguration.defaultValidator();
Properties properties = new Properties();
properties.put( HibernateValidatorConfiguration.ALLOW_PARALLEL_METHODS_DEFINE_PARAMETER_CONSTRAINTS, "true" );
defaultValidator.setValidationProperties( properties );
return defaultValidator;
}
} Since |
A quick update: We'll try to do something about this by default. Could you please confirm which JDK you're running on there? Is it by any chance >8 in which case it might be a regression that happens only on newer JDKs (while working reliably on 8)? Or are you seeing the effect on JDK 8 as well? |
Those exceptions always occured on JDK 11. Unfortunately, I can't tell if it already happens with JDK 8 because we've been using 11 for a while already. And I'm afraid that trying to reproduce it now with 8 would prove to be difficult because it only happened so rarely (and that particular application requires 11+ anyway). |
Thanks for the quick reply, that's very helpful for a start. We are seeing similar exceptions on our JDK 15 CI build at the moment, never seen on JDK 8 CI before, so it looks like a JDK 11+ regression to me. |
My last comment wasn't correct: In fact, we've already been using JDK 15 as runtime environment for a couple of weeks, too. I was under the impression that the exceptions may have occured before we made the move from 11 to 15, but actually this is already outside our log retention period of 30 days. So at this point, I cannot say if it was introduced with 11 or 15 (let alone 8), but we're now witnessing it with 15, too. |
After debugging this down to the level of From that perspective, we won't try to work around it in our code (and it seems we cannot anyway). Thanks for your help in narrowing this! |
BTW here's the Hibernate Validator ticket for it: https://hibernate.atlassian.net/browse/HV-1801?focusedCommentId=107317 Apparently there's a workaround: adding the JVM flags |
I am having the same issue with openjdk:16-jdk-alpine in my docker image. |
Spring Boot 2.2.6, Spring Cloud Greenwich.RELEASE (I have since realized that I should be using the Hoxton branch with 2.2.x, which I have upgraded to now)
Following the suggestion from https://stackoverflow.com/questions/57811421/how-to-validate-request-parameters-on-feign-client/61635351#61635351, I can successfully use a validated Feign interface like this:
That is, this works most of the time. Very rarely, but then seemingly in bursts, the call to
triggerGpsLogFile
fails due to an exception like shown below. This application runs in a Kubernetes cluster and there are usually many thousands of calls to this method per day without the exception. Then one day, there are suddenly around 100 cases of theConstraintDeclarationException
within a time span of 10 minutes, only to be gone again afterwards.GpsService.triggerGpsLogFile()
makes the call toGpsClient.triggerGpsLogFile()
.Having read the relevant Hibernate Validator documentation and the source code of
ParallelMethodsMustNotDefineParameterConstraints
, I understand that Bean Validation method parameter annotations on overridden/implementing methods may pose a problem.And as @wilkinsona pointed out at spring-projects/spring-boot#17000,
@Validated
is realized by dynamic proxies (which can also be seen in the stacktrace above). So I kind of see why this could be a problem. But then I don't understand why the vast majority of calls work correctly, also throwing aConstraintViolationException
(note: Violation <-> Declaration) if applicable.I couldn't find any official documentation about using
@Validated
on a@FeignClient
, maybe that's for a reason and what I'm doing is basically unsupported?The text was updated successfully, but these errors were encountered: