BVal
  1. BVal
  2. BVAL-78

Avoid unsafe casting and object swapping when processing @ReportAsSingleViolation composed constraints

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.2-incubating
    • Fix Version/s: 0.2-incubating
    • Component/s: jsr303
    • Labels:
      None

      Description

      Numerous warnings abound in ConstraintViolation due to the fact that ConstraintValidationListener must be used as a raw type. Further the GroupValidationContext must be cast to a BeanValidationContext so that the listener reference can be reset, which doesn't feel optimal either. The attached patch:

      • Modifies GroupValidationContext<T> such that, rather than extending ValidationContext<T> where T extends ValidationListener, it instead expressly implements ValidationContext<ConstraintValidationListener<T>> (T is now effectively the same type variable as ConstraintValidationListener<T>). Now GroupValidationContext.getListener() expressly returns a ConstraintValidationListener.
      • Adds state management for @ReportAsSingleViolation composed constraints to ConstraintValidationListener so that the original listener instance can be used throughout.
      • The reportAsSingle execution path bails as soon as it is known that a composing constraint has failed.

        Activity

        Hide
        Matt Benson added a comment -

        Update patch since BVAL-76 was accepted.

        Show
        Matt Benson added a comment - Update patch since BVAL-76 was accepted.
        Hide
        Carlos Vara added a comment -

        Merged the patch, thanks Matt!

        I added a commentary regarding the use of an AtomicInteger in ConstraintValidationListener, since it should not be needed as objects of that class (and all the classes involved in the validation process) are never shared between threads.

        Show
        Carlos Vara added a comment - Merged the patch, thanks Matt! I added a commentary regarding the use of an AtomicInteger in ConstraintValidationListener, since it should not be needed as objects of that class (and all the classes involved in the validation process) are never shared between threads.

          People

          • Assignee:
            Carlos Vara
            Reporter:
            Matt Benson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development