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 61681a4a79..3a6f44f3ea 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 @@ -369,10 +369,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); } } @@ -385,26 +385,6 @@ public class AnnotationAttributes extends LinkedHashMap { } } - /** - * Store the supplied {@code value} in this map under the specified - * {@code key}, unless a value is already stored under the key. - * @param key the key under which to store the value - * @param value the value to store - * @return the current value stored in this map, or {@code null} if no - * value was previously stored in this map - * @see #get - * @see #put - * @since 4.2 - */ - @Override - public Object putIfAbsent(String key, Object value) { - Object obj = get(key); - if (obj == null) { - obj = put(key, value); - } - return obj; - } - @Override public String toString() { Iterator> entries = entrySet().iterator(); 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 54d286cdcd..fd23536d28 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 @@ -72,13 +72,21 @@ public class AnnotationAttributesTests { } @Test - public void unresolvableClass() throws Exception { + public void unresolvableClassWithClassNotFoundException() throws Exception { attributes.put("unresolvableClass", new ClassNotFoundException("myclass")); assertThatIllegalArgumentException().isThrownBy(() -> attributes.getClass("unresolvableClass")) .withMessageContaining("myclass"); } + @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);