Skip to content

Context cache is broken if two Bean Override fields declare annotations in different order #33633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sbrannen opened this issue Oct 2, 2024 · 0 comments
Assignees
Labels
in: test Issues in the test module type: bug A general bug
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Oct 2, 2024

Given the following example test classes, one would expect that Test1 and Test2 would share the same ApplicationContext.

However, due to the current implementation of equals() in OverrideMetadata, the annotations on the logically equivalent messageService fields are compared using Arrays.equals() which takes the declaration order into account. Whereas, the declaration order of the annotations is not relevant for this particular "equality" check.

@SpringJUnitConfig(Config.class)
class Test1 {

   @TestBean
   @Qualifier("system")
   MessageService messageService;

   // rest of test class
}
@SpringJUnitConfig(Config.class)
class Test2 {

   @Qualifier("system")
   @TestBean
   MessageService messageService;

   // rest of test class
}

In light of the above, we should compare the annotations declared on a Bean Override field using Set semantics.

FYI: Spring Boot's testing support took the same approach in its QualifierDefinition.

@sbrannen sbrannen added in: test Issues in the test module type: bug A general bug labels Oct 2, 2024
@sbrannen sbrannen added this to the 6.2.0-RC2 milestone Oct 2, 2024
@sbrannen sbrannen self-assigned this Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant