diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java index f7a8076728..ddd84aa620 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java @@ -28,21 +28,16 @@ final class ReflectionTypeReference extends AbstractTypeReference { private final Class type; private ReflectionTypeReference(Class type) { - super(type.getPackageName(), type.getSimpleName(), safeCreate(getEnclosingClass(type))); + super(type.getPackageName(), type.getSimpleName(), getEnclosingClass(type)); this.type = type; } @Nullable - private static Class getEnclosingClass(Class type) { - if (type.isArray()) { - return type.getComponentType().getEnclosingClass(); - } - return type.getEnclosingClass(); - } - - @Nullable - private static ReflectionTypeReference safeCreate(@Nullable Class type) { - return (type != null ? new ReflectionTypeReference(type) : null); + private static TypeReference getEnclosingClass(Class type) { + Class candidate = (type.isArray() + ? type.getComponentType().getEnclosingClass() + : type.getEnclosingClass()); + return (candidate != null ? new ReflectionTypeReference(candidate) : null); } static ReflectionTypeReference of(Class type) { diff --git a/spring-core/src/test/java/org/springframework/aot/hint/ReflectionTypeReferenceTests.java b/spring-core/src/test/java/org/springframework/aot/hint/ReflectionTypeReferenceTests.java index 73895db9e2..e36883cea2 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/ReflectionTypeReferenceTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/ReflectionTypeReferenceTests.java @@ -44,10 +44,14 @@ class ReflectionTypeReferenceTests { Arguments.of(ReflectionTypeReference.of(int[].class), "int[]"), Arguments.of(ReflectionTypeReference.of(Integer[].class), "java.lang.Integer[]"), Arguments.of(ReflectionTypeReference.of(Object[].class), "java.lang.Object[]"), - Arguments.of(ReflectionTypeReference.of(StaticInner.class), "org.springframework.aot.hint.ReflectionTypeReferenceTests$StaticInner"), - Arguments.of(ReflectionTypeReference.of(StaticInner[].class), "org.springframework.aot.hint.ReflectionTypeReferenceTests$StaticInner[]"), - Arguments.of(ReflectionTypeReference.of(Inner.class), "org.springframework.aot.hint.ReflectionTypeReferenceTests$Inner"), - Arguments.of(ReflectionTypeReference.of(Inner[].class), "org.springframework.aot.hint.ReflectionTypeReferenceTests$Inner[]") + Arguments.of(ReflectionTypeReference.of(StaticInner.class), + "org.springframework.aot.hint.ReflectionTypeReferenceTests$StaticInner"), + Arguments.of(ReflectionTypeReference.of(StaticInner[].class), + "org.springframework.aot.hint.ReflectionTypeReferenceTests$StaticInner[]"), + Arguments.of(ReflectionTypeReference.of(Inner.class), + "org.springframework.aot.hint.ReflectionTypeReferenceTests$Inner"), + Arguments.of(ReflectionTypeReference.of(Inner[].class), + "org.springframework.aot.hint.ReflectionTypeReferenceTests$Inner[]") ); }