Skip to content

Allow a single element to override an array attribute in a meta-annotation [SPR-13972] #18544

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

Closed
4 tasks done
spring-projects-issues opened this issue Feb 22, 2016 · 5 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 22, 2016

Juergen Hoeller opened SPR-13972 and commented

Overview

In 4.2, aliased annotation attribute types must match exactly. However, it is rather common in Java for single element values to be specified for an array attribute: Reflecting this in custom annotation design, it would be nice for a custom annotation to be able to declare a single element only, aliasing a meta-annotation attribute which was originally declared as an array, e.g. in a custom @PropertySource variant with a single String value.

Deliverables

  1. Allow for a single element overriding an array attribute in a meta-annotation by convention.
    • See findMergedAnnotationAttributesWithSingleElementOverridingAnArrayViaConvention() in AnnotatedElementUtilsTests.
  2. Allow for a single element overriding an array attribute in a meta-annotation using @AliasFor.
    • See findMergedAnnotationAttributesWithSingleElementOverridingAnArrayViaAliasFor() in AnnotatedElementUtilsTests.
  3. Ensure that the aforementioned overrides are supported in AnnotationAttributes (which is assumed to already be the case but should be verified).
    • See singleElementToSingleElementArrayConversionSupport() in AnnotationAttributesTests.
  4. Ensure that the aforementioned overrides are supported in synthesized annotations.
    • See various getMergedAnnotation*WithSingleElementOverridingAnArrayVia*() and findMergedAnnotationWithSingleElementOverridingAnArrayVia*() methods in AnnotatedElementUtilsTests.

Affects: 4.2.4

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Juergen Hoeller, the committed change only works for reading such attributes via the AnnotationAttributes API -- actually, that (little known) feature has been in place for several years in AnnotationAttributes - however, this does not work for synthesized annotations.

When attempting to use this feature with synthesized annotations (e.g., a merged @RequestMapping), we see errors similar to the following (thrown from MapAnnotationAttributeExtractor.enrichAndValidateAttributes()):

java.lang.IllegalArgumentException: Attributes map {name=, value=/get, path=/get, params=[Ljava.lang.String;@6325a3ee, headers=[Ljava.lang.String;@1d16f93d, consumes=[Ljava.lang.String;@67b92f0a, produces=[Ljava.lang.String;@2b9627bc, method=[Lorg.springframework.web.bind.annotation.RequestMethod;@65e2dbf3} returned a value of type [java.lang.String] for attribute 'value', but a value of type [[Ljava.lang.String;] is required as defined by annotation type [org.springframework.web.bind.annotation.RequestMapping].

I have been planning on adding such support for synthesized annotations. So, do you want me to reopen/repurpose this issue or create a separate one to address this?

Cheers,

Sam

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Let's reopen this one for the wider purpose in the 4.3 timeframe. I only really sneaked it in since I ran into it when coding a recent unit test :-)

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

OK. I'm reopening this issue and assigning it to me in order to address annotations synthesized from maps.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Current work can be viewed in the following branch:

https://github.com/sbrannen/spring-framework/commits/SPR-13972

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Pushed to master in the following commit:

eb654dc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants