Fix StringIndexOutOfBoundsException with Class-File metadata
Prior to this commit, the new `ClassFileAnnotationMetadata` would fail when reading `Class<T>` annotation attributes when values are primitive types. This commit uses `java.lang.constant.ClassDesc` to better parse type descriptors from the bytecode. Fixes gh-24882
This commit is contained in:
@@ -308,6 +308,14 @@ public abstract class AbstractAnnotationMetadataTests {
|
||||
assertThat(attributes.get("mv").get(0)).isEqualTo(values);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAnnotationAttributeVoidType() {
|
||||
MultiValueMap<String, Object> attributes =
|
||||
get(WithVoidType.class).getAllAnnotationAttributes(ComplexAttributes.class.getName());
|
||||
assertThat(attributes).containsOnlyKeys("names", "count", "type", "subAnnotation");
|
||||
assertThat(attributes.get("type")).containsAnyOf(Void.class, void.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRepeatableReturnsAttributes() {
|
||||
MultiValueMap<String, Object> attributes =
|
||||
@@ -445,12 +453,19 @@ public abstract class AbstractAnnotationMetadataTests {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ComplexAttributes(names = {"first", "second"}, count = TestEnum.ONE,
|
||||
type = TestEnum.class, subAnnotation = @SubAnnotation(name="spring"))
|
||||
@Metadata(mv = {42})
|
||||
public static class WithComplexAttributeTypes {
|
||||
}
|
||||
|
||||
@ComplexAttributes(names = "void", count = TestEnum.ONE, type = void.class,
|
||||
subAnnotation = @SubAnnotation(name="spring"))
|
||||
public static class WithVoidType {
|
||||
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ComplexAttributes {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user