Skip to content

Commit

Permalink
Fix BindingReflectionHintsRegistrar anonymous classes support
Browse files Browse the repository at this point in the history
This commit ensures that giving an anonymous class for reflection hints
registration does not result in a NullPointerException, since the
canonical name of anonymous classes is null.

Fixes gh-29657
  • Loading branch information
bclozel committed Dec 7, 2022
1 parent 92a6e7d commit d601f31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -71,7 +71,7 @@ private boolean shouldSkipType(Class<?> type) {
}

private boolean shouldSkipMembers(Class<?> type) {
return type.getCanonicalName().startsWith("java.") || type.isArray();
return (type.getCanonicalName() != null && type.getCanonicalName().startsWith("java.")) || type.isArray();
}

private void registerReflectionHints(ReflectionHints hints, Set<Type> seen, Type type) {
Expand Down
Expand Up @@ -221,6 +221,12 @@ void registerTypeForSerializationWithRecord() {
});
}

@Test
void registerTypeForSerializationWithAnonymousClass() {
Runnable anonymousRunnable = () -> { };
bindingRegistrar.registerReflectionHints(this.hints.reflection(), anonymousRunnable.getClass());
}

@Test
void registerTypeForJacksonAnnotations() {
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithJsonProperty.class);
Expand Down

0 comments on commit d601f31

Please sign in to comment.