You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AnnotationReadingVisitorUtils.getMergedAnnotationAttributes() overrides values it should not [SPR-11649] #16272
I'd expect this call to return the attributes/values defined in the @VsoObject annotation, and it worked fine in Spring versions up to 4.0.2. However, due to the changes introduced in conjunction with #16198 in Spring 4.0.3 the returned values are those coming from the @VsoFinder annotation.
A quick look at AnnotationReadingVisitorUtils.getMergedAnnotationAttributes() confirms that indeed the values of attributes with the same name are overridden with the values from annotations of any type, not only from the requested annotation type.
Deliverables
Ensure that AnnotationReadingVisitorUtils.getMergedAnnotationAttributes() only overrides attributes in the target annotation with attributes from annotations that are annotated with the target annotation.
A few notes on the status quo as well as my changes:
AnnotationMetadataReadingVisitor currently tracks the meta-annotations present on the underlying class in a LinkedMultiValueMap.
This data structure unfortunately does not accurately represent the tree nature of the annotation hierarchy, but we need this tree-like structural information to determine which annotations are allowed to override the target annotation.
To overcome this, we have two options:
Overhaul AnnotationMetadataReadingVisitor and associated classes so that the actual tree nature of the metadata is preserved. This would allow us to query the tree structure to infer which annotations are meta-annotated with other annotations.
Look up the meta-annotation metadata for each annotation as we encounter it in the AnnotationReadingVisitorUtils.getMergedAnnotationAttributes() algorithm.
In my branch I implemented the latter option since it required fewer changes to the code base; however, I am not totally happy with it for the following reasons:
It uses ASM to revisit meta-annotations that have already been visited in the original creation of the metadata for the underlying class, but this revisiting is necessary since the tree structure is not preserved. See AnnotationReadingVisitorUtils.isMetaAnnotated().
isMetaAnnotated() swallows IOExceptions silently.
getMergedAnnotationAttributes always instantiates a new SimpleMetadataReaderFactory with zero caching.
Juergen Hoeller, could you please review this change before I push it to the official repository?
I've addressed the immediate problem here through passing the AnnotationMetadataReadingVisitor's metaAnnotationMap into the getMergedAnnotationAttributes algorithm, checking for a corresponding entry there before actually letting another annotation's attributes override. This makes all test cases from Sam's branch pass.
If any corner problems remain, let's deal with them for 4.0.5.
Activity
spring-projects-issues commentedon Apr 2, 2014
Sam Brannen commented
This sounds like it might in fact be a bug.
We will look into it!
Thanks,
Sam
spring-projects-issues commentedon Apr 2, 2014
Sam Brannen commented
I've just pushed a fix to a #16272 branch in my personal GitHub repository (direct link to commit).
A few notes on the status quo as well as my changes:
AnnotationMetadataReadingVisitorcurrently tracks the meta-annotations present on the underlying class in aLinkedMultiValueMap.AnnotationMetadataReadingVisitorand associated classes so that the actual tree nature of the metadata is preserved. This would allow us to query the tree structure to infer which annotations are meta-annotated with other annotations.AnnotationReadingVisitorUtils.getMergedAnnotationAttributes()algorithm.In my branch I implemented the latter option since it required fewer changes to the code base; however, I am not totally happy with it for the following reasons:
AnnotationReadingVisitorUtils.isMetaAnnotated().isMetaAnnotated()swallowsIOExceptionssilently.getMergedAnnotationAttributesalways instantiates a newSimpleMetadataReaderFactorywith zero caching.Juergen Hoeller, could you please review this change before I push it to the official repository?
Thanks!
Sam
spring-projects-issues commentedon Apr 30, 2014
Juergen Hoeller commented
I've addressed the immediate problem here through passing the AnnotationMetadataReadingVisitor's metaAnnotationMap into the getMergedAnnotationAttributes algorithm, checking for a corresponding entry there before actually letting another annotation's attributes override. This makes all test cases from Sam's branch pass.
If any corner problems remain, let's deal with them for 4.0.5.
Juergen
spring-projects-issues commentedon May 9, 2014
Sam Brannen commented
Juergen Hoeller,
That's definitely a more elegant solution. ;)
Thanks!