From 14c5228288535106dcd3a5866232bba2463b3df9 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 3 Oct 2023 13:37:26 +0200 Subject: [PATCH] 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 --- .../aot/BeanRegistrationsAotContribution.java | 19 -------------- ...BeanRegistrationsAotContributionTests.java | 26 ------------------- .../beans/GenericBeanWithBounds.java | 24 ----------------- .../beans/testfixture/beans/RecordBean.java | 19 -------------- 4 files changed, 88 deletions(-) delete mode 100644 spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/GenericBeanWithBounds.java delete mode 100644 spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/RecordBean.java diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java index 7b74a7b488a..432201b47aa 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java @@ -16,8 +16,6 @@ package org.springframework.beans.factory.aot; -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.Type; import java.util.Map; import javax.lang.model.element.Modifier; @@ -32,12 +30,10 @@ import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.core.ResolvableType; import org.springframework.javapoet.ClassName; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.util.ClassUtils; -import org.springframework.util.ReflectionUtils; /** * AOT contribution from a {@link BeanRegistrationsAotProcessor} used to @@ -128,21 +124,6 @@ class BeanRegistrationsAotContribution } currentClass = currentClass.getSuperclass(); } - // Workaround for https://github.com/oracle/graal/issues/6510 - if (beanClass.isRecord()) { - hints.registerType(beanClass, MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS); - } - // Workaround for https://github.com/oracle/graal/issues/6529 - ReflectionUtils.doWithMethods(beanClass, method -> { - for (Type type : method.getGenericParameterTypes()) { - if (type instanceof GenericArrayType) { - Class clazz = ResolvableType.forType(type).resolve(); - if (clazz != null) { - hints.registerType(clazz); - } - } - } - }); }); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java index d9a0e337af9..0c2482b1478 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java @@ -37,10 +37,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.testfixture.beans.Employee; -import org.springframework.beans.testfixture.beans.GenericBeanWithBounds; import org.springframework.beans.testfixture.beans.ITestBean; -import org.springframework.beans.testfixture.beans.Person; -import org.springframework.beans.testfixture.beans.RecordBean; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.beans.testfixture.beans.factory.aot.MockBeanFactoryInitializationCode; import org.springframework.core.test.io.support.MockSpringFactoriesLoader; @@ -156,29 +153,6 @@ class BeanRegistrationsAotContributionTests { .accepts(this.generationContext.getRuntimeHints()); } - @Test - void applyToRegisterReflectionHintsOnRecordBean() { - RegisteredBean registeredBean = registerBean(new RootBeanDefinition(RecordBean.class)); - BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory, - registeredBean, null, List.of()); - BeanRegistrationsAotContribution contribution = createContribution(RecordBean.class, generator); - contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode); - assertThat(reflection().onType(RecordBean.class) - .withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS, - MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS)) - .accepts(this.generationContext.getRuntimeHints()); - } - - @Test - void applyToRegisterReflectionHintsOnGenericBeanWithBounds() { - RegisteredBean registeredBean = registerBean(new RootBeanDefinition(GenericBeanWithBounds.class)); - BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory, - registeredBean, null, List.of()); - BeanRegistrationsAotContribution contribution = createContribution(GenericBeanWithBounds.class, generator); - contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode); - assertThat(reflection().onType(Person[].class)).accepts(this.generationContext.getRuntimeHints()); - } - private RegisteredBean registerBean(RootBeanDefinition rootBeanDefinition) { String beanName = "testBean"; this.beanFactory.registerBeanDefinition(beanName, rootBeanDefinition); diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/GenericBeanWithBounds.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/GenericBeanWithBounds.java deleted file mode 100644 index 647c071cbfd..00000000000 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/GenericBeanWithBounds.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2002-2023 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.beans.testfixture.beans; - -public class GenericBeanWithBounds { - - @SafeVarargs - public final void process(T... persons) { - } -} diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/RecordBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/RecordBean.java deleted file mode 100644 index 75419ab1cb7..00000000000 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/RecordBean.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2002-2023 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.beans.testfixture.beans; - -public record RecordBean(String name) { }