Skip to content

Commit a7975c6

Browse files
committed
AnnotationUtils explicitly handles null parameters
Issue: SPR-12604 (cherry picked from commit 0ddf8dd)
1 parent cdaf449 commit a7975c6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.util.ConcurrentReferenceHashMap;
3636
import org.springframework.util.ObjectUtils;
3737
import org.springframework.util.ReflectionUtils;
38+
import org.springframework.util.StringUtils;
3839

3940
/**
4041
* General utility methods for working with annotations, handling bridge methods
@@ -654,6 +655,9 @@ public static Object getValue(Annotation annotation) {
654655
* @see #getValue(Annotation)
655656
*/
656657
public static Object getValue(Annotation annotation, String attributeName) {
658+
if (annotation == null || !StringUtils.hasLength(attributeName)) {
659+
return null;
660+
}
657661
try {
658662
Method method = annotation.annotationType().getDeclaredMethod(attributeName);
659663
ReflectionUtils.makeAccessible(method);
@@ -683,6 +687,9 @@ public static Object getDefaultValue(Annotation annotation) {
683687
* @see #getDefaultValue(Class, String)
684688
*/
685689
public static Object getDefaultValue(Annotation annotation, String attributeName) {
690+
if (annotation == null) {
691+
return null;
692+
}
686693
return getDefaultValue(annotation.annotationType(), attributeName);
687694
}
688695

@@ -706,6 +713,9 @@ public static Object getDefaultValue(Class<? extends Annotation> annotationType)
706713
* @see #getDefaultValue(Annotation, String)
707714
*/
708715
public static Object getDefaultValue(Class<? extends Annotation> annotationType, String attributeName) {
716+
if (annotationType == null || !StringUtils.hasLength(attributeName)) {
717+
return null;
718+
}
709719
try {
710720
return annotationType.getDeclaredMethod(attributeName).getDefaultValue();
711721
}

0 commit comments

Comments
 (0)