Skip to content

Commit 1e5e8db

Browse files
committed
Add missing reflection hint in BeanRegistrationsAotContribution
Prior to this commit, the `BeanRegistrationsAotContribution` would only contribute introspection hints for declared methods. This does not cover inherited public methods. This commit adds the missing hint on public methods. Fixes gh-31293
1 parent db5ba85 commit 1e5e8db

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ private void generateRegisterHints(RuntimeHints runtimeHints, Map<BeanRegistrati
117117
registrations.keySet().forEach(beanRegistrationKey -> {
118118
ReflectionHints hints = runtimeHints.reflection();
119119
Class<?> beanClass = beanRegistrationKey.beanClass();
120-
hints.registerType(beanClass, MemberCategory.INTROSPECT_DECLARED_METHODS);
120+
hints.registerType(beanClass, MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS);
121121
// Workaround for https://github.com/oracle/graal/issues/6510
122122
if (beanClass.isRecord()) {
123-
hints.registerType(beanClass, MemberCategory.INVOKE_DECLARED_METHODS);
123+
hints.registerType(beanClass, MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS);
124124
}
125125
// Workaround for https://github.com/oracle/graal/issues/6529
126126
ReflectionUtils.doWithMethods(beanClass, method -> {

spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void applyToRegisterReflectionHints() {
147147
BeanRegistrationsAotContribution contribution = createContribution(TestBean.class, generator);
148148
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
149149
assertThat(reflection().onType(TestBean.class)
150-
.withMemberCategory(MemberCategory.INTROSPECT_DECLARED_METHODS))
150+
.withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS))
151151
.accepts(this.generationContext.getRuntimeHints());
152152
}
153153

@@ -159,7 +159,8 @@ void applyToRegisterReflectionHintsOnRecordBean() {
159159
BeanRegistrationsAotContribution contribution = createContribution(RecordBean.class, generator);
160160
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
161161
assertThat(reflection().onType(RecordBean.class)
162-
.withMemberCategories(MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_METHODS))
162+
.withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS,
163+
MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS))
163164
.accepts(this.generationContext.getRuntimeHints());
164165
}
165166

0 commit comments

Comments
 (0)