From 156546ad05a1201ee924a57398f0268fd7577dbe Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 13 Aug 2023 13:40:31 +0200 Subject: [PATCH] Make AnnotationAttributes.validated field immutable --- .../core/annotation/AnnotationAttributes.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java index fe7a49612a..dfe98c1238 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java @@ -53,7 +53,7 @@ public class AnnotationAttributes extends LinkedHashMap { final String displayName; - boolean validated = false; + final boolean validated; /** @@ -62,6 +62,7 @@ public class AnnotationAttributes extends LinkedHashMap { public AnnotationAttributes() { this.annotationType = null; this.displayName = UNKNOWN; + this.validated = false; } /** @@ -73,6 +74,7 @@ public class AnnotationAttributes extends LinkedHashMap { super(initialCapacity); this.annotationType = null; this.displayName = UNKNOWN; + this.validated = false; } /** @@ -85,6 +87,7 @@ public class AnnotationAttributes extends LinkedHashMap { super(map); this.annotationType = null; this.displayName = UNKNOWN; + this.validated = false; } /** @@ -108,9 +111,20 @@ public class AnnotationAttributes extends LinkedHashMap { * @since 4.2 */ public AnnotationAttributes(Class annotationType) { - Assert.notNull(annotationType, "'annotationType' must not be null"); - this.annotationType = annotationType; - this.displayName = annotationType.getName(); + this(annotationType, false); + } + + /** + * Create a new, empty {@link AnnotationAttributes} instance for the + * specified {@code annotationType}. + * @param annotationType the annotation type name represented by this + * {@code AnnotationAttributes} instance; never {@code null} + * @param classLoader the ClassLoader to try to load the annotation type on, + * or {@code null} to just store the annotation type name + * @since 4.3.2 + */ + public AnnotationAttributes(String annotationType, @Nullable ClassLoader classLoader) { + this(getAnnotationType(annotationType, classLoader), false); } /** @@ -129,20 +143,6 @@ public class AnnotationAttributes extends LinkedHashMap { this.validated = validated; } - /** - * Create a new, empty {@link AnnotationAttributes} instance for the - * specified {@code annotationType}. - * @param annotationType the annotation type name represented by this - * {@code AnnotationAttributes} instance; never {@code null} - * @param classLoader the ClassLoader to try to load the annotation type on, - * or {@code null} to just store the annotation type name - * @since 4.3.2 - */ - public AnnotationAttributes(String annotationType, @Nullable ClassLoader classLoader) { - Assert.notNull(annotationType, "'annotationType' must not be null"); - this.annotationType = getAnnotationType(annotationType, classLoader); - this.displayName = annotationType; - } @SuppressWarnings("unchecked") @Nullable