Uploaded image for project: 'Hibernate Validator'
  1. HV-1528

ClassCastException in ValidationException.isAlreadyValidatedForCurrentGroup

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 6.0.4.Final
    • Fix Version/s: None
    • Component/s: engine
    • Labels:
      None
    • Environment:
      6.0.4.Final, Java 8, BeanValidation 2.0
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Suitable for new contributors:
      Yes, likely
    • Last commented by a user?:
      true
    • Sprint:

      Description

      Wen trying to validate a pretty large list of beans, I sometimes encounter a ClassCastException in the ValidationException.isAlreadyValidatedForCurrentGroup method.

      The issue is that we have two types of objects (BeanPathMetaConstraintProcessedUnit and BeanGroupProcessedUnit) in the processedUnits Set. Sometimes two instances of theses classes have the same hashcode value. When applying the equals method, I encounter a ClassCastException.

      This part of the equals method is the problem :

      if ( o == null || getClass() != BeanPathMetaConstraintProcessedUnit.class ) {
          return false;
      }
      
      BeanPathMetaConstraintProcessedUnit that = (BeanPathMetaConstraintProcessedUnit) o; // ClassCast because it's an instance of BeanGroupProcessedUnit
      

      I think, the comparison should be o.getClass != BeanGroupProcessedUnit.class. There is the same problem in the BeanGroupProcessedUnit equals method.

      Here is the stack trace:

      java.lang.ClassCastException: org.hibernate.validator.internal.engine.ValidationContext$BeanPathMetaConstraintProcessedUnit cannot be cast to org.hibernate.validator.internal.engine.ValidationContext$BeanGroupProcessedUnit
      	at org.hibernate.validator.internal.engine.ValidationContext$BeanGroupProcessedUnit.equals(ValidationContext.java:620)
      	at java.util.HashMap.getNode(HashMap.java:571)
      	at java.util.HashMap.containsKey(HashMap.java:595)
      	at java.util.HashSet.contains(HashSet.java:203)
      	at org.hibernate.validator.internal.engine.ValidationContext.isAlreadyValidatedForCurrentGroup(ValidationContext.java:440)
      	at org.hibernate.validator.internal.engine.ValidationContext.isBeanAlreadyValidated(ValidationContext.java:269)
      	at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedAnnotatedObjectForCurrentGroup(ValidatorImpl.java:626)
      	at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:604)
      	at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:420)
      	at org.hibernate.validator.internal.engine.ValidatorImpl.access$300(ValidatorImpl.java:85)
      	at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.doValidate(ValidatorImpl.java:723)
      	at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.indexedValue(ValidatorImpl.java:691)
      	at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:26)
      	at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:16)
      	at org.hibernate.validator.internal.engine.valueextraction.ValueExtractorHelper.extractValues(ValueExtractorHelper.java:41)
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: