Overview
In commit c5b9c3d, I modified the getAnnotationsReturnsDirectAnnotations() method in AbstractMethodMetadataTests to use the containsExactly() assertion instead of containsExactlyInAnyOrder(), because AnnotatedTypeMetadata.getAnnotations() must return annotations in source declaration order.
For example, if multiple @PropertySource annotations are present or meta-present on a class, the order in which they are declared in the source code dictates the order in which the property sources are added to the Environment.
However, AbstractMethodMetadataTests began to fail sporadically on Java 24 or higher, and getAnnotationsReturnsDirectAnnotations() was subsequently changed to use containsExactlyInAnyOrder() again in order not to fail the build.
After further investigation, I determined that ClassFileAnnotationDelegate currently creates MergedAnnotations from a HashSet instead of a LinkedHashSet or List, which results in a non-deterministic iteration order of the annotations and loses the original source declaration order.
For parity with our reflection-based and ASM-based annotation metadata processing, we need to fix the issue in ClassFileAnnotationDelegate.
In addition, we should update all related tests to use the containsExactly() assertion instead of containsExactlyInAnyOrder() in order to ensure we consistently adhere to this requirement.
Related Issues
Overview
In commit c5b9c3d, I modified the
getAnnotationsReturnsDirectAnnotations()method inAbstractMethodMetadataTeststo use thecontainsExactly()assertion instead ofcontainsExactlyInAnyOrder(), becauseAnnotatedTypeMetadata.getAnnotations()must return annotations in source declaration order.For example, if multiple
@PropertySourceannotations are present or meta-present on a class, the order in which they are declared in the source code dictates the order in which the property sources are added to theEnvironment.However,
AbstractMethodMetadataTestsbegan to fail sporadically on Java 24 or higher, andgetAnnotationsReturnsDirectAnnotations()was subsequently changed to usecontainsExactlyInAnyOrder()again in order not to fail the build.After further investigation, I determined that
ClassFileAnnotationDelegatecurrently createsMergedAnnotationsfrom aHashSetinstead of aLinkedHashSetorList, which results in a non-deterministic iteration order of the annotations and loses the original source declaration order.For parity with our reflection-based and ASM-based annotation metadata processing, we need to fix the issue in
ClassFileAnnotationDelegate.In addition, we should update all related tests to use the
containsExactly()assertion instead ofcontainsExactlyInAnyOrder()in order to ensure we consistently adhere to this requirement.Related Issues