From a9cd45e7f26e319c24ff6d1438f23138f97e9e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Fri, 7 Oct 2022 17:29:43 +0200 Subject: [PATCH] Improve BindingReflectionHintsRegistrar extensibility This commit introduces a shouldSkipType(Class type) method and changes shouldRegisterMembers(Class type) to shouldSkipMembers(Class type). Closes gh-29279 --- .../hint/BindingReflectionHintsRegistrar.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java index d2356de7dd0..5fb6078b091 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java @@ -64,12 +64,21 @@ public class BindingReflectionHintsRegistrar { } /** - * Return whether the members of the type should be registered transitively. + * Return whether the type should be skipped. * @param type the type to evaluate - * @return {@code true} if the members of the type should be registered transitively + * @return {@code true} if the type should be skipped */ - protected boolean shouldRegisterMembers(Class type) { - return !type.getCanonicalName().startsWith("java.") && !type.isArray(); + protected boolean shouldSkipType(Class type) { + return type.isPrimitive() || type == Object.class; + } + + /** + * Return whether the members of the type should be skipped. + * @param type the type to evaluate + * @return {@code true} if the members of the type should be skipped + */ + protected boolean shouldSkipMembers(Class type) { + return type.getCanonicalName().startsWith("java.") || type.isArray(); } private void registerReflectionHints(ReflectionHints hints, Set seen, Type type) { @@ -78,11 +87,11 @@ public class BindingReflectionHintsRegistrar { } seen.add(type); if (type instanceof Class clazz) { - if (clazz.isPrimitive() || clazz == Object.class) { + if (shouldSkipType(clazz)) { return; } hints.registerType(clazz, typeHint -> { - if (shouldRegisterMembers(clazz)) { + if (!shouldSkipMembers(clazz)) { if (clazz.isRecord()) { typeHint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); for (RecordComponent recordComponent : clazz.getRecordComponents()) {