Skip to content

Commit d601f31

Browse files
committed
Fix BindingReflectionHintsRegistrar anonymous classes support
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
1 parent 92a6e7d commit d601f31

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private boolean shouldSkipType(Class<?> type) {
7171
}
7272

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

7777
private void registerReflectionHints(ReflectionHints hints, Set<Type> seen, Type type) {

spring-core/src/test/java/org/springframework/aot/hint/BindingReflectionHintsRegistrarTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ void registerTypeForSerializationWithRecord() {
221221
});
222222
}
223223

224+
@Test
225+
void registerTypeForSerializationWithAnonymousClass() {
226+
Runnable anonymousRunnable = () -> { };
227+
bindingRegistrar.registerReflectionHints(this.hints.reflection(), anonymousRunnable.getClass());
228+
}
229+
224230
@Test
225231
void registerTypeForJacksonAnnotations() {
226232
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithJsonProperty.class);

0 commit comments

Comments
 (0)