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

AnnotationUtils fails to synthesize nested maps into annotations [SPR-13338] #17923

Closed
1 task done
spring-projects-issues opened this issue Aug 10, 2015 · 1 comment
Closed
1 task done
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-13338 and commented

Status Quo

The Javadoc for the synthesizeAnnotation(Map<String, Object>, Class<A>, AnnotatedElement) method in AnnotationUtils states the following:

Synthesize an annotation from the supplied map of annotation attributes by wrapping the map in a dynamic proxy that implements an annotation of the specified annotationType and transparently enforces attribute alias semantics for annotation attributes that are annotated with @AliasFor.

The supplied map must contain a key-value pair for every attribute defined in the supplied annotationType that is not aliased or does not have a default value.

Note that AnnotationAttributes is a specialized type of Map that is an ideal candidate for this method's attributes argument.

Note that the Javadoc says that key-value pairs must be present, but it does not say that there are any limitations on the types of values that are permitted. The Javadoc also explicitly states that AnnotationAttributes is an ideal candidate for synthesis.

However, if the map of annotation attributes was created manually (with nested maps instead of annotations) or with one of the getAnnotationAttributes(..) variants with nestedAnnotationsAsMap set to true, an exception is thrown during synthesis since a map or array or maps is not compatible with an annotation or array of annotations, respectively.

Deliverables

  1. Ensure that a nested map or nested array of maps is properly synthesized into an annotation or array of annotations when synthesizing the enclosing map into an annotation.

Affects: 4.2 GA

Referenced from: commits f17173f

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Fixed in GitHub commit f17173f:

Synthesize nested maps into annotations

Prior to this commit, attempting to synthesize an annotation from a map of annotation attributes that contained nested maps instead of nested annotations would result in an exception.

This commit addresses this issue by properly synthesizing nested maps and nested arrays of maps into nested annotations and nested arrays of annotations, respectively.

@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.2.1 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