mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-28 18:19:05 +00:00
Do not load concrete types in annotation metadata
This change fixes a regression introduced in the previous commit. Closes gh-35252
This commit is contained in:
+28
-1
@@ -16,15 +16,26 @@
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.type.AbstractAnnotationMetadataTests;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link SimpleAnnotationMetadata} and
|
||||
* {@link SimpleAnnotationMetadataReadingVisitor} on Java < 24,
|
||||
* and for the ClassFile API variant on Java >= 24.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class DefaultAnnotationMetadataTests extends AbstractAnnotationMetadataTests {
|
||||
|
||||
@@ -34,9 +45,25 @@ class DefaultAnnotationMetadataTests extends AbstractAnnotationMetadataTests {
|
||||
return MetadataReaderFactory.create(source.getClassLoader())
|
||||
.getMetadataReader(source.getName()).getAnnotationMetadata();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClassAttributeWhenUnknownClass() {
|
||||
var annotation = get(WithClassMissingFromClasspath.class).getAnnotations().get(ClassAttributes.class);
|
||||
assertThat(annotation.getStringArray("types")).contains("com.github.benmanes.caffeine.cache.Caffeine");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> annotation.getClassArray("types"));
|
||||
}
|
||||
|
||||
@ClassAttributes(types = {Caffeine.class})
|
||||
public static class WithClassMissingFromClasspath {
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ClassAttributes {
|
||||
Class<?>[] types();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+29
-1
@@ -16,14 +16,25 @@
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.type.AbstractAnnotationMetadataTests;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link SimpleAnnotationMetadata} and
|
||||
* {@link SimpleAnnotationMetadataReadingVisitor}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class SimpleAnnotationMetadataTests extends AbstractAnnotationMetadataTests {
|
||||
|
||||
@@ -34,9 +45,26 @@ class SimpleAnnotationMetadataTests extends AbstractAnnotationMetadataTests {
|
||||
source.getClassLoader()).getMetadataReader(
|
||||
source.getName()).getAnnotationMetadata();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClassAttributeWhenUnknownClass() {
|
||||
var annotation = get(WithClassMissingFromClasspath.class).getAnnotations().get(ClassAttributes.class);
|
||||
assertThat(annotation.getStringArray("types")).contains("com.github.benmanes.caffeine.cache.Caffeine");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> annotation.getClassArray("types"));
|
||||
}
|
||||
|
||||
@ClassAttributes(types = {Caffeine.class})
|
||||
public static class WithClassMissingFromClasspath {
|
||||
}
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ClassAttributes {
|
||||
Class<?>[] types();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user