Skip to content

Commit 7d13ef9

Browse files
committed
#1507 - Fix potential NullPointerException in Jsr303AwarePropertyMetadata.
We now check whether we could really load `@Range`, which is only available from Java Validation 2.0 and newer. Classpaths that only included a 1.x flavor of that would end up with `null` for the loaded class and have that forwarded into a method not accepting `null` values.
1 parent 107fcfa commit 7d13ef9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ protected String getAnnotatedInputType() {
539539
private static class Jsr303AwarePropertyMetadata extends DefaultPropertyMetadata {
540540

541541
private static final Optional<Class<? extends Annotation>> LENGTH_ANNOTATION;
542-
private static final Class<? extends Annotation> URL_ANNOTATION, RANGE_ANNOTATION;
542+
private static final @Nullable Class<? extends Annotation> URL_ANNOTATION, RANGE_ANNOTATION;
543543
private static final Map<Class<? extends Annotation>, String> TYPE_MAP;
544544

545545
static {
@@ -609,10 +609,13 @@ public Optional<String> getPattern() {
609609
@Override
610610
public Long getMin() {
611611

612-
Optional<Long> attribute = getAnnotationAttribute(RANGE_ANNOTATION, "min", Long.class);
612+
if (RANGE_ANNOTATION != null) {
613+
614+
Optional<Long> attribute = getAnnotationAttribute(RANGE_ANNOTATION, "min", Long.class);
613615

614-
if (attribute.isPresent()) {
615-
return attribute.get();
616+
if (attribute.isPresent()) {
617+
return attribute.get();
618+
}
616619
}
617620

618621
return getAnnotationAttribute(Min.class, "value", Long.class).orElse(null);
@@ -626,10 +629,13 @@ public Long getMin() {
626629
@Override
627630
public Long getMax() {
628631

629-
Optional<Long> attribute = getAnnotationAttribute(RANGE_ANNOTATION, "max", Long.class);
632+
if (RANGE_ANNOTATION != null) {
633+
634+
Optional<Long> attribute = getAnnotationAttribute(RANGE_ANNOTATION, "max", Long.class);
630635

631-
if (attribute.isPresent()) {
632-
return attribute.get();
636+
if (attribute.isPresent()) {
637+
return attribute.get();
638+
}
633639
}
634640

635641
return getAnnotationAttribute(Max.class, "value", Long.class).orElse(null);

0 commit comments

Comments
 (0)