diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java index e0fe472c6f..63a769b4f8 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import java.util.Set; import org.springframework.core.BridgeMethodResolver; import org.springframework.lang.Nullable; -import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -154,9 +153,6 @@ public class AnnotatedElementUtils { * @see #hasMetaAnnotationTypes */ public static Set getMetaAnnotationTypes(AnnotatedElement element, Class annotationType) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - return getMetaAnnotationTypes(element, element.getAnnotation(annotationType)); } @@ -175,9 +171,6 @@ public class AnnotatedElementUtils { * @see #hasMetaAnnotationTypes */ public static Set getMetaAnnotationTypes(AnnotatedElement element, String annotationName) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.hasLength(annotationName, "'annotationName' must not be null or empty"); - return getMetaAnnotationTypes(element, AnnotationUtils.getAnnotation(element, annotationName)); } @@ -217,9 +210,6 @@ public class AnnotatedElementUtils { * @see #getMetaAnnotationTypes */ public static boolean hasMetaAnnotationTypes(AnnotatedElement element, Class annotationType) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - return hasMetaAnnotationTypes(element, annotationType, null); } @@ -236,9 +226,6 @@ public class AnnotatedElementUtils { * @see #getMetaAnnotationTypes */ public static boolean hasMetaAnnotationTypes(AnnotatedElement element, String annotationName) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.hasLength(annotationName, "'annotationName' must not be null or empty"); - return hasMetaAnnotationTypes(element, null, annotationName); } @@ -271,14 +258,10 @@ public class AnnotatedElementUtils { * @see #hasAnnotation(AnnotatedElement, Class) */ public static boolean isAnnotated(AnnotatedElement element, Class annotationType) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - // Shortcut: directly present on the element, with no processing needed? if (element.isAnnotationPresent(annotationType)) { return true; } - return Boolean.TRUE.equals(searchWithGetSemantics(element, annotationType, null, alwaysTrueAnnotationProcessor)); } @@ -295,9 +278,6 @@ public class AnnotatedElementUtils { * @return {@code true} if a matching annotation is present */ public static boolean isAnnotated(AnnotatedElement element, String annotationName) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.hasLength(annotationName, "'annotationName' must not be null or empty"); - return Boolean.TRUE.equals(searchWithGetSemantics(element, null, annotationName, alwaysTrueAnnotationProcessor)); } @@ -322,7 +302,6 @@ public class AnnotatedElementUtils { public static AnnotationAttributes getMergedAnnotationAttributes( AnnotatedElement element, Class annotationType) { - Assert.notNull(annotationType, "'annotationType' must not be null"); AnnotationAttributes attributes = searchWithGetSemantics(element, annotationType, null, new MergedAnnotationAttributesProcessor()); AnnotationUtils.postProcessAnnotationAttributes(element, attributes, false, false); @@ -382,7 +361,6 @@ public class AnnotatedElementUtils { public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { - Assert.hasLength(annotationName, "'annotationName' must not be null or empty"); AnnotationAttributes attributes = searchWithGetSemantics(element, null, annotationName, new MergedAnnotationAttributesProcessor(classValuesAsString, nestedAnnotationsAsMap)); AnnotationUtils.postProcessAnnotationAttributes(element, attributes, classValuesAsString, nestedAnnotationsAsMap); @@ -409,8 +387,6 @@ public class AnnotatedElementUtils { */ @Nullable public static A getMergedAnnotation(AnnotatedElement element, Class annotationType) { - Assert.notNull(annotationType, "'annotationType' must not be null"); - // Shortcut: directly present on the element, with no merging needed? if (!(element instanceof Class)) { // Do not use this shortcut against a Class: Inherited annotations @@ -446,12 +422,7 @@ public class AnnotatedElementUtils { * @see #getAllAnnotationAttributes(AnnotatedElement, String) * @see #findAllMergedAnnotations(AnnotatedElement, Class) */ - public static Set getAllMergedAnnotations(AnnotatedElement element, - Class annotationType) { - - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - + public static Set getAllMergedAnnotations(AnnotatedElement element, Class annotationType) { MergedAnnotationAttributesProcessor processor = new MergedAnnotationAttributesProcessor(false, false, true); searchWithGetSemantics(element, annotationType, null, processor); return postProcessAndSynthesizeAggregatedResults(element, annotationType, processor.getAggregatedResults()); @@ -516,9 +487,6 @@ public class AnnotatedElementUtils { public static Set getMergedRepeatableAnnotations(AnnotatedElement element, Class annotationType, @Nullable Class containerType) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - if (containerType == null) { containerType = resolveContainerType(annotationType); } @@ -603,14 +571,10 @@ public class AnnotatedElementUtils { * @see #isAnnotated(AnnotatedElement, Class) */ public static boolean hasAnnotation(AnnotatedElement element, Class annotationType) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - // Shortcut: directly present on the element, with no processing needed? if (element.isAnnotationPresent(annotationType)) { return true; } - return Boolean.TRUE.equals(searchWithFindSemantics(element, annotationType, null, alwaysTrueAnnotationProcessor)); } @@ -710,8 +674,6 @@ public class AnnotatedElementUtils { */ @Nullable public static A findMergedAnnotation(AnnotatedElement element, Class annotationType) { - Assert.notNull(annotationType, "'annotationType' must not be null"); - // Shortcut: directly present on the element, with no merging needed? if (!(element instanceof Class)) { // Do not use this shortcut against a Class: Inherited annotations @@ -746,12 +708,7 @@ public class AnnotatedElementUtils { * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #getAllMergedAnnotations(AnnotatedElement, Class) */ - public static Set findAllMergedAnnotations(AnnotatedElement element, - Class annotationType) { - - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - + public static Set findAllMergedAnnotations(AnnotatedElement element, Class annotationType) { MergedAnnotationAttributesProcessor processor = new MergedAnnotationAttributesProcessor(false, false, true); searchWithFindSemantics(element, annotationType, null, processor); return postProcessAndSynthesizeAggregatedResults(element, annotationType, processor.getAggregatedResults()); @@ -816,9 +773,6 @@ public class AnnotatedElementUtils { public static Set findMergedRepeatableAnnotations(AnnotatedElement element, Class annotationType, @Nullable Class containerType) { - Assert.notNull(element, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - if (containerType == null) { containerType = resolveContainerType(annotationType); } @@ -902,8 +856,6 @@ public class AnnotatedElementUtils { @Nullable Class containerType, Processor processor, Set visited, int metaDepth) { - Assert.notNull(element, "AnnotatedElement must not be null"); - if (visited.add(element)) { try { // Start searching within locally declared annotations @@ -1096,8 +1048,6 @@ public class AnnotatedElementUtils { @Nullable Class containerType, Processor processor, Set visited, int metaDepth) { - Assert.notNull(element, "AnnotatedElement must not be null"); - if (visited.add(element)) { try { // Locally declared annotations (ignoring @Inherited) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index b7ed7e8ec2..f764ceddbf 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -439,9 +439,6 @@ public abstract class AnnotationUtils { private static Set getRepeatableAnnotations(AnnotatedElement annotatedElement, Class annotationType, @Nullable Class containerAnnotationType, boolean declaredMode) { - Assert.notNull(annotatedElement, "AnnotatedElement must not be null"); - Assert.notNull(annotationType, "Annotation type must not be null"); - try { if (annotatedElement instanceof Method) { annotatedElement = BridgeMethodResolver.findBridgedMethod((Method) annotatedElement); @@ -472,8 +469,6 @@ public abstract class AnnotationUtils { */ @Nullable public static A findAnnotation(AnnotatedElement annotatedElement, Class annotationType) { - Assert.notNull(annotatedElement, "AnnotatedElement must not be null"); - // Do NOT store result in the findAnnotationCache since doing so could break // findAnnotation(Class, Class) and findAnnotation(Method, Class). A ann = findAnnotation(annotatedElement, annotationType, new HashSet<>()); @@ -745,7 +740,6 @@ public abstract class AnnotationUtils { */ @Nullable public static Class findAnnotationDeclaringClass(Class annotationType, @Nullable Class clazz) { - Assert.notNull(annotationType, "Annotation type must not be null"); if (clazz == null || Object.class == clazz) { return null; } @@ -781,7 +775,6 @@ public abstract class AnnotationUtils { */ @Nullable public static Class findAnnotationDeclaringClassForTypes(List> annotationTypes, @Nullable Class clazz) { - Assert.notEmpty(annotationTypes, "List of annotation types must not be empty"); if (clazz == null || Object.class == clazz) { return null; } @@ -812,8 +805,6 @@ public abstract class AnnotationUtils { * @see #isAnnotationInherited(Class, Class) */ public static boolean isAnnotationDeclaredLocally(Class annotationType, Class clazz) { - Assert.notNull(annotationType, "Annotation type must not be null"); - Assert.notNull(clazz, "Class must not be null"); try { return (clazz.getDeclaredAnnotation(annotationType) != null); } @@ -843,8 +834,6 @@ public abstract class AnnotationUtils { * @see #isAnnotationDeclaredLocally(Class, Class) */ public static boolean isAnnotationInherited(Class annotationType, Class clazz) { - Assert.notNull(annotationType, "Annotation type must not be null"); - Assert.notNull(clazz, "Class must not be null"); return (clazz.isAnnotationPresent(annotationType) && !isAnnotationDeclaredLocally(annotationType, clazz)); } @@ -1444,7 +1433,6 @@ public abstract class AnnotationUtils { @SuppressWarnings("unchecked") static A synthesizeAnnotation(A annotation, @Nullable Object annotatedElement) { - Assert.notNull(annotation, "Annotation must not be null"); if (annotation instanceof SynthesizedAnnotation) { return annotation; } @@ -1497,9 +1485,6 @@ public abstract class AnnotationUtils { public static A synthesizeAnnotation(Map attributes, Class annotationType, @Nullable AnnotatedElement annotatedElement) { - Assert.notNull(attributes, "'attributes' must not be null"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - MapAnnotationAttributeExtractor attributeExtractor = new MapAnnotationAttributeExtractor(attributes, annotationType, annotatedElement); InvocationHandler handler = new SynthesizedAnnotationInvocationHandler(attributeExtractor); @@ -1574,7 +1559,6 @@ public abstract class AnnotationUtils { @SuppressWarnings("unchecked") @Nullable static A[] synthesizeAnnotationArray(@Nullable Map[] maps, Class annotationType) { - Assert.notNull(annotationType, "'annotationType' must not be null"); if (maps == null) { return null; } @@ -1703,7 +1687,6 @@ public abstract class AnnotationUtils { * @see #getAttributeOverrideName(Method, Class) */ static List getAttributeAliasNames(Method attribute) { - Assert.notNull(attribute, "attribute must not be null"); AliasDescriptor descriptor = AliasDescriptor.from(attribute); return (descriptor != null ? descriptor.getAttributeAliasNames() : Collections. emptyList()); } @@ -1726,13 +1709,9 @@ public abstract class AnnotationUtils { */ @Nullable static String getAttributeOverrideName(Method attribute, @Nullable Class metaAnnotationType) { - Assert.notNull(attribute, "attribute must not be null"); - Assert.notNull(metaAnnotationType, "metaAnnotationType must not be null"); - Assert.isTrue(Annotation.class != metaAnnotationType, - "metaAnnotationType must not be [java.lang.annotation.Annotation]"); - AliasDescriptor descriptor = AliasDescriptor.from(attribute); - return (descriptor != null ? descriptor.getAttributeOverrideName(metaAnnotationType) : null); + return (descriptor != null && metaAnnotationType != null ? + descriptor.getAttributeOverrideName(metaAnnotationType) : null); } /** @@ -2043,7 +2022,6 @@ public abstract class AnnotationUtils { @SuppressWarnings("unchecked") private AliasDescriptor(Method sourceAttribute, AliasFor aliasFor) { Class declaringClass = sourceAttribute.getDeclaringClass(); - Assert.isTrue(declaringClass.isAnnotation(), "sourceAttribute must be from an annotation"); this.sourceAttribute = sourceAttribute; this.sourceAnnotationType = (Class) declaringClass; @@ -2117,7 +2095,6 @@ public abstract class AnnotationUtils { } private void validateDefaultValueConfiguration(Method aliasedAttribute) { - Assert.notNull(aliasedAttribute, "aliasedAttribute must not be null"); Object defaultValue = this.sourceAttribute.getDefaultValue(); Object aliasedDefaultValue = aliasedAttribute.getDefaultValue(); @@ -2211,10 +2188,6 @@ public abstract class AnnotationUtils { @Nullable public String getAttributeOverrideName(Class metaAnnotationType) { - Assert.notNull(metaAnnotationType, "metaAnnotationType must not be null"); - Assert.isTrue(Annotation.class != metaAnnotationType, - "metaAnnotationType must not be [java.lang.annotation.Annotation]"); - // Search the attribute override hierarchy, starting with the current attribute for (AliasDescriptor desc = this; desc != null; desc = desc.getAttributeOverrideDescriptor()) { if (desc.isOverrideFor(metaAnnotationType)) {