ClassCast exception when creating Combined constraint

Description

See https://github.com/davidkarlsen/hibernate-validator/tree/HV-448 (never mind the naming of the branch - it was an old one - but changed to fit this issue).

I get

javax.validation.ValidationException: Unable to initialize org.hibernate.validator.constraints.impl.SizeValidatorForString at org.hibernate.validator.engine.ConstraintTree.initializeConstraint(ConstraintTree.java:444) at org.hibernate.validator.engine.ConstraintTree.createAndInitializeValidator(ConstraintTree.java:346) at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:317) at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:144) at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:117) at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:84) at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:473) at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:395) at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:376) at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:315) at org.hibernate.validator.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:634) at org.hibernate.validator.engine.ValidatorImpl.validateCascadedMethodConstraints(ValidatorImpl.java:532) at org.hibernate.validator.engine.ValidatorImpl.validateReturnValueForGroup(ValidatorImpl.java:1156) at org.hibernate.validator.engine.ValidatorImpl.validateReturnValueInContext(ValidatorImpl.java:1074) at org.hibernate.validator.engine.ValidatorImpl.validateReturnValue(ValidatorImpl.java:247) at org.hibernate.hv448.ValidationAspect.validateReturnedValue(ValidationAspect.java:129) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:603) at org.springframework.aop.aspectj.AspectJAfterReturningAdvice.afterReturning(AspectJAfterReturningAdvice.java:58) at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:51) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy16.proceedOkWithDefinedArg(Unknown Source) at org.hibernate.hv448.ValidationAspectTest.proceedOkWithDefinedArg(ValidationAspectTest.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.ClassCastException: $Proxy22 cannot be cast to javax.validation.constraints.Size at org.hibernate.validator.constraints.impl.SizeValidatorForString.initialize(SizeValidatorForString.java:30) at org.hibernate.validator.engine.ConstraintTree.initializeConstraint(ConstraintTree.java:441) ... 59 more

when validating with a composed constraint.

Environment

None

Activity

Gunnar MorlingMay 4, 2011 at 7:39 PM

I'm not sure about HV-450, have to see how much work this is slightly smiling face

David KarlsenMay 2, 2011 at 9:46 PM

My bad - closing.
BTW: Will https://hibernate.atlassian.net/browse/HV-450#icft=HV-450 be updated for 4.2 betas?

Gunnar MorlingApril 24, 2011 at 10:44 PM

David, there is a problem with your custom constraint @CompositeTest. This constraint references the validator type SizeValidatorForString within the @Constraint meta-annotation. This validator is a validator for the @Size annotation, you would have to reference a validator parametrized with the @CompositeTest annotation type instead. In case you want to create a constraint which is just composed from some other existing constraints but doesn't add any own validation logic, just use an empty array for the "validatedBy" attribute of the @Constraint meta-annotation.

Rejected

Details

Assignee

Reporter

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

David Karlsen
Gunnar Morling

Components

Affects versions

Priority

Created April 22, 2011 at 10:48 PM
Updated May 4, 2011 at 7:39 PM
Resolved May 4, 2011 at 7:38 PM

Flag notifications