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
MethodValidationPostProcessor fails for certain generic method signatures when running against Hibernate Validator 5 [SPR-12237] #22186
Comments
Juergen Hoeller commented Could you post the full stacktrace please? This could be an issue with the proxy/implementation mismatch in case of a JDK proxy... Switching to proxyTargetClass=true might help. It could also be an internal problem in Hibernate Validator itself; we'll see. Juergen |
Adam McCormick commented Here's the full stack trace:
|
Nishant Niranjan commented I was facing similar issue , while I used hibernate-validator-annotation-processor-5.0.1.Final.jar and |
Eugeniu Rabii commented I hate to be mean, but it's one year since this has been opened. There are no updates? I can re-produce this one with latest spring/hibernate. |
Juergen Hoeller commented This seems to be an issue in Hibernate Validator itself since different HV versions apparently exhibit different behavior here. If we can do something about it from Spring's side, in our Juergen |
Eugeniu Rabii commented I did report : https://hibernate.atlassian.net/browse/HV-1011 and they gave one of their samples as a response which I can't get to re-produce the error. On the other had, it is easy to reproduce on spring side. Again, I don't want to be mean - but that seems like your issue. A small example that proves this:
The root cause of the problem seems to be here:
I am not that versatile to understand what is going on actually; but seems like some information is lost/un-matched because of some proxing. |
Juergen Hoeller commented The problem with the test case reported to HV is that it was obtaining the concrete declared method on the implementation class; this will obviously work. However, when coming in through a generic bridge method on the interface (which may happen with an interface-based proxy), HV seems to be stuck. Anyway, we'll try to resolve the bridge method on Spring's side... Juergen |
Juergen Hoeller commented As far as I was able to reproduce this, it only happens against Hibernate Validator 5 (more specifically, 5.2.1, using the standard BV 1.1 API for method validation) but not against Hibernate Validator 4 (i.e. 4.3.1, using HV's native method validation API). It can be enforced by performing the method call on a raw declaration of the service interface, calling the T (Object) variant of the method and therefore going through the generated bridge method on the implementation class. Juergen |
Juergen Hoeller commented In other words, the test case in HV-1011 should fail once the method is retrieved like this:
|
Juergen Hoeller commented I'm afraid there is no clean way to resolve this on Spring's side if the validation metadata lives in a generic interface. We have to pass a variant of that interface method into the validation engine, otherwise that engine may not find the validation metadata. We are more flexible there on Java 8 where annotations are being preserved across bridge methods, while it's almost bound to fail on Java 6 or 7 in some scenarios, also depending on the BV provider etc. In the end, Hibernate Validator should accept a given bridge method in such an interface scenario, as outlined above. For the time being, I've put a workaround in place where, in case of the regular attempt failing, we resolve the bridge method on the implementation class and call the validation engine once more with this resolved method. We cannot do this by default since it's quite a guess across Bean Validation providers and JVMs, but since it does make those tests pass with Hibernate Validator 5.2.1 on Java 8, it's worth that workaround at least. So in summary, from my perspective, HV-1011 should get addressed on Hibernate Validator's side, but we do have a workaround in place as of Spring 4.2.1 which hopefully addresses your case as well. Please give the upcoming Juergen |
Eugeniu Rabii commented
|
Juergen Hoeller commented Thanks for the heads-up, Eugeniu Rabii. The workaround doesn't hurt since it's just a fallback for a case that otherwise would fail immediately... So I guess I'll leave it in place for the time being, not least of it all for working with older HV 5.x versions (and 5.2.2 isn't out yet anyway). Juergen |
Adam McCormick opened SPR-12237 and commented
I am trying to validate service layer method arguments using the
MethodValidationPostProcessor
. This is failing on, what appears to be, different the method signatures.With an interface such as:
And the following implementation:
Validation works fine when calling
update(String, Item)
but throws the following exception when callingcreate(Item)
:This is also working fine if
Service<T>
is an abstract class and I just extend it.Attached is a sample application that demonstrates the problem.
Affects: 4.0.6
Attachments:
Referenced from: commits 7118fcf
3 votes, 8 watchers
The text was updated successfully, but these errors were encountered: