Skip to content

Dubbo route compareTo method donot work correctly #3249

@cvictory

Description

@cvictory

有如下问题:
1.java中要求 A.compareTo(B)和B.compareTo(A)得到的结果,应该是等价的。但是ScriptRoute里

` @Override
    public int compareTo(Router o) {
        if (o == null || o.getClass() != ScriptRouter.class) {
            return 1;
        }
        ScriptRouter c = (ScriptRouter) o;
        return this.priority == c.priority ? rule.compareTo(c.rule) : (this.priority > c.priority ? 1 : -1);
    }

想让ScriptRoute.compareTo(others) 等价于 others.compareTo(scriptRoute), 其实部分其他script如果自定义了自己的compareTo也会存在这个问题。

  1. 2.6和2.7兼容的问题
    2.6和2.7的顺序要怎么满足合理需求的同时,同时能满足前面的第一点要求。

先做个记录,问题待细化。

---------transplate

Have the following questions:
1.java requires that the results obtained by A.compareTo(B) and B.compareTo(A) should be equivalent. But in ScriptRoute

` @Override
     Public int compareTo(Router o) {
         If (o == null || o.getClass() != ScriptRouter.class) {
             Return 1;
         }
         ScriptRouter c = (ScriptRouter) o;
         Return this.priority == c.priority ? rule.compareTo(c.rule) : (this.priority > c.priority ? 1 : -1);
     }

let ScriptRoute.compareTo(others) to be equivalent to others.compareTo(scriptRoute). In fact, some other scripts have this problem if they customize their compareTo.

  1. 2.6 and 2.7 compatible issues
    How the order of 2.6 and 2.7 can meet the reasonable requirements, while meeting the first point requirements.

Make a record first, and the problem is to be refined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions