javax.validation.ConstraintDeclarationException: HV000131: A method return value must not be marked for cascaded validation more than once in a class hierarchy, but the following two methods are marked as such: public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService$Proxy$_$$_WeldSubclass.createValidEvent(), public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService.createValidEvent().

Hibernate JIRA | Gunnar Morling | 4 years ago
  1. 0

    Weld creates proxy sub-classes for intercepted classes, re-declaring any annotations declared on the proxied super-class. For return values marked for cascaded validation this causes an exception because a return value must not be marked more than once as cascaded per hierarchy line: {code} javax.validation.ConstraintDeclarationException: HV000131: A method return value must not be marked for cascaded validation more than once in a class hierarchy, but the following two methods are marked as such: public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService$Proxy$_$$_WeldSubclass.createValidEvent(), public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService.createValidEvent(). at org.hibernate.validator.internal.metadata.aggregated.rule.ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.apply(ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.java:33) at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.assertCorrectnessOfConfiguration(ExecutableMetaData.java:443) at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:361) {code} For parameter constraints we circumvented the problem by checking whether any constraints on overriding methods resemble the constraints on the supertype method. For return values this can't be done in the same way, since there is an explicit TCK test expecting an exception when a return value is marked as cascaded several times. The only way I see around this is to try to detect proxy classes and ignore any cascaded markers on them as discussed in HV-754.

    Hibernate JIRA | 4 years ago | Gunnar Morling
    javax.validation.ConstraintDeclarationException: HV000131: A method return value must not be marked for cascaded validation more than once in a class hierarchy, but the following two methods are marked as such: public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService$Proxy$_$$_WeldSubclass.createValidEvent(), public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService.createValidEvent().
  2. 0

    Weld creates proxy sub-classes for intercepted classes, re-declaring any annotations declared on the proxied super-class. For return values marked for cascaded validation this causes an exception because a return value must not be marked more than once as cascaded per hierarchy line: {code} javax.validation.ConstraintDeclarationException: HV000131: A method return value must not be marked for cascaded validation more than once in a class hierarchy, but the following two methods are marked as such: public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService$Proxy$_$$_WeldSubclass.createValidEvent(), public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService.createValidEvent(). at org.hibernate.validator.internal.metadata.aggregated.rule.ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.apply(ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.java:33) at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.assertCorrectnessOfConfiguration(ExecutableMetaData.java:443) at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:361) {code} For parameter constraints we circumvented the problem by checking whether any constraints on overriding methods resemble the constraints on the supertype method. For return values this can't be done in the same way, since there is an explicit TCK test expecting an exception when a return value is marked as cascaded several times. The only way I see around this is to try to detect proxy classes and ignore any cascaded markers on them as discussed in HV-754.

    Hibernate JIRA | 4 years ago | Gunnar Morling
    javax.validation.ConstraintDeclarationException: HV000131: A method return value must not be marked for cascaded validation more than once in a class hierarchy, but the following two methods are marked as such: public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService$Proxy$_$$_WeldSubclass.createValidEvent(), public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService.createValidEvent().
  3. 0

    For a purely composed cross-parameter constraint (i.e. a constraint which has no own validator but is annotated with another cross-parameter constraint), the validation target needs to be retrieved from the composing constraint(s). Currently such a constraint causes the following exception: {code} javax.validation.ConstraintDeclarationException: HV000132: Void methods must not be constrained or marked for cascaded validation, but method public void org.hibernate.validator.test.internal.constraintvalidators.ScriptAssertValidatorTest$CalendarService.createCalendarEvent(java.lang.String,java.util.Date,java.util.Date) is. at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.checkReturnValueConfiguration(ExecutableMetaData.java:479) at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:362) at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataImpl$BuilderDelegate.build(BeanMetaDataImpl.java:601) at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataImpl$BeanMetaDataBuilder.build(BeanMetaDataImpl.java:508) at org.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.java:182) {code}

    Hibernate JIRA | 4 years ago | Gunnar Morling
    javax.validation.ConstraintDeclarationException: HV000132: Void methods must not be constrained or marked for cascaded validation, but method public void org.hibernate.validator.test.internal.constraintvalidators.ScriptAssertValidatorTest$CalendarService.createCalendarEvent(java.lang.String,java.util.Date,java.util.Date) is.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    For a purely composed cross-parameter constraint (i.e. a constraint which has no own validator but is annotated with another cross-parameter constraint), the validation target needs to be retrieved from the composing constraint(s). Currently such a constraint causes the following exception: {code} javax.validation.ConstraintDeclarationException: HV000132: Void methods must not be constrained or marked for cascaded validation, but method public void org.hibernate.validator.test.internal.constraintvalidators.ScriptAssertValidatorTest$CalendarService.createCalendarEvent(java.lang.String,java.util.Date,java.util.Date) is. at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.checkReturnValueConfiguration(ExecutableMetaData.java:479) at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:362) at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataImpl$BuilderDelegate.build(BeanMetaDataImpl.java:601) at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataImpl$BeanMetaDataBuilder.build(BeanMetaDataImpl.java:508) at org.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.java:182) {code}

    Hibernate JIRA | 4 years ago | Gunnar Morling
    javax.validation.ConstraintDeclarationException: HV000132: Void methods must not be constrained or marked for cascaded validation, but method public void org.hibernate.validator.test.internal.constraintvalidators.ScriptAssertValidatorTest$CalendarService.createCalendarEvent(java.lang.String,java.util.Date,java.util.Date) is.
  6. 0

    I have created a {{CustomMin}} constraint, which is an exact copy of {{javax.validation.constraints.Min as follows}}: {code:title=CustomMin.java} @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) @Retention(RUNTIME) @Documented @Constraint(validatedBy = { }) public @interface CustomMin { String message() default "{javax.validation.constraints.Min.message}"; Class<?>[] groups() default { }; Class<? extends Payload>[] payload() default { }; /** * @return value the element must be higher or equal to */ long value(); /** * Defines several {@link CustomMin} annotations on the same element. * * @see CustomMin */ @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) @Retention(RUNTIME) @Documented @interface List { CustomMin[] value(); } } {code} I am trying to validate parameters using the {{ExecutableValidator}} as follows: {code:title=TestValidator.java} package com.test.validation.constraints; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.ValidatorFactory; import javax.validation.constraints.Min; import javax.validation.executable.ExecutableValidator; import java.lang.reflect.Method; import java.util.Set; public class TestValidator { @CustomMin(1) public Integer test(@Min(1) Integer i) { return i; } public static void main(String[] args) throws Exception { TestValidator customerFacade = new TestValidator(); Method method = TestValidator.class.getMethod("test", Integer.class); Object[] parameterValues = {0}; ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); ExecutableValidator executableValidator = factory.getValidator().forExecutables(); Set<ConstraintViolation<TestValidator>> parameterViolations = executableValidator.validateParameters( customerFacade, method, parameterValues ); System.out.println("parameterViolations = " + parameterViolations); } } {code} The above is causing the following exception: {code} Exception in thread "main" javax.validation.ConstraintDeclarationException: HV000141: The constraint com.test.validation.constraints.CustomMin used ConstraintTarget#IMPLICIT where the target cannot be inferred. at org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl.determineConstraintType(ConstraintDescriptorImpl.java:404) at org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl.<init>(ConstraintDescriptorImpl.java:186) at org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl.<init>(ConstraintDescriptorImpl.java:208) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.buildConstraintDescriptor(AnnotationMetaDataProvider.java:588) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findConstraintAnnotations(AnnotationMetaDataProvider.java:515) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findConstraints(AnnotationMetaDataProvider.java:469) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findExecutableMetaData(AnnotationMetaDataProvider.java:313) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getMetaData(AnnotationMetaDataProvider.java:294) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getMethodMetaData(AnnotationMetaDataProvider.java:280) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.retrieveBeanConfiguration(AnnotationMetaDataProvider.java:143) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfiguration(AnnotationMetaDataProvider.java:130) at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfigurationForHierarchy(AnnotationMetaDataProvider.java:113) at org.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.java:187) at org.hibernate.validator.internal.metadata.BeanMetaDataManager.getBeanMetaData(BeanMetaDataManager.java:152) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:878) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:240) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:198) at com.test.validation.constraints.TestValidator.main(TestValidator.java:23) 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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) {code}

    Hibernate JIRA | 3 years ago | George Fountopoulos
    javax.validation.ConstraintDeclarationException: HV000141: The constraint com.test.validation.constraints.CustomMin used ConstraintTarget#IMPLICIT where the target cannot be inferred.

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. javax.validation.ConstraintDeclarationException

      HV000131: A method return value must not be marked for cascaded validation more than once in a class hierarchy, but the following two methods are marked as such: public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService$Proxy$_$$_WeldSubclass.createValidEvent(), public org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.Event org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.CalendarService.createValidEvent().

      at org.hibernate.validator.internal.metadata.aggregated.rule.ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.apply()
    2. Hibernate Validator Engine
      ExecutableMetaData$Builder.build
      1. org.hibernate.validator.internal.metadata.aggregated.rule.ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.apply(ReturnValueMayOnlyBeMarkedOnceAsCascadedPerHierarchyLine.java:33)
      2. org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.assertCorrectnessOfConfiguration(ExecutableMetaData.java:443)
      3. org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:361)
      3 frames