Fix NPE in Constructor predicate
This commit fixes a NullPointerException issue in the constructor hint predicate. Prior to this commit, a hint for a constructor was directly looked up and dereferenced a type hint without checking if there was one first.
This commit is contained in:
parent
772d801e48
commit
7a3e8bf648
|
|
@ -286,7 +286,8 @@ public class ReflectionHintsPredicates {
|
|||
|
||||
@Override
|
||||
Predicate<RuntimeHints> 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<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes()).map(TypeReference::of).toList();
|
||||
ExecutableHint syntheticHint = ExecutableHint.ofConstructor(parameters)
|
||||
.setModes(this.executableMode).build();
|
||||
|
|
|
|||
|
|
@ -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 -> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue