Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions