Uploaded image for project: 'BVal'
  1. BVal
  2. BVAL-116

Multiple errors reported for a single validation failure with composite keys

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.5
    • 0.5, 1.0
    • jsr303
    • None

    Description

      Am testing using JPA 2.0 and have an Entity with a composite key consisting of three columns. All are set to be "Not Null" in the database definition. When a test runs that has only one of the three values set to null, three error messages are returned. It was not too hard to figure out why. In the org.apache.bval.jsr303.ConstraintValidation, there is this code starting at around line 170:

              // process composed constraints
              if (isReportAsSingleViolation()) {
                  ConstraintValidationListener<?> listener = context.getListener();
                  listener.beginReportAsSingle();
      
                  boolean failed = listener.hasViolations();
                  try {
                      // stop validating when already failed and
                      // ReportAsSingleInvalidConstraint = true ?
                      for (Iterator<ConstraintValidation<?>> composed = getComposingValidations().iterator(); !failed && composed.hasNext();) {
                          composed.next().validate(context);
                          failed = listener.hasViolations();
                      }
                  } finally {
                      listener.endReportAsSingle();
                      // Restore current constraint validation
                      context.setConstraintValidation(this);
                  }
      
                  if (failed) {
                      // TODO RSt - how should the composed constraint error report look like?
                      ConstraintValidatorContextImpl jsrContext = new ConstraintValidatorContextImpl(context, this);
                      addErrors(context, jsrContext); // add defaultErrorMessage only
                      return;
                  }
              }
      

      This same code gets executed all three times (as we have three components to the primary key). As "luck" would have it, for my first pass through the first one was the one with the NULL value. This set's the "hasViolations" in the "listener" object. Since they all pass in the same context, they pass in the same listener. Thus, even though the subsequent calls to "compose.next().validate(context)" do NOT fail, "failed" is still set to true…

      Fix this if you can, but I can't really generate a stand alone test case for you - I have deadlines too! It doesn't seem to hard to me though...

      Attachments

        1. BVAL-116.patch
          1 kB
          Albert Lee

        Activity

          People

            allee8285 Albert Lee
            blackduck.joe Joe Gamache
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: