@@ -514,7 +514,7 @@ private static <A extends Annotation> A findAnnotation(AnnotatedElement annotate
514514 try {
515515 Annotation [] anns = annotatedElement .getDeclaredAnnotations ();
516516 for (Annotation ann : anns ) {
517- if (ann .annotationType (). equals ( annotationType ) ) {
517+ if (ann .annotationType () == annotationType ) {
518518 return (A ) ann ;
519519 }
520520 }
@@ -703,7 +703,7 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A>
703703 try {
704704 Annotation [] anns = clazz .getDeclaredAnnotations ();
705705 for (Annotation ann : anns ) {
706- if (ann .annotationType (). equals ( annotationType ) ) {
706+ if (ann .annotationType () == annotationType ) {
707707 return (A ) ann ;
708708 }
709709 }
@@ -828,7 +828,7 @@ public static boolean isAnnotationDeclaredLocally(Class<? extends Annotation> an
828828 Assert .notNull (clazz , "Class must not be null" );
829829 try {
830830 for (Annotation ann : clazz .getDeclaredAnnotations ()) {
831- if (ann .annotationType (). equals ( annotationType ) ) {
831+ if (ann .annotationType () == annotationType ) {
832832 return true ;
833833 }
834834 }
@@ -1360,7 +1360,8 @@ public static <A extends Annotation> A synthesizeAnnotation(A annotation, Annota
13601360 if (annotation == null ) {
13611361 return null ;
13621362 }
1363- if (annotation instanceof SynthesizedAnnotation ) {
1363+ if (annotation instanceof SynthesizedAnnotation || (Proxy .isProxyClass (annotation .getClass ()) &&
1364+ Proxy .getInvocationHandler (annotation ) instanceof SynthesizedAnnotationInvocationHandler )) {
13641365 return annotation ;
13651366 }
13661367
@@ -1372,8 +1373,9 @@ public static <A extends Annotation> A synthesizeAnnotation(A annotation, Annota
13721373 DefaultAnnotationAttributeExtractor attributeExtractor =
13731374 new DefaultAnnotationAttributeExtractor (annotation , annotatedElement );
13741375 InvocationHandler handler = new SynthesizedAnnotationInvocationHandler (attributeExtractor );
1375- return (A ) Proxy .newProxyInstance (annotation .getClass ().getClassLoader (),
1376- new Class <?>[] {(Class <A >) annotationType , SynthesizedAnnotation .class }, handler );
1376+ Class <?>[] exposedInterfaces = (canExposeSynthesizedMarker (annotationType ) ?
1377+ new Class <?>[] {annotationType , SynthesizedAnnotation .class } : new Class <?>[] {annotationType });
1378+ return (A ) Proxy .newProxyInstance (annotation .getClass ().getClassLoader (), exposedInterfaces , handler );
13771379 }
13781380
13791381 /**
@@ -1418,8 +1420,9 @@ public static <A extends Annotation> A synthesizeAnnotation(Map<String, Object>
14181420 MapAnnotationAttributeExtractor attributeExtractor =
14191421 new MapAnnotationAttributeExtractor (attributes , annotationType , annotatedElement );
14201422 InvocationHandler handler = new SynthesizedAnnotationInvocationHandler (attributeExtractor );
1421- return (A ) Proxy .newProxyInstance (annotationType .getClassLoader (),
1422- new Class <?>[] {annotationType , SynthesizedAnnotation .class }, handler );
1423+ Class <?>[] exposedInterfaces = (canExposeSynthesizedMarker (annotationType ) ?
1424+ new Class <?>[] {annotationType , SynthesizedAnnotation .class } : new Class <?>[] {annotationType });
1425+ return (A ) Proxy .newProxyInstance (annotationType .getClassLoader (), exposedInterfaces , handler );
14231426 }
14241427
14251428 /**
@@ -1539,10 +1542,23 @@ static Map<String, List<String>> getAttributeAliasMap(Class<? extends Annotation
15391542 }
15401543
15411544 attributeAliasesCache .put (annotationType , map );
1542-
15431545 return map ;
15441546 }
15451547
1548+ /**
1549+ * Check whether we can expose our {@link SynthesizedAnnotation} marker for the given annotation type.
1550+ * @param annotationType the annotation type that we are about to create a synthesized proxy for
1551+ */
1552+ private static boolean canExposeSynthesizedMarker (Class <? extends Annotation > annotationType ) {
1553+ try {
1554+ return (Class .forName (SynthesizedAnnotation .class .getName (), false , annotationType .getClassLoader ()) ==
1555+ SynthesizedAnnotation .class );
1556+ }
1557+ catch (ClassNotFoundException ex ) {
1558+ return false ;
1559+ }
1560+ }
1561+
15461562 /**
15471563 * Determine if annotations of the supplied {@code annotationType} are
15481564 * <em>synthesizable</em> (i.e., in need of being wrapped in a dynamic
@@ -1629,7 +1645,7 @@ static List<String> getAttributeAliasNames(Method attribute) {
16291645 static String getAttributeOverrideName (Method attribute , Class <? extends Annotation > metaAnnotationType ) {
16301646 Assert .notNull (attribute , "attribute must not be null" );
16311647 Assert .notNull (metaAnnotationType , "metaAnnotationType must not be null" );
1632- Assert .isTrue (! Annotation .class . equals ( metaAnnotationType ) ,
1648+ Assert .isTrue (Annotation .class != metaAnnotationType ,
16331649 "metaAnnotationType must not be [java.lang.annotation.Annotation]" );
16341650
16351651 AliasDescriptor descriptor = AliasDescriptor .from (attribute );
@@ -1931,7 +1947,7 @@ private AliasDescriptor(Method sourceAttribute, AliasFor aliasFor) {
19311947 this .sourceAnnotationType = (Class <? extends Annotation >) declaringClass ;
19321948 this .sourceAttributeName = this .sourceAttribute .getName ();
19331949
1934- this .aliasedAnnotationType = (Annotation .class . equals ( aliasFor .annotation () ) ?
1950+ this .aliasedAnnotationType = (Annotation .class == aliasFor .annotation () ?
19351951 this .sourceAnnotationType : aliasFor .annotation ());
19361952 this .aliasedAttributeName = getAliasedAttributeName (aliasFor , this .sourceAttribute );
19371953 try {
@@ -1945,7 +1961,7 @@ private AliasDescriptor(Method sourceAttribute, AliasFor aliasFor) {
19451961 throw new AnnotationConfigurationException (msg , ex );
19461962 }
19471963
1948- this .isAliasPair = this .sourceAnnotationType . equals ( this .aliasedAnnotationType );
1964+ this .isAliasPair = ( this .sourceAnnotationType == this .aliasedAnnotationType );
19491965 }
19501966
19511967 private void validate () {
@@ -1979,7 +1995,7 @@ private void validate() {
19791995
19801996 Class <?> returnType = this .sourceAttribute .getReturnType ();
19811997 Class <?> aliasedReturnType = this .aliasedAttribute .getReturnType ();
1982- if (! returnType . equals ( aliasedReturnType ) ) {
1998+ if (returnType != aliasedReturnType ) {
19831999 String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] " +
19842000 "and attribute [%s] in annotation [%s] must declare the same return type." ,
19852001 this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
@@ -2030,7 +2046,7 @@ private void validateAgainst(AliasDescriptor otherDescriptor) {
20302046 * @see #isAliasFor
20312047 */
20322048 private boolean isOverrideFor (Class <? extends Annotation > metaAnnotationType ) {
2033- return this .aliasedAnnotationType . equals ( metaAnnotationType );
2049+ return ( this .aliasedAnnotationType == metaAnnotationType );
20342050 }
20352051
20362052 /**
@@ -2087,7 +2103,7 @@ private List<AliasDescriptor> getOtherDescriptors() {
20872103
20882104 public String getAttributeOverrideName (Class <? extends Annotation > metaAnnotationType ) {
20892105 Assert .notNull (metaAnnotationType , "metaAnnotationType must not be null" );
2090- Assert .isTrue (! Annotation .class . equals ( metaAnnotationType ) ,
2106+ Assert .isTrue (Annotation .class != metaAnnotationType ,
20912107 "metaAnnotationType must not be [java.lang.annotation.Annotation]" );
20922108
20932109 // Search the attribute override hierarchy, starting with the current attribute
0 commit comments