Skip to content

Commit

Permalink
fix issue-8387 on master (#8624)
Browse files Browse the repository at this point in the history
  • Loading branch information
changfubai committed Sep 3, 2021
1 parent 04f4fee commit 7d95364
Showing 1 changed file with 2 additions and 24 deletions.
Expand Up @@ -17,7 +17,6 @@
package org.apache.dubbo.common.extension.support;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.extension.SPI;

import java.util.Comparator;

Expand Down Expand Up @@ -46,36 +45,15 @@ public int compare(Object o1, Object o2) {
Class clazz1 = (Class) o1;
Class clazz2 = (Class) o2;

Class<?> inf = findSpi(clazz1);

OrderInfo a1 = parseOrder(clazz1);
OrderInfo a2 = parseOrder(clazz2);

int n1 = a1 == null ? 0 : a1.order;
int n2 = a2 == null ? 0 : a2.order;
int n1 = a1.order;
int n2 = a2.order;
// never return 0 even if n1 equals n2, otherwise, o1 and o2 will override each other in collection like HashSet
return n1 > n2 ? 1 : -1;
}

private Class<?> findSpi(Class clazz) {
if (clazz.getInterfaces().length == 0) {
return null;
}

for (Class<?> intf : clazz.getInterfaces()) {
if (intf.isAnnotationPresent(SPI.class)) {
return intf;
} else {
Class result = findSpi(intf);
if (result != null) {
return result;
}
}
}

return null;
}

private OrderInfo parseOrder(Class<?> clazz) {
OrderInfo info = new OrderInfo();
if (clazz.isAnnotationPresent(Activate.class)) {
Expand Down

0 comments on commit 7d95364

Please sign in to comment.