Polishing

This commit is contained in:
Sam Brannen 2017-04-26 18:59:43 +02:00
parent c668d9a473
commit c855182e03
2 changed files with 14 additions and 9 deletions

View File

@ -1282,7 +1282,9 @@ public abstract class AnnotationUtils {
* Retrieve the <em>value</em> of the {@code value} attribute of a * Retrieve the <em>value</em> of the {@code value} attribute of a
* single-element Annotation, given an annotation instance. * single-element Annotation, given an annotation instance.
* @param annotation the annotation instance from which to retrieve the value * @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) * @see #getValue(Annotation, String)
*/ */
public static Object getValue(Annotation annotation) { public static Object getValue(Annotation annotation) {
@ -1293,9 +1295,9 @@ public abstract class AnnotationUtils {
* Retrieve the <em>value</em> of a named attribute, given an annotation instance. * Retrieve the <em>value</em> of a named attribute, given an annotation instance.
* @param annotation the annotation instance from which to retrieve the value * @param annotation the annotation instance from which to retrieve the value
* @param attributeName the name of the attribute value to retrieve * @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 * @return the attribute value, or {@code null} if not found unless the attribute
* can not be retrieved due to {@link AnnotationConfigurationException}, in which case it * value cannot be retrieved due to an {@link AnnotationConfigurationException}, in
* will be re-thrown * which case such an exception will be rethrown
* @see #getValue(Annotation) * @see #getValue(Annotation)
* @see #rethrowAnnotationConfigurationException(Throwable) * @see #rethrowAnnotationConfigurationException(Throwable)
*/ */
@ -1311,7 +1313,7 @@ public abstract class AnnotationUtils {
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
rethrowAnnotationConfigurationException(ex.getTargetException()); rethrowAnnotationConfigurationException(ex.getTargetException());
throw new IllegalStateException( 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) { catch (Throwable ex) {
return null; return null;

View File

@ -1241,9 +1241,12 @@ public class AnnotationUtilsTests {
assertEquals("location: ", "", contextConfig.location()); assertEquals("location: ", "", contextConfig.location());
} }
@Test(expected = AnnotationConfigurationException.class) @Test
public void synthesizeAnnotationWithAttributeAliasesDifferentValues() throws Exception { public void synthesizeAnnotationWithAttributeAliasesWithDifferentValues() throws Exception {
getValue(synthesizeAnnotation(ContextConfigMismatch.class.getAnnotation(ContextConfig.class))); ContextConfig contextConfig = synthesizeAnnotation(ContextConfigMismatch.class.getAnnotation(ContextConfig.class));
exception.expect(AnnotationConfigurationException.class);
getValue(contextConfig);
} }
@Test @Test