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
This commit is contained in:
@@ -66,6 +66,7 @@ public class ReflectiveRuntimeHintsRegistrar {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void registerAnnotationIfNecessary(RuntimeHints hints, AnnotatedElement element) {
|
||||
MergedAnnotation<Reflective> reflectiveAnnotation = MergedAnnotations.from(element)
|
||||
.get(Reflective.class);
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.aot.hint.TypeHint;
|
||||
import org.springframework.aot.hint.TypeHint.Builder;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.MergedAnnotation;
|
||||
import org.springframework.core.annotation.SynthesizedAnnotation;
|
||||
|
||||
/**
|
||||
* Utility methods for runtime hints support code.
|
||||
@@ -49,7 +48,7 @@ public abstract class RuntimeHintsUtils {
|
||||
* at runtime.
|
||||
* @param hints the {@link RuntimeHints} instance to use
|
||||
* @param annotationType the annotation type
|
||||
* @deprecated as annotation attributes are visible without additional hints
|
||||
* @deprecated For removal prior to Spring Framework 6.0
|
||||
*/
|
||||
@Deprecated
|
||||
public static void registerAnnotation(RuntimeHints hints, Class<?> annotationType) {
|
||||
@@ -69,9 +68,13 @@ public abstract class RuntimeHintsUtils {
|
||||
* that determines if the hints are required.
|
||||
* @param hints the {@link RuntimeHints} instance to use
|
||||
* @param annotationType the annotation type
|
||||
* @deprecated For removal prior to Spring Framework 6.0
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void registerSynthesizedAnnotation(RuntimeHints hints, Class<?> annotationType) {
|
||||
hints.proxies().registerJdkProxy(annotationType, SynthesizedAnnotation.class);
|
||||
hints.proxies().registerJdkProxy(annotationType,
|
||||
org.springframework.core.annotation.SynthesizedAnnotation.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +83,9 @@ public abstract class RuntimeHintsUtils {
|
||||
* @param hints the {@link RuntimeHints} instance to use
|
||||
* @param annotation the annotation
|
||||
* @see #registerSynthesizedAnnotation(RuntimeHints, Class)
|
||||
* @deprecated For removal prior to Spring Framework 6.0
|
||||
*/
|
||||
@Deprecated
|
||||
public static void registerAnnotationIfNecessary(RuntimeHints hints, MergedAnnotation<?> annotation) {
|
||||
if (annotation.isSynthesizable()) {
|
||||
registerSynthesizedAnnotation(hints, annotation.getType());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -23,6 +23,10 @@ package org.springframework.core.annotation;
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.2
|
||||
* @deprecated For removal prior to Spring Framework 6.0; use
|
||||
* {@link AnnotationUtils#isSynthesizedAnnotation(java.lang.annotation.Annotation)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface SynthesizedAnnotation {
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.SynthesizedAnnotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -95,11 +94,13 @@ class ReflectiveRuntimeHintsRegistrarTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void shouldRegisterAnnotationProxy() {
|
||||
process(SampleMethodMetaAnnotatedBeanWithAlias.class);
|
||||
RuntimeHints runtimeHints = this.runtimeHints;
|
||||
assertThat(RuntimeHintsPredicates.proxies().forInterfaces(
|
||||
SampleInvoker.class, SynthesizedAnnotation.class)).accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.proxies()
|
||||
.forInterfaces(SampleInvoker.class, org.springframework.core.annotation.SynthesizedAnnotation.class))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.MergedAnnotation;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.core.annotation.SynthesizedAnnotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -43,6 +42,7 @@ class RuntimeHintsUtilsTests {
|
||||
private final RuntimeHints hints = new RuntimeHints();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void registerSynthesizedAnnotation() {
|
||||
RuntimeHintsUtils.registerSynthesizedAnnotation(this.hints, SampleInvoker.class);
|
||||
assertThat(this.hints.proxies().jdkProxies()).singleElement()
|
||||
@@ -50,6 +50,7 @@ class RuntimeHintsUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void registerAnnotationIfNecessaryWithNonSynthesizedAnnotation() throws NoSuchFieldException {
|
||||
MergedAnnotation<SampleInvoker> annotation = MergedAnnotations
|
||||
.from(TestBean.class.getField("sampleInvoker")).get(SampleInvoker.class);
|
||||
@@ -58,6 +59,7 @@ class RuntimeHintsUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void registerAnnotationIfNecessaryWithLocalAliases() throws NoSuchFieldException {
|
||||
MergedAnnotation<LocalMapping> annotation = MergedAnnotations
|
||||
.from(TestBean.class.getField("localMapping")).get(LocalMapping.class);
|
||||
@@ -67,6 +69,7 @@ class RuntimeHintsUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void registerAnnotationIfNecessaryWithMetaAttributeOverride() throws NoSuchFieldException {
|
||||
MergedAnnotation<SampleInvoker> annotation = MergedAnnotations
|
||||
.from(TestBean.class.getField("retryInvoker")).get(SampleInvoker.class);
|
||||
@@ -76,6 +79,7 @@ class RuntimeHintsUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void registerAnnotationIfNecessaryWithSynthesizedAttribute() throws NoSuchFieldException {
|
||||
MergedAnnotation<RetryContainer> annotation = MergedAnnotations
|
||||
.from(TestBean.class.getField("retryContainer")).get(RetryContainer.class);
|
||||
@@ -84,9 +88,11 @@ class RuntimeHintsUtilsTests {
|
||||
.satisfies(annotationProxy(RetryContainer.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private Consumer<JdkProxyHint> annotationProxy(Class<?> type) {
|
||||
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
|
||||
.containsExactly(TypeReference.of(type), TypeReference.of(SynthesizedAnnotation.class));
|
||||
.containsExactly(TypeReference.of(type),
|
||||
TypeReference.of(org.springframework.core.annotation.SynthesizedAnnotation.class));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user