Hi,
I'm wondering if there's a way to make the validation of a composite constraint fail fast (or short circuit) if the validation of a meta constraint fails. In my case, I have two constraints @NullHostileCollection for Collection<?> and composite @NumberList for List<? extends Number>, which look like
Code:
@Target({METHOD, FIELD, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = NullHostileCollectionValidator.class)
@Documented
public @interface NullHostileCollection {
Code:
@Target({METHOD, FIELD, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = NumberListValidator.class)
@Documented
@NullHostileCollection
@ReportAsSingleViolation
public @interface NumberList {
When I validate a number list which contains null values, the NullHostileCollectionValidator correctly considers the list invalid. However, validation then continues to the NumberListValidator instad of short circuiting. As a result, the NumberListValidator can't assume anything about the list and has to have extra checks to avoid NPEs, etc. Is it possible to make the validation short circuit? This behaviour makes even more sense when reporting as a single violation, IMO.
Thanks,
Emerson