We're updating the issue view to help you get more done. 

NPE w/ overloaded methods on class validated with MethodValidationInterceptor

Description

This has been spawned from a forum posting.
If a bean validated with the MethodValidationInterceptor has two methods with the same name that are prefixed with get/has/is, calling one of these methods will result in a NullPointerException.

1 2 3 4 5 6 7 8 java.lang.NullPointerException at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:846) at org.hibernate.validator.internal.engine.ValidatorImpl.validateAllParameters(ValidatorImpl.java:218) at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:88) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)

Code snippet example:
Problem experienced when calling following methods on method validated bean.

1 2 ValidatedObject getMyValidObject(arg1); ValidatedObject getMyValidObject(arg1, arg2);

Workaround:

1 2 ValidatedObject retrieveMyValidObject(arg1); ValidatedObject retrieveMyValidObject(arg1, arg2);

or:

1 2 ValidatedObject getMyValidObject(arg1); ValidatedObject getMyValidObjectDifferentMethodName(arg1, arg2);

I'm not aware of a workaround that doesn't involve having to change the interface!
A detailed description with some code references is available here:
https://forum.hibernate.org/viewtopic.php?f=9&t=1016470&p=2456768#p2456768

Environment

None

Status

Assignee

Gunnar Morling

Reporter

Louis Burton

Labels

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

4.3.0.Final

Priority

Major