Overview

While working on #25800, I realized that two @ActiveProfiles declarations on different test classes using the same profiles but declared in a different order would result in the creation of a duplicate yet identical ApplicationContext in the context cache in the Spring TestContext Framework. This is because ActiveProfilesUtils stores the active profiles in a LinkedHashSet to preserve registration order. The set is then converted to a String[] which is handed off to MergedContextConfiguration which also uses a LinkedHashSet to ensure uniqueness but still retains the registration order of the active profiles. When the MergedContextConfiguration is used as the context cache key to check whether an ApplicationContext already exists for the given metadata, the implementation of equals() in MergedContextConfiguration uses Arrays.equals() to compare two sets of active profiles, and that results in a cache miss for semantically identical active profile arrays { apples, oranges } and { oranges, apples }. Consequently, an identical ApplicationContext is created and stored in the context cache when that should not be the case.

Deliverables

  • [x] Ensure that active profiles are both unique and sorted within MergedContextConfiguration in order to avoid context cache misses.