Skip to content

Commit af963b5

Browse files
committed
Account for the fact that validatedBy can now be null in the AP
since it has a default value of {} Signed-off-by: marko-bekhta <[email protected]>
1 parent 118e815 commit af963b5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

annotation-processor/src/main/java/org/hibernate/validator/ap/internal/checks/ConstraintValidatorCheck.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
package org.hibernate.validator.ap.internal.checks;
66

77
import java.util.Collections;
8+
import java.util.List;
89
import java.util.Set;
910

1011
import javax.lang.model.element.AnnotationMirror;
12+
import javax.lang.model.element.AnnotationValue;
1113
import javax.lang.model.element.TypeElement;
1214

1315
import org.hibernate.validator.ap.internal.util.AnnotationApiHelper;
@@ -39,9 +41,10 @@ public Set<ConstraintCheckIssue> checkAnnotationType(TypeElement element, Annota
3941
AnnotationMirror constraintMirror = annotationApiHelper.getMirror(
4042
element.getAnnotationMirrors(), BeanValidationTypes.CONSTRAINT
4143
);
42-
boolean atLeastOneValidatorGiven = !annotationApiHelper.getAnnotationArrayValue(
44+
List<? extends AnnotationValue> validatedBy = annotationApiHelper.getAnnotationArrayValue(
4345
constraintMirror, "validatedBy"
44-
).isEmpty();
46+
);
47+
boolean atLeastOneValidatorGiven = validatedBy != null && !validatedBy.isEmpty();
4548

4649
if ( !( atLeastOneValidatorGiven || constraintHelper.isComposedConstraint( element ) ) ) {
4750

annotation-processor/src/main/java/org/hibernate/validator/ap/internal/util/ConstraintHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,10 @@ private List<? extends AnnotationValue> getValidatorClassesFromConstraintMetaAnn
10131013

10141014
AnnotationValue validatedBy = annotationApiHelper.getAnnotationValue( constraintMetaAnnotation, "validatedBy" );
10151015

1016+
if ( validatedBy == null ) {
1017+
return List.of();
1018+
}
1019+
10161020
return validatedBy.accept(
10171021
new SimpleAnnotationValueVisitor8<List<? extends AnnotationValue>, Void>() {
10181022

0 commit comments

Comments
 (0)