Skip to content

Commit eac616a

Browse files
committed
Restore support for package private ReflectiveProcessor
See gh-28975
1 parent d6afa8d commit eac616a

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ private Entry createEntry(AnnotatedElement element) {
113113

114114
private ReflectiveProcessor instantiateClass(Class<? extends ReflectiveProcessor> type) {
115115
try {
116-
return type.getDeclaredConstructor().newInstance();
116+
Constructor<? extends ReflectiveProcessor> constructor = type.getDeclaredConstructor();
117+
ReflectionUtils.makeAccessible(constructor);
118+
return constructor.newInstance();
117119
}
118120
catch (Exception ex) {
119121
throw new IllegalStateException("Failed to instantiate " + type, ex);

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
import java.lang.annotation.Retention;
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
24+
import java.lang.reflect.Method;
2425

2526
import org.junit.jupiter.api.Test;
2627

28+
import org.springframework.aot.hint.MemberCategory;
29+
import org.springframework.aot.hint.ReflectionHints;
2730
import org.springframework.aot.hint.RuntimeHints;
2831
import org.springframework.aot.hint.TypeReference;
2932
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
@@ -121,6 +124,16 @@ void shouldProcessAnnotationOnInheritedClass() {
121124
.satisfies(methodHint -> assertThat(methodHint.getName()).isEqualTo("managed")));
122125
}
123126

127+
@Test
128+
void shouldInvokeCustomProcessor() {
129+
process(SampleCustomProcessor.class);
130+
assertThat(RuntimeHintsPredicates.reflection()
131+
.onMethod(SampleCustomProcessor.class, "managed")).accepts(this.runtimeHints);
132+
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)
133+
.withMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.runtimeHints);
134+
135+
}
136+
124137
private void process(Class<?> beanClass) {
125138
this.registrar.registerRuntimeHints(this.runtimeHints, beanClass);
126139
}
@@ -252,4 +265,24 @@ void managed() {
252265
}
253266
}
254267

268+
static class SampleCustomProcessor {
269+
270+
@Reflective(TestReflectiveProcessor.class)
271+
public String managed() {
272+
return "test";
273+
}
274+
275+
}
276+
277+
private static class TestReflectiveProcessor extends SimpleReflectiveProcessor {
278+
279+
@Override
280+
protected void registerMethodHint(ReflectionHints hints, Method method) {
281+
super.registerMethodHint(hints, method);
282+
hints.registerType(method.getReturnType(), type ->
283+
type.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
284+
}
285+
286+
}
287+
255288
}

0 commit comments

Comments
 (0)