@@ -456,8 +456,8 @@ public static <A extends Annotation> Set<A> getDeclaredRepeatableAnnotations(Ann
456
456
private static <A extends Annotation > Set <A > getRepeatableAnnotations (AnnotatedElement annotatedElement ,
457
457
Class <A > annotationType , Class <? extends Annotation > containerAnnotationType , boolean declaredMode ) {
458
458
459
- Assert .notNull (annotatedElement , "annotatedElement must not be null" );
460
- Assert .notNull (annotationType , "annotationType must not be null" );
459
+ Assert .notNull (annotatedElement , "AnnotatedElement must not be null" );
460
+ Assert .notNull (annotationType , "Annotation type must not be null" );
461
461
462
462
try {
463
463
if (annotatedElement instanceof Method ) {
@@ -488,6 +488,11 @@ private static <A extends Annotation> Set<A> getRepeatableAnnotations(AnnotatedE
488
488
* @since 4.2
489
489
*/
490
490
public static <A extends Annotation > A findAnnotation (AnnotatedElement annotatedElement , Class <A > annotationType ) {
491
+ Assert .notNull (annotatedElement , "AnnotatedElement must not be null" );
492
+ if (annotationType == null ) {
493
+ return null ;
494
+ }
495
+
491
496
// Do NOT store result in the findAnnotationCache since doing so could break
492
497
// findAnnotation(Class, Class) and findAnnotation(Method, Class).
493
498
return synthesizeAnnotation (
@@ -506,7 +511,6 @@ public static <A extends Annotation> A findAnnotation(AnnotatedElement annotated
506
511
*/
507
512
@ SuppressWarnings ("unchecked" )
508
513
private static <A extends Annotation > A findAnnotation (AnnotatedElement annotatedElement , Class <A > annotationType , Set <Annotation > visited ) {
509
- Assert .notNull (annotatedElement , "AnnotatedElement must not be null" );
510
514
try {
511
515
Annotation [] anns = annotatedElement .getDeclaredAnnotations ();
512
516
for (Annotation ann : anns ) {
@@ -546,6 +550,11 @@ private static <A extends Annotation> A findAnnotation(AnnotatedElement annotate
546
550
*/
547
551
@ SuppressWarnings ("unchecked" )
548
552
public static <A extends Annotation > A findAnnotation (Method method , Class <A > annotationType ) {
553
+ Assert .notNull (method , "Method must not be null" );
554
+ if (annotationType == null ) {
555
+ return null ;
556
+ }
557
+
549
558
AnnotationCacheKey cacheKey = new AnnotationCacheKey (method , annotationType );
550
559
A result = (A ) findAnnotationCache .get (cacheKey );
551
560
@@ -663,6 +672,11 @@ public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> a
663
672
*/
664
673
@ SuppressWarnings ("unchecked" )
665
674
private static <A extends Annotation > A findAnnotation (Class <?> clazz , Class <A > annotationType , boolean synthesize ) {
675
+ Assert .notNull (clazz , "Class must not be null" );
676
+ if (annotationType == null ) {
677
+ return null ;
678
+ }
679
+
666
680
AnnotationCacheKey cacheKey = new AnnotationCacheKey (clazz , annotationType );
667
681
A result = (A ) findAnnotationCache .get (cacheKey );
668
682
if (result == null ) {
@@ -686,8 +700,6 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A>
686
700
*/
687
701
@ SuppressWarnings ("unchecked" )
688
702
private static <A extends Annotation > A findAnnotation (Class <?> clazz , Class <A > annotationType , Set <Annotation > visited ) {
689
- Assert .notNull (clazz , "Class must not be null" );
690
-
691
703
try {
692
704
Annotation [] anns = clazz .getDeclaredAnnotations ();
693
705
for (Annotation ann : anns ) {
@@ -863,6 +875,11 @@ public static boolean isAnnotationInherited(Class<? extends Annotation> annotati
863
875
public static boolean isAnnotationMetaPresent (Class <? extends Annotation > annotationType ,
864
876
Class <? extends Annotation > metaAnnotationType ) {
865
877
878
+ Assert .notNull (annotationType , "Annotation type must not be null" );
879
+ if (metaAnnotationType == null ) {
880
+ return false ;
881
+ }
882
+
866
883
AnnotationCacheKey cacheKey = new AnnotationCacheKey (annotationType , metaAnnotationType );
867
884
Boolean metaPresent = metaPresentCache .get (cacheKey );
868
885
if (metaPresent != null ) {
@@ -1760,8 +1777,7 @@ public boolean equals(Object other) {
1760
1777
return false ;
1761
1778
}
1762
1779
AnnotationCacheKey otherKey = (AnnotationCacheKey ) other ;
1763
- return (this .element .equals (otherKey .element ) &&
1764
- ObjectUtils .nullSafeEquals (this .annotationType , otherKey .annotationType ));
1780
+ return (this .element .equals (otherKey .element ) && this .annotationType .equals (otherKey .annotationType ));
1765
1781
}
1766
1782
1767
1783
@ Override
0 commit comments