Skip to content

Commit 14c5228

Browse files
committed
Remove reflection hints workarounds for GraalVM issues
This commit removes the previously introduced reflection hints that were working around known issues in GraalVM. Spring Framework 6.1 will require recent maintenance versions of GraalVM and should not contribute such hints anymore. Closes gh-30394
1 parent 1fd5491 commit 14c5228

File tree

4 files changed

+0
-88
lines changed

4 files changed

+0
-88
lines changed

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.beans.factory.aot;
1818

19-
import java.lang.reflect.GenericArrayType;
20-
import java.lang.reflect.Type;
2119
import java.util.Map;
2220

2321
import javax.lang.model.element.Modifier;
@@ -32,12 +30,10 @@
3230
import org.springframework.aot.hint.ReflectionHints;
3331
import org.springframework.aot.hint.RuntimeHints;
3432
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
35-
import org.springframework.core.ResolvableType;
3633
import org.springframework.javapoet.ClassName;
3734
import org.springframework.javapoet.CodeBlock;
3835
import org.springframework.javapoet.MethodSpec;
3936
import org.springframework.util.ClassUtils;
40-
import org.springframework.util.ReflectionUtils;
4137

4238
/**
4339
* AOT contribution from a {@link BeanRegistrationsAotProcessor} used to
@@ -128,21 +124,6 @@ private void generateRegisterHints(RuntimeHints runtimeHints, Map<BeanRegistrati
128124
}
129125
currentClass = currentClass.getSuperclass();
130126
}
131-
// Workaround for https://github.com/oracle/graal/issues/6510
132-
if (beanClass.isRecord()) {
133-
hints.registerType(beanClass, MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS);
134-
}
135-
// Workaround for https://github.com/oracle/graal/issues/6529
136-
ReflectionUtils.doWithMethods(beanClass, method -> {
137-
for (Type type : method.getGenericParameterTypes()) {
138-
if (type instanceof GenericArrayType) {
139-
Class<?> clazz = ResolvableType.forType(type).resolve();
140-
if (clazz != null) {
141-
hints.registerType(clazz);
142-
}
143-
}
144-
}
145-
});
146127
});
147128
}
148129

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
import org.springframework.beans.factory.support.RegisteredBean;
3838
import org.springframework.beans.factory.support.RootBeanDefinition;
3939
import org.springframework.beans.testfixture.beans.Employee;
40-
import org.springframework.beans.testfixture.beans.GenericBeanWithBounds;
4140
import org.springframework.beans.testfixture.beans.ITestBean;
42-
import org.springframework.beans.testfixture.beans.Person;
43-
import org.springframework.beans.testfixture.beans.RecordBean;
4441
import org.springframework.beans.testfixture.beans.TestBean;
4542
import org.springframework.beans.testfixture.beans.factory.aot.MockBeanFactoryInitializationCode;
4643
import org.springframework.core.test.io.support.MockSpringFactoriesLoader;
@@ -156,29 +153,6 @@ void applyToRegisterReflectionHints() {
156153
.accepts(this.generationContext.getRuntimeHints());
157154
}
158155

159-
@Test
160-
void applyToRegisterReflectionHintsOnRecordBean() {
161-
RegisteredBean registeredBean = registerBean(new RootBeanDefinition(RecordBean.class));
162-
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory,
163-
registeredBean, null, List.of());
164-
BeanRegistrationsAotContribution contribution = createContribution(RecordBean.class, generator);
165-
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
166-
assertThat(reflection().onType(RecordBean.class)
167-
.withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS,
168-
MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS))
169-
.accepts(this.generationContext.getRuntimeHints());
170-
}
171-
172-
@Test
173-
void applyToRegisterReflectionHintsOnGenericBeanWithBounds() {
174-
RegisteredBean registeredBean = registerBean(new RootBeanDefinition(GenericBeanWithBounds.class));
175-
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory,
176-
registeredBean, null, List.of());
177-
BeanRegistrationsAotContribution contribution = createContribution(GenericBeanWithBounds.class, generator);
178-
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
179-
assertThat(reflection().onType(Person[].class)).accepts(this.generationContext.getRuntimeHints());
180-
}
181-
182156
private RegisteredBean registerBean(RootBeanDefinition rootBeanDefinition) {
183157
String beanName = "testBean";
184158
this.beanFactory.registerBeanDefinition(beanName, rootBeanDefinition);

spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/GenericBeanWithBounds.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/RecordBean.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)