Restore support for package private ReflectiveProcessor
See gh-28975
This commit is contained in:
@@ -113,7 +113,9 @@ public class ReflectiveRuntimeHintsRegistrar {
|
||||
|
||||
private ReflectiveProcessor instantiateClass(Class<? extends ReflectiveProcessor> type) {
|
||||
try {
|
||||
return type.getDeclaredConstructor().newInstance();
|
||||
Constructor<? extends ReflectiveProcessor> constructor = type.getDeclaredConstructor();
|
||||
ReflectionUtils.makeAccessible(constructor);
|
||||
return constructor.newInstance();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to instantiate " + type, ex);
|
||||
|
||||
@@ -21,9 +21,12 @@ import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.ReflectionHints;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
@@ -121,6 +124,16 @@ class ReflectiveRuntimeHintsRegistrarTests {
|
||||
.satisfies(methodHint -> assertThat(methodHint.getName()).isEqualTo("managed")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInvokeCustomProcessor() {
|
||||
process(SampleCustomProcessor.class);
|
||||
assertThat(RuntimeHintsPredicates.reflection()
|
||||
.onMethod(SampleCustomProcessor.class, "managed")).accepts(this.runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)
|
||||
.withMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
private void process(Class<?> beanClass) {
|
||||
this.registrar.registerRuntimeHints(this.runtimeHints, beanClass);
|
||||
}
|
||||
@@ -252,4 +265,24 @@ class ReflectiveRuntimeHintsRegistrarTests {
|
||||
}
|
||||
}
|
||||
|
||||
static class SampleCustomProcessor {
|
||||
|
||||
@Reflective(TestReflectiveProcessor.class)
|
||||
public String managed() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class TestReflectiveProcessor extends SimpleReflectiveProcessor {
|
||||
|
||||
@Override
|
||||
protected void registerMethodHint(ReflectionHints hints, Method method) {
|
||||
super.registerMethodHint(hints, method);
|
||||
hints.registerType(method.getReturnType(), type ->
|
||||
type.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user