@@ -107,7 +107,7 @@ public abstract class AnnotationUtils {
107
107
* An object that can be stored in {@link AnnotationAttributes} as a
108
108
* placeholder for an attribute's declared default value.
109
109
*/
110
- private static final Object DEFAULT_VALUE_PLACEHOLDER = "<SPRING DEFAULT VALUE PLACEHOLDER>" ;
110
+ private static final Object DEFAULT_VALUE_PLACEHOLDER = new String ( "<SPRING DEFAULT VALUE PLACEHOLDER>" ) ;
111
111
112
112
private static final Map <AnnotationCacheKey , Annotation > findAnnotationCache =
113
113
new ConcurrentReferenceHashMap <AnnotationCacheKey , Annotation >(256 );
@@ -803,15 +803,15 @@ public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement anno
803
803
* <p>This method provides fully recursive annotation reading capabilities on par with
804
804
* the reflection-based {@link org.springframework.core.type.StandardAnnotationMetadata}.
805
805
*
806
- * <p><strong>NOTE</strong>: this variant of {@code getAnnotationAttributes()} is
807
- * only intended for use within the framework. Specifically, the
808
- * {@code defaultValuesAsPlaceholder} flag can be set to {@code true} in order to
809
- * support processing of attribute aliases while merging attributes within an annotation
810
- * hierarchy. If this method is invoked with {@code defaultValuesAsPlaceholder} set to
811
- * {@code true}:
806
+ * <p><strong>NOTE</strong>: This variant of {@code getAnnotationAttributes()} is
807
+ * only intended for use within the framework. Specifically, the {@code mergeMode} flag
808
+ * can be set to {@code true} in order to support processing of attribute aliases while
809
+ * merging attributes within an annotation hierarchy. When running in <em>merge mode</em>,
810
+ * the following special rules apply:
812
811
* <ol>
813
812
* <li>The supplied annotation will <strong>not</strong> be
814
813
* {@linkplain #synthesizeAnnotation synthesized} before retrieving its attributes.</li>
814
+ * <li>Default values will be replaced with {@link #DEFAULT_VALUE_PLACEHOLDER}.</li>
815
815
* <li>The resulting, merged annotation attributes should eventually be
816
816
* {@linkplain #postProcessAnnotationAttributes post-processed} in order to
817
817
* ensure that placeholders have been replaced by actual default values and
@@ -828,17 +828,17 @@ public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement anno
828
828
* {@link AnnotationAttributes} maps (for compatibility with
829
829
* {@link org.springframework.core.type.AnnotationMetadata}) or to preserve them as
830
830
* {@code Annotation} instances
831
- * @param defaultValuesAsPlaceholder whether to replace default values with
832
- * {@link #DEFAULT_VALUE_PLACEHOLDER} or leave them as is
831
+ * @param mergeMode whether the annotation attributes should be created
832
+ * using <em>merge mode</em>
833
833
* @return the annotation attributes (a specialized Map) with attribute names as keys
834
834
* and corresponding attribute values as values; never {@code null}
835
835
* @since 4.2
836
836
* @see #postProcessAnnotationAttributes
837
837
*/
838
838
static AnnotationAttributes getAnnotationAttributes (AnnotatedElement annotatedElement , Annotation annotation ,
839
- boolean classValuesAsString , boolean nestedAnnotationsAsMap , boolean defaultValuesAsPlaceholder ) {
839
+ boolean classValuesAsString , boolean nestedAnnotationsAsMap , boolean mergeMode ) {
840
840
841
- if (!defaultValuesAsPlaceholder ) {
841
+ if (!mergeMode ) {
842
842
annotation = synthesizeAnnotation (annotation , annotatedElement );
843
843
}
844
844
@@ -848,7 +848,7 @@ static AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedEl
848
848
try {
849
849
Object value = method .invoke (annotation );
850
850
Object defaultValue = method .getDefaultValue ();
851
- if (defaultValuesAsPlaceholder && (defaultValue != null )) {
851
+ if (mergeMode && (defaultValue != null )) {
852
852
if (ObjectUtils .nullSafeEquals (value , defaultValue )) {
853
853
value = DEFAULT_VALUE_PLACEHOLDER ;
854
854
}
@@ -1390,8 +1390,8 @@ static void postProcessAnnotationAttributes(AnnotatedElement element, Annotation
1390
1390
Object value = attributes .get (attributeName );
1391
1391
Object aliasedValue = attributes .get (aliasedAttributeName );
1392
1392
1393
- if (!ObjectUtils .nullSafeEquals (value , aliasedValue ) && ! DEFAULT_VALUE_PLACEHOLDER . equals (value )
1394
- && ! DEFAULT_VALUE_PLACEHOLDER . equals (aliasedValue )) {
1393
+ if (!ObjectUtils .nullSafeEquals (value , aliasedValue ) && (value != DEFAULT_VALUE_PLACEHOLDER )
1394
+ && (aliasedValue != DEFAULT_VALUE_PLACEHOLDER )) {
1395
1395
String elementAsString = (element == null ? "unknown element" : element .toString ());
1396
1396
String msg = String .format (
1397
1397
"In AnnotationAttributes for annotation [%s] declared on [%s], attribute [%s] and its alias [%s] are "
@@ -1402,11 +1402,11 @@ static void postProcessAnnotationAttributes(AnnotatedElement element, Annotation
1402
1402
}
1403
1403
1404
1404
// Replace default values with aliased values...
1405
- if (DEFAULT_VALUE_PLACEHOLDER . equals ( value ) ) {
1405
+ if (value == DEFAULT_VALUE_PLACEHOLDER ) {
1406
1406
attributes .put (attributeName ,
1407
1407
adaptValue (element , aliasedValue , classValuesAsString , nestedAnnotationsAsMap ));
1408
1408
}
1409
- if (DEFAULT_VALUE_PLACEHOLDER . equals ( aliasedValue ) ) {
1409
+ if (aliasedValue == DEFAULT_VALUE_PLACEHOLDER ) {
1410
1410
attributes .put (aliasedAttributeName ,
1411
1411
adaptValue (element , value , classValuesAsString , nestedAnnotationsAsMap ));
1412
1412
}
@@ -1415,7 +1415,7 @@ static void postProcessAnnotationAttributes(AnnotatedElement element, Annotation
1415
1415
1416
1416
for (String attributeName : attributes .keySet ()) {
1417
1417
Object value = attributes .get (attributeName );
1418
- if (DEFAULT_VALUE_PLACEHOLDER . equals ( value ) ) {
1418
+ if (value == DEFAULT_VALUE_PLACEHOLDER ) {
1419
1419
attributes .put (attributeName ,
1420
1420
adaptValue (element , getDefaultValue (annotationType , attributeName ), classValuesAsString ,
1421
1421
nestedAnnotationsAsMap ));
0 commit comments