Skip to content

AnnotatedTypeMetadata no longer retains source declaration order on Java 24+ #36598

@sbrannen

Description

@sbrannen

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions