Skip to content

Commit 69f2309

Browse files
committed
Deprecate SynthesizedAnnotation and related methods
Since Spring no longer adds the SynthesizedAnnotation interface to the JDK dynamic proxy used to synthesize an annotation, this commit officially deprecates SynthesizedAnnotation and related methods in RuntimeHintsUtils. See gh-29041, gh-29054 Closes gh-29053
1 parent 0ec03a8 commit 69f2309

File tree

12 files changed

+37
-12
lines changed

12 files changed

+37
-12
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationsRuntimeHints.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
class BeanFactoryAnnotationsRuntimeHints implements RuntimeHintsRegistrar {
3131

3232
@Override
33+
@SuppressWarnings("deprecation")
3334
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3435
RuntimeHintsUtils.registerSynthesizedAnnotation(hints, Qualifier.class);
3536
}

spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public void registerRuntimeHints(RuntimeHints runtimeHints, Class<?>... types) {
6666
});
6767
}
6868

69+
@SuppressWarnings("deprecation")
6970
private void registerAnnotationIfNecessary(RuntimeHints hints, AnnotatedElement element) {
7071
MergedAnnotation<Reflective> reflectiveAnnotation = MergedAnnotations.from(element)
7172
.get(Reflective.class);

spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.aot.hint.TypeHint.Builder;
2525
import org.springframework.core.annotation.AliasFor;
2626
import org.springframework.core.annotation.MergedAnnotation;
27-
import org.springframework.core.annotation.SynthesizedAnnotation;
2827

2928
/**
3029
* Utility methods for runtime hints support code.
@@ -49,7 +48,7 @@ public abstract class RuntimeHintsUtils {
4948
* at runtime.
5049
* @param hints the {@link RuntimeHints} instance to use
5150
* @param annotationType the annotation type
52-
* @deprecated as annotation attributes are visible without additional hints
51+
* @deprecated For removal prior to Spring Framework 6.0
5352
*/
5453
@Deprecated
5554
public static void registerAnnotation(RuntimeHints hints, Class<?> annotationType) {
@@ -69,9 +68,13 @@ public static void registerAnnotation(RuntimeHints hints, Class<?> annotationTyp
6968
* that determines if the hints are required.
7069
* @param hints the {@link RuntimeHints} instance to use
7170
* @param annotationType the annotation type
71+
* @deprecated For removal prior to Spring Framework 6.0
7272
*/
73+
@Deprecated
74+
@SuppressWarnings("deprecation")
7375
public static void registerSynthesizedAnnotation(RuntimeHints hints, Class<?> annotationType) {
74-
hints.proxies().registerJdkProxy(annotationType, SynthesizedAnnotation.class);
76+
hints.proxies().registerJdkProxy(annotationType,
77+
org.springframework.core.annotation.SynthesizedAnnotation.class);
7578
}
7679

7780
/**
@@ -80,7 +83,9 @@ public static void registerSynthesizedAnnotation(RuntimeHints hints, Class<?> an
8083
* @param hints the {@link RuntimeHints} instance to use
8184
* @param annotation the annotation
8285
* @see #registerSynthesizedAnnotation(RuntimeHints, Class)
86+
* @deprecated For removal prior to Spring Framework 6.0
8387
*/
88+
@Deprecated
8489
public static void registerAnnotationIfNecessary(RuntimeHints hints, MergedAnnotation<?> annotation) {
8590
if (annotation.isSynthesizable()) {
8691
registerSynthesizedAnnotation(hints, annotation.getType());

spring-core/src/main/java/org/springframework/core/annotation/SynthesizedAnnotation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,10 @@
2323
*
2424
* @author Sam Brannen
2525
* @since 4.2
26+
* @deprecated For removal prior to Spring Framework 6.0; use
27+
* {@link AnnotationUtils#isSynthesizedAnnotation(java.lang.annotation.Annotation)}
28+
* instead.
2629
*/
30+
@Deprecated
2731
public interface SynthesizedAnnotation {
2832
}

spring-core/src/test/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrarTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.springframework.aot.hint.TypeReference;
3232
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
3333
import org.springframework.core.annotation.AliasFor;
34-
import org.springframework.core.annotation.SynthesizedAnnotation;
3534

3635
import static org.assertj.core.api.Assertions.assertThat;
3736
import static org.mockito.Mockito.mock;
@@ -95,11 +94,13 @@ void shouldNotRegisterAnnotationProxyIfNotNeeded() {
9594
}
9695

9796
@Test
97+
@SuppressWarnings("deprecation")
9898
void shouldRegisterAnnotationProxy() {
9999
process(SampleMethodMetaAnnotatedBeanWithAlias.class);
100100
RuntimeHints runtimeHints = this.runtimeHints;
101-
assertThat(RuntimeHintsPredicates.proxies().forInterfaces(
102-
SampleInvoker.class, SynthesizedAnnotation.class)).accepts(runtimeHints);
101+
assertThat(RuntimeHintsPredicates.proxies()
102+
.forInterfaces(SampleInvoker.class, org.springframework.core.annotation.SynthesizedAnnotation.class))
103+
.accepts(runtimeHints);
103104
}
104105

105106
@Test

spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.core.annotation.AliasFor;
2929
import org.springframework.core.annotation.MergedAnnotation;
3030
import org.springframework.core.annotation.MergedAnnotations;
31-
import org.springframework.core.annotation.SynthesizedAnnotation;
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
3433

@@ -43,13 +42,15 @@ class RuntimeHintsUtilsTests {
4342
private final RuntimeHints hints = new RuntimeHints();
4443

4544
@Test
45+
@SuppressWarnings("deprecation")
4646
void registerSynthesizedAnnotation() {
4747
RuntimeHintsUtils.registerSynthesizedAnnotation(this.hints, SampleInvoker.class);
4848
assertThat(this.hints.proxies().jdkProxies()).singleElement()
4949
.satisfies(annotationProxy(SampleInvoker.class));
5050
}
5151

5252
@Test
53+
@SuppressWarnings("deprecation")
5354
void registerAnnotationIfNecessaryWithNonSynthesizedAnnotation() throws NoSuchFieldException {
5455
MergedAnnotation<SampleInvoker> annotation = MergedAnnotations
5556
.from(TestBean.class.getField("sampleInvoker")).get(SampleInvoker.class);
@@ -58,6 +59,7 @@ void registerAnnotationIfNecessaryWithNonSynthesizedAnnotation() throws NoSuchFi
5859
}
5960

6061
@Test
62+
@SuppressWarnings("deprecation")
6163
void registerAnnotationIfNecessaryWithLocalAliases() throws NoSuchFieldException {
6264
MergedAnnotation<LocalMapping> annotation = MergedAnnotations
6365
.from(TestBean.class.getField("localMapping")).get(LocalMapping.class);
@@ -67,6 +69,7 @@ void registerAnnotationIfNecessaryWithLocalAliases() throws NoSuchFieldException
6769
}
6870

6971
@Test
72+
@SuppressWarnings("deprecation")
7073
void registerAnnotationIfNecessaryWithMetaAttributeOverride() throws NoSuchFieldException {
7174
MergedAnnotation<SampleInvoker> annotation = MergedAnnotations
7275
.from(TestBean.class.getField("retryInvoker")).get(SampleInvoker.class);
@@ -76,6 +79,7 @@ void registerAnnotationIfNecessaryWithMetaAttributeOverride() throws NoSuchField
7679
}
7780

7881
@Test
82+
@SuppressWarnings("deprecation")
7983
void registerAnnotationIfNecessaryWithSynthesizedAttribute() throws NoSuchFieldException {
8084
MergedAnnotation<RetryContainer> annotation = MergedAnnotations
8185
.from(TestBean.class.getField("retryContainer")).get(RetryContainer.class);
@@ -84,9 +88,11 @@ void registerAnnotationIfNecessaryWithSynthesizedAttribute() throws NoSuchFieldE
8488
.satisfies(annotationProxy(RetryContainer.class));
8589
}
8690

91+
@SuppressWarnings("deprecation")
8792
private Consumer<JdkProxyHint> annotationProxy(Class<?> type) {
8893
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
89-
.containsExactly(TypeReference.of(type), TypeReference.of(SynthesizedAnnotation.class));
94+
.containsExactly(TypeReference.of(type),
95+
TypeReference.of(org.springframework.core.annotation.SynthesizedAnnotation.class));
9096
}
9197

9298

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessagingAnnotationsRuntimeHints.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
public class MessagingAnnotationsRuntimeHints implements RuntimeHintsRegistrar {
3535

3636
@Override
37+
@SuppressWarnings("deprecation")
3738
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3839
Stream.of(Controller.class, Header.class, Headers.class, Payload.class).forEach(annotationType ->
3940
RuntimeHintsUtils.registerSynthesizedAnnotation(hints, annotationType));
4041
}
42+
4143
}

spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/SimpAnnotationsRuntimeHints.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
public class SimpAnnotationsRuntimeHints implements RuntimeHintsRegistrar {
3131

3232
@Override
33+
@SuppressWarnings("deprecation")
3334
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
3435
RuntimeHintsUtils.registerSynthesizedAnnotation(hints, SendToUser.class);
3536
}
37+
3638
}

spring-test/src/main/java/org/springframework/test/context/aot/hint/TestContextRuntimeHints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private static List<TypeReference> listOf(String... classNames) {
169169
}
170170

171171
@SafeVarargs
172-
@SuppressWarnings("unchecked")
172+
@SuppressWarnings({ "unchecked", "deprecation" })
173173
private static void registerSynthesizedAnnotations(RuntimeHints runtimeHints, Class<? extends Annotation>... annotationTypes) {
174174
for (Class<? extends Annotation> annotationType : annotationTypes) {
175175
registerAnnotation(runtimeHints.reflection(), annotationType);

spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.context.ApplicationContext;
3737
import org.springframework.context.ApplicationContextInitializer;
3838
import org.springframework.context.ConfigurableApplicationContext;
39-
import org.springframework.core.annotation.SynthesizedAnnotation;
4039
import org.springframework.javapoet.ClassName;
4140
import org.springframework.test.context.MergedContextConfiguration;
4241
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterSharedConfigTests;
@@ -210,9 +209,11 @@ private static void assertAnnotationRegistered(RuntimeHints runtimeHints, Class<
210209
.anySatisfy(annotationProxy(annotationType));
211210
}
212211

212+
@SuppressWarnings("deprecation")
213213
private static Consumer<JdkProxyHint> annotationProxy(Class<? extends Annotation> type) {
214214
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
215-
.containsExactly(TypeReference.of(type), TypeReference.of(SynthesizedAnnotation.class));
215+
.containsExactly(TypeReference.of(type),
216+
TypeReference.of(org.springframework.core.annotation.SynthesizedAnnotation.class));
216217
}
217218

218219
@Test

spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
class TransactionRuntimeHints implements RuntimeHintsRegistrar {
3636

3737
@Override
38+
@SuppressWarnings("deprecation")
3839
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
3940
RuntimeHintsUtils.registerSynthesizedAnnotation(hints, Transactional.class);
4041
hints.reflection().registerTypes(TypeReference.listOf(

spring-web/src/main/java/org/springframework/web/bind/annotation/WebAnnotationsRuntimeHintsRegistrar.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
public final class WebAnnotationsRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
3535

3636
@Override
37+
@SuppressWarnings("deprecation")
3738
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3839
Stream.of(Controller.class, ControllerAdvice.class, CookieValue.class,
3940
CrossOrigin.class, MatrixVariable.class, ModelAttribute.class,

0 commit comments

Comments
 (0)