diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java index f1bcf9fd3f..39ca02b7bc 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java @@ -353,10 +353,10 @@ public class AnnotationAttributes extends LinkedHashMap { } private void assertNotException(String attributeName, Object attributeValue) { - if (attributeValue instanceof Exception) { + if (attributeValue instanceof Throwable) { throw new IllegalArgumentException(String.format( "Attribute '%s' for annotation [%s] was not resolvable due to exception [%s]", - attributeName, this.displayName, attributeValue), (Exception) attributeValue); + attributeName, this.displayName, attributeValue), (Throwable) attributeValue); } } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java index cfa212c81e..8b112e924b 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java @@ -77,13 +77,21 @@ public class AnnotationAttributesTests { } @Test - public void unresolvableClass() throws Exception { + public void unresolvableClassWithClassNotFoundException() throws Exception { attributes.put("unresolvableClass", new ClassNotFoundException("myclass")); exception.expect(IllegalArgumentException.class); exception.expectMessage(containsString("myclass")); attributes.getClass("unresolvableClass"); } + @Test + public void unresolvableClassWithLinkageError() throws Exception { + attributes.put("unresolvableClass", new LinkageError("myclass")); + exception.expect(IllegalArgumentException.class); + exception.expectMessage(containsString("myclass")); + attributes.getClass("unresolvableClass"); + } + @Test public void singleElementToSingleElementArrayConversionSupport() throws Exception { Filter filter = FilteredClass.class.getAnnotation(Filter.class);