Improve exception for mixed explicit/implicit aliases with @AliasFor

Given the following improperly configured composed @RequestMapping
annotation:

@Retention(RetentionPolicy.RUNTIME)
@RequestMapping
@interface PostApi {

	@AliasFor("value")
	String[] path() default {};

	@AliasFor(annotation = RequestMapping.class, attribute = "path")
	String[] value() default {};
}

Prior to this commit, an attempt to process the above annotation
resulted in an exception similar to the following, which is not
especially helpful to discern the problem.

> Attribute 'value' in annotation [PostApi] must be declared as an
> @AliasFor 'path', not 'path'.

This commit improves the exception message for such scenarios,
resulting in an exception message similar to the following.

> Attribute 'value' in annotation [PostApi] must be declared as an
> @AliasFor attribute 'path' in annotation [PostApi], not attribute
> 'path' in annotation [RequestMapping].

Closes gh-24168
This commit is contained in:
Sam Brannen
2019-12-10 14:09:55 +01:00
parent 4466114cfa
commit 2bd821c909
2 changed files with 60 additions and 17 deletions

View File

@@ -182,9 +182,9 @@ final class AnnotationTypeMapping {
Method mirror = resolveAliasTarget(target, targetAliasFor, false);
if (!mirror.equals(attribute)) {
throw new AnnotationConfigurationException(String.format(
"%s must be declared as an @AliasFor '%s', not '%s'.",
"%s must be declared as an @AliasFor %s, not %s.",
StringUtils.capitalize(AttributeMethods.describe(target)),
attribute.getName(), mirror.getName()));
AttributeMethods.describe(attribute), AttributeMethods.describe(mirror)));
}
}
}