diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
index bf0cafc4643..eb5cdfc0a0e 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
@@ -1282,7 +1282,9 @@ public abstract class AnnotationUtils {
* Retrieve the value of the {@code value} attribute of a
* single-element Annotation, given an annotation instance.
* @param annotation the annotation instance from which to retrieve the value
- * @return the attribute value, or {@code null} if not found
+ * @return the attribute value, or {@code null} if not found unless the attribute
+ * value cannot be retrieved due to an {@link AnnotationConfigurationException}, in
+ * which case such an exception will be rethrown
* @see #getValue(Annotation, String)
*/
public static Object getValue(Annotation annotation) {
@@ -1293,9 +1295,9 @@ public abstract class AnnotationUtils {
* Retrieve the value of a named attribute, given an annotation instance.
* @param annotation the annotation instance from which to retrieve the value
* @param attributeName the name of the attribute value to retrieve
- * @return the attribute value, or {@code null} if not found unless the the attribute value
- * can not be retrieved due to {@link AnnotationConfigurationException}, in which case it
- * will be re-thrown
+ * @return the attribute value, or {@code null} if not found unless the attribute
+ * value cannot be retrieved due to an {@link AnnotationConfigurationException}, in
+ * which case such an exception will be rethrown
* @see #getValue(Annotation)
* @see #rethrowAnnotationConfigurationException(Throwable)
*/
@@ -1311,7 +1313,7 @@ public abstract class AnnotationUtils {
catch (InvocationTargetException ex) {
rethrowAnnotationConfigurationException(ex.getTargetException());
throw new IllegalStateException(
- "Could not obtain value for annotation attribute '" + attributeName + "' on " + annotation, ex);
+ "Could not obtain value for annotation attribute '" + attributeName + "' in " + annotation, ex);
}
catch (Throwable ex) {
return null;
diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java
index 02f22b02925..80693e7e42a 100644
--- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java
+++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java
@@ -1240,10 +1240,13 @@ public class AnnotationUtilsTests {
assertEquals("value: ", "", contextConfig.value());
assertEquals("location: ", "", contextConfig.location());
}
-
- @Test(expected = AnnotationConfigurationException.class)
- public void synthesizeAnnotationWithAttributeAliasesDifferentValues() throws Exception {
- getValue(synthesizeAnnotation(ContextConfigMismatch.class.getAnnotation(ContextConfig.class)));
+
+ @Test
+ public void synthesizeAnnotationWithAttributeAliasesWithDifferentValues() throws Exception {
+ ContextConfig contextConfig = synthesizeAnnotation(ContextConfigMismatch.class.getAnnotation(ContextConfig.class));
+
+ exception.expect(AnnotationConfigurationException.class);
+ getValue(contextConfig);
}
@Test