#1507 - Fix potential NullPointerException in Jsr303AwarePropertyMetadata.
We now check whether we could really load `@Range`, which is only available in Hibernate Validator. An arrangement in which the Validation API JAR is on the classpath but not Hibernate Validator would let us end up with the relevant instance being `null` and need a check for before being handed into code that requires the type to not be `null`.
This commit is contained in:
@@ -539,7 +539,7 @@ public class PropertyUtils {
|
||||
private static class Jsr303AwarePropertyMetadata extends DefaultPropertyMetadata {
|
||||
|
||||
private static final Optional<Class<? extends Annotation>> LENGTH_ANNOTATION;
|
||||
private static final Class<? extends Annotation> URL_ANNOTATION, RANGE_ANNOTATION;
|
||||
private static final @Nullable Class<? extends Annotation> URL_ANNOTATION, RANGE_ANNOTATION;
|
||||
private static final Map<Class<? extends Annotation>, String> TYPE_MAP;
|
||||
|
||||
static {
|
||||
@@ -609,10 +609,13 @@ public class PropertyUtils {
|
||||
@Override
|
||||
public Long getMin() {
|
||||
|
||||
Optional<Long> attribute = getAnnotationAttribute(RANGE_ANNOTATION, "min", Long.class);
|
||||
if (RANGE_ANNOTATION != null) {
|
||||
|
||||
if (attribute.isPresent()) {
|
||||
return attribute.get();
|
||||
Optional<Long> attribute = getAnnotationAttribute(RANGE_ANNOTATION, "min", Long.class);
|
||||
|
||||
if (attribute.isPresent()) {
|
||||
return attribute.get();
|
||||
}
|
||||
}
|
||||
|
||||
return getAnnotationAttribute(Min.class, "value", Long.class).orElse(null);
|
||||
@@ -626,10 +629,13 @@ public class PropertyUtils {
|
||||
@Override
|
||||
public Long getMax() {
|
||||
|
||||
Optional<Long> attribute = getAnnotationAttribute(RANGE_ANNOTATION, "max", Long.class);
|
||||
if (RANGE_ANNOTATION != null) {
|
||||
|
||||
if (attribute.isPresent()) {
|
||||
return attribute.get();
|
||||
Optional<Long> attribute = getAnnotationAttribute(RANGE_ANNOTATION, "max", Long.class);
|
||||
|
||||
if (attribute.isPresent()) {
|
||||
return attribute.get();
|
||||
}
|
||||
}
|
||||
|
||||
return getAnnotationAttribute(Max.class, "value", Long.class).orElse(null);
|
||||
|
||||
Reference in New Issue
Block a user