Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transitive implicit aliases do not always work with @AliasFor in merged annotations [SPR-14069] #18641

Closed
1 task
spring-projects-issues opened this issue Mar 18, 2016 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Sam Brannen opened SPR-14069 and commented

Status Quo

For the most post, transitive implicit aliases for annotation attribute overrides configured via @AliasFor work. However, I have detected a corner case that fails.

Failing Example

Given the following three annotations, if an attempt is made to look up a merged @ContextConfig annotation via AnnotatedElementUtils (e.g., using getMergedAnnotation() or findMergedAnnotation()) on an element annotated with @TransitiveImplicitAliasesContextConfig then the look up will fail with an AnnotationConfigurationException stating something similar to the following:

attribute 'value' and its alias 'locations' are declared with values of [{}] and [{test.groovy}], but only one is permitted.

If the value attribute in ImplicitAliasesContextConfig declares attribute = "locations" via @AliasFor, the code then works as expected. Thus, there is obviously a bug in the lookup mechanism for names of overridden attributes in conjunction with transitive implicit aliases.

@Retention(RetentionPolicy.RUNTIME)
@interface ContextConfig {

	@AliasFor(attribute = "locations")
	String[] value() default {};

	@AliasFor(attribute = "value")
	String[] locations() default {};

	Class<?>[] classes() default {};
}
@ContextConfig
@Retention(RetentionPolicy.RUNTIME)
@interface ImplicitAliasesContextConfig {

	@AliasFor(annotation = ContextConfig.class, attribute = "locations")
	String[] groovyScripts() default {};

	@AliasFor(annotation = ContextConfig.class, attribute = "locations")
	String[] xmlFiles() default {};

	// intentionally omitted: attribute = "locations"
	@AliasFor(annotation = ContextConfig.class)
	String[] locations() default {};

	// intentionally omitted: attribute = "locations"
	@AliasFor(annotation = ContextConfig.class)
	String[] value() default {};
}
@ImplicitAliasesContextConfig
@Retention(RetentionPolicy.RUNTIME)
@interface TransitiveImplicitAliasesContextConfig {

	@AliasFor(annotation = ImplicitAliasesContextConfig.class, attribute = "xmlFiles")
	String[] xml() default {};

	@AliasFor(annotation = ImplicitAliasesContextConfig.class, attribute = "groovyScripts")
	String[] groovy() default {};
}

Deliverables

  1. Determine why the aforementioned example fails and fix the bug.
    • See TODO in AnnotatedElementUtilsTests.

Affects: 4.2.2

Referenced from: commits d22480b, 2153d88

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Fixed as described in GitHub commit d22480b:

Ensure all aliased attributes in target annotation are overridden

Prior to this commit, it was possible that implicit aliases and
transitive implicit aliases (configured via @AliasFor) might not be
honored in certain circumstances, in particular if implicit aliases
were declared to override different attributes within an alias pair in
the target meta-annotation.

This commit addresses this issue by ensuring that all aliased
attributes in the target meta-annotation are overridden during the
merge process in AnnotatedElementUtils.

In addition, concrete default values for attributes in a
meta-annotation declaration can now be effectively shadowed by
transitive implicit aliases in composed annotations.

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.3 RC1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants