Description
This issue collects the various tasks and ideas related to overhauling our annotation handling code. This issue will be edited as additional ideas arise.
Prerequisites
These tasks will generally help with implementing the new API:
API Improvements
These are the core API related tasks:
- Create replacement API for handling merged annotations [SPR-17161] #21697
- Migrate existing AnnotationUtils and AnnotatedElementUtils to use new MergedAnnotations API #22562
Minor Performance Improvements
Initially the new API will cause an additional overhead. We can reclaim a few milliseconds in a few other areas of the framework to help:
- Use less memory and try to skip more classes when processing @Configuration classes #22563
- Skip more classes when processing beans in EventListenerMethodProcessor #22564
- Increase StringBuilder initial size used in the ASM Frame class #22565
- Make ConcurrentReferenceHashMap a bit more JIT friendly #22566
- Use shared zero length arrays in ReflectionUtils #22567
- Optimize StringUtils.cleanPath #22568
- Use shared InjectionMetadata instance for beans skipped by AutowiredAnnotationBeanPostProcessor #22570
- Cache BridgeMethodResolver results #22579
- Add public getDeclaredMethods method to ReflectionUtils #22580
- Minimise need to iterate over a class's methods #22420
Migrate classes to use the new API directly
A few classes would benefit from using the new annotations API directly. Especially relevant are any areas of the code that make several utils calls, when they could hold onto a MergedAnnotations
instance:
- Migrate AnnotationAwareOrderComparator to MergedAnnotations #22581
- Migrate AutowiredAnnotationBeanPostProcessor to MergedAnnotations #22582
- Migrate DefaultListableBeanFactory to MergedAnnotations #22584
- Migrate AnnotationJmxAttributeSource to MergedAnnotations #22657
Make use of annotation index
Indexing annotations to do less work may help performance.
Introduce MergedAnnotation finder methods #22569Programmatic annotation presence registry (allowing for index integration) #22578Investigate logic based annotation indexes (e.g. Jackson classes won't have Spring annotations)
Overhaul metadata code
The existing ASM based meta-data reader code currently recursively processes annotations. The new MergedAnnotations
API may be suitable to expose directly. It might also be possible to not use ASM when reading meta-annotations and instead just use standard reflection.
- Refactor ASM annotation reading code
- Expose MergedAnnotations from meta-data classes #22884
Accidentally introduced regressions
- Regression in merged annotation resolution #22654
- AnnotationsScanner throws NPE due to because AnnotatedElement proxy is not cloning arrays #22655
- AnnotationUtils.isAnnotationMetaPresent(…) no longer considers javax.annotation.Nonnull #22685
- AnnotatedElementUtils.getAllAnnotationAttributes(…, "javax.annotation.Nonnull") returns null #22696