org.springframework.aop.support.AopUtils
public static List<Advisor> findAdvisorsThatCanApply(List<Advisor> candidateAdvisors, Class<?> clazz) {
if (candidateAdvisors.isEmpty()) {
return candidateAdvisors;
}
List<Advisor> eligibleAdvisors = new ArrayList<>();
for (Advisor candidate : candidateAdvisors) {
if (candidate instanceof IntroductionAdvisor && canApply(candidate, clazz)) {
eligibleAdvisors.add(candidate);
}
}
boolean hasIntroductions = !eligibleAdvisors.isEmpty();
for (Advisor candidate : candidateAdvisors) {
if (candidate instanceof IntroductionAdvisor) {
// already processed
continue;
}
if (canApply(candidate, clazz, hasIntroductions)) {
eligibleAdvisors.add(candidate);
}
}
return eligibleAdvisors;
}
public static List<Advisor> myFindAdvisorsThatCanApply(List<Advisor> candidateAdvisors, Class<?> clazz) {
if (candidateAdvisors.isEmpty()) {
return candidateAdvisors;
}
List<Advisor> eligibleAdvisors = new ArrayList<>();
boolean hasIntroductions = false;
for (Advisor candidate : candidateAdvisors) {
if (candidate instanceof IntroductionAdvisor) {
if (canApply(candidate, clazz)) {
eligibleAdvisors.add(candidate);
if (!hasIntroductions) {
hasIntroductions = true;
}
}
continue;
}
if (canApply(candidate, clazz, hasIntroductions)) {
eligibleAdvisors.add(candidate);
}
}
return eligibleAdvisors;
}
Comment From: bclozel
@angieCat I believe we're looping twice over the candidate advisors on purpose. Once to look for IntroductionAdvisor instances (and add them to the list of they can apply), and then another time to register the remaining ones knowing if we've found introductions.
With your code sample, it seems that we can register Advisor instances with hasIntroductions as false, because there might be IntroductionAdvisor instances later in the list.
Is my understanding correct? Did you run our test suite with that change? If the test suite didn't fail, we're probably missing a test case.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.