diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHintsPredicates.java b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHintsPredicates.java index db3c9a81505..c74cb78501b 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHintsPredicates.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHintsPredicates.java @@ -286,7 +286,8 @@ public class ReflectionHintsPredicates { @Override Predicate exactMatch() { - return hints -> hints.reflection().getTypeHint(this.executable.getDeclaringClass()).constructors().anyMatch(executableHint -> { + return hints -> (hints.reflection().getTypeHint(this.executable.getDeclaringClass()) != null) && + hints.reflection().getTypeHint(this.executable.getDeclaringClass()).constructors().anyMatch(executableHint -> { List parameters = Arrays.stream(this.executable.getParameterTypes()).map(TypeReference::of).toList(); ExecutableHint syntheticHint = ExecutableHint.ofConstructor(parameters) .setModes(this.executableMode).build(); diff --git a/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsPredicatesTests.java b/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsPredicatesTests.java index 6953a325928..2ef2c8f0177 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsPredicatesTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsPredicatesTests.java @@ -136,6 +136,11 @@ class ReflectionHintsPredicatesTests { @Nested class ReflectionOnConstructor { + @Test + void constructorIntrospectionDoesNotMatchMissingHint() { + assertPredicateDoesNotMatch(reflection.onConstructor(publicConstructor).introspect()); + } + @Test void constructorIntrospectionMatchesConstructorHint() { runtimeHints.reflection().registerType(SampleClass.class, typeHint -> typeHint.withConstructor(Collections.emptyList(), constructorHint -> {