Restore native support for record beans

After b374824319 related
to gh-29246, `"queryAllDeclaredMethods": true` is now added
on all registered beans.

This legit change triggers oracle/graal#6510. This
commit workarounds this GraalVM bug, and should be
removed once the GraalVM fix has reached a wide enough
audience.

Closes gh-30383
This commit is contained in:
Sébastien Deleuze
2023-04-28 09:57:22 +02:00
parent 82e5464972
commit cefb734763
3 changed files with 49 additions and 9 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.generate.MethodReference;
import org.springframework.aot.generate.MethodReference.ArgumentCodeGenerator;
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.javapoet.ClassName;
@@ -109,8 +110,15 @@ class BeanRegistrationsAotContribution
}
private void generateRegisterHints(RuntimeHints runtimeHints, Map<BeanRegistrationKey, Registration> registrations) {
registrations.keySet().forEach(beanRegistrationKey -> runtimeHints.reflection()
.registerType(beanRegistrationKey.beanClass(), MemberCategory.INTROSPECT_DECLARED_METHODS));
registrations.keySet().forEach(beanRegistrationKey -> {
ReflectionHints hints = runtimeHints.reflection();
Class<?> beanClass = beanRegistrationKey.beanClass();
hints.registerType(beanClass, MemberCategory.INTROSPECT_DECLARED_METHODS);
// Workaround for https://github.com/oracle/graal/issues/6510
if (beanClass.isRecord()) {
hints.registerType(beanClass, MemberCategory.INVOKE_DECLARED_METHODS);
}
});
}
/**