Always pass test class to ActiveProfilesResolver
Prior to this commit, if @ActiveProfiles were used as a meta-annotation on a composed annotation, then the composed annotation's class would be passed to the ActiveProfilesResolver.resolve() method instead of the test class, which breaks the contract for ActiveProfilesResolver. This commit addresses this issue by ensuring that the actual test class is always passed to ActiveProfilesResolver.resolve(). Issue: SPR-11467
This commit is contained in:
@@ -507,6 +507,7 @@ abstract class ContextLoaderUtils {
|
||||
final Set<String> activeProfiles = new HashSet<String>();
|
||||
|
||||
while (descriptor != null) {
|
||||
Class<?> rootDeclaringClass = descriptor.getRootDeclaringClass();
|
||||
Class<?> declaringClass = descriptor.getDeclaringClass();
|
||||
|
||||
AnnotationAttributes annAttrs = descriptor.getAnnotationAttributes();
|
||||
@@ -530,12 +531,12 @@ abstract class ContextLoaderUtils {
|
||||
}
|
||||
catch (Exception e) {
|
||||
String msg = String.format("Could not instantiate ActiveProfilesResolver of "
|
||||
+ "type [%s] for test class [%s].", resolverClass.getName(), declaringClass.getName());
|
||||
+ "type [%s] for test class [%s].", resolverClass.getName(), rootDeclaringClass.getName());
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg, e);
|
||||
}
|
||||
|
||||
profiles = resolver.resolve(declaringClass);
|
||||
profiles = resolver.resolve(rootDeclaringClass);
|
||||
if (profiles == null) {
|
||||
String msg = String.format(
|
||||
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles.",
|
||||
@@ -555,7 +556,7 @@ abstract class ContextLoaderUtils {
|
||||
}
|
||||
|
||||
descriptor = annAttrs.getBoolean("inheritProfiles") ? findAnnotationDescriptor(
|
||||
descriptor.getRootDeclaringClass().getSuperclass(), annotationType) : null;
|
||||
rootDeclaringClass.getSuperclass(), annotationType) : null;
|
||||
}
|
||||
|
||||
return StringUtils.toStringArray(activeProfiles);
|
||||
|
||||
Reference in New Issue
Block a user