Skip to content

Commit 2aaa66f

Browse files
committed
Allow for ordering of mixed AspectJ before/after advices
Issue: SPR-9438
1 parent e3c83bb commit 2aaa66f

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.aop.aspectj.autoproxy;
1818

19+
import java.util.ArrayList;
1920
import java.util.Comparator;
20-
import java.util.LinkedList;
2121
import java.util.List;
2222

2323
import org.aopalliance.aop.Advice;
@@ -67,29 +67,24 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
6767
@Override
6868
@SuppressWarnings("unchecked")
6969
protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
70-
// build list for sorting
7170
List<PartiallyComparableAdvisorHolder> partiallyComparableAdvisors =
72-
new LinkedList<PartiallyComparableAdvisorHolder>();
71+
new ArrayList<PartiallyComparableAdvisorHolder>(advisors.size());
7372
for (Advisor element : advisors) {
7473
partiallyComparableAdvisors.add(
7574
new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR));
7675
}
77-
78-
// sort it
7976
List<PartiallyComparableAdvisorHolder> sorted =
8077
PartialOrder.sort(partiallyComparableAdvisors);
81-
if (sorted == null) {
82-
// TODO: work harder to give a better error message here.
83-
throw new IllegalArgumentException("Advice precedence circularity error");
78+
if (sorted != null) {
79+
List<Advisor> result = new ArrayList<Advisor>(advisors.size());
80+
for (PartiallyComparableAdvisorHolder pcAdvisor : sorted) {
81+
result.add(pcAdvisor.getAdvisor());
82+
}
83+
return result;
8484
}
85-
86-
// extract results again
87-
List<Advisor> result = new LinkedList<Advisor>();
88-
for (PartiallyComparableAdvisorHolder pcAdvisor : sorted) {
89-
result.add(pcAdvisor.getAdvisor());
85+
else {
86+
return super.sortAdvisors(advisors);
9087
}
91-
92-
return result;
9388
}
9489

9590
/**

0 commit comments

Comments
 (0)