Rework AnnotatedElementAdapter to avoid cloning the underlying Annotation array if it is empty when getAnnotations() is called.

Additionally, make the class static and add a factory method that returns a singleton instance for null or an empty Annotation arrays.

Comment From: sbrannen

This has been merged into main in 7fa2a289708a4d7d0c8e63433db6f6205ade4229 and revised in 5345a139186f44cbb73f841a1124efe652eea667.

Thanks

Comment From: jhoeller

Backported to 6.1.6, 6.0.19, 5.3.34 as well now since it is a straightforward internal optimization in a hot code path.

Comment From: sbrannen

  • see also #32476