Skip to content

NullPointerException if passing an anonymous class to ReflectionsHint#registerType #29774

@Artur-

Description

@Artur-

If you (accidentally in this case) pass an anonymous class to registerType it fails with

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "org.springframework.aot.hint.AbstractTypeReference.getCanonicalName()" is null
	at org.springframework.aot.hint.AbstractTypeReference.equals(AbstractTypeReference.java:93)
	at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1214)
	at org.springframework.aot.hint.ReflectionHints.registerType(ReflectionHints.java:85)
	at org.springframework.aot.hint.ReflectionHints.registerType(ReflectionHints.java:98)
	at org.springframework.aot.hint.ReflectionHints.registerType(ReflectionHints.java:120)

This happened to us when trying to use

for (var c : reflections.getSubTypesOf(Converter.class)) {
     reflection.registerType(c, memberCategories);
}

and so it happens that Converter contains

public interface Converter<PRESENTATION, MODEL> extends Serializable {
...
    static <P, M> Converter<P, M> from(
            SerializableFunction<P, Result<M>> toModel,
            SerializableFunction<M, P> toPresentation) {
        return new Converter<P, M>() {
...

Seems like the org.reflections library returns Converter$2 as one of the sub types, which then fails when passed to registerType.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingtype: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions