3434public final class Version {
3535 private static final Logger logger = LoggerFactory .getLogger (Version .class );
3636
37- // Dubbo RPC protocol version
38- public static final String DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.2 " ;
37+ // Dubbo RPC protocol version, for compatibility, it must not be between 2.0.10 ~ 2.6.2
38+ public static final String DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.1 " ;
3939 // Dubbo implementation version, usually is jar version.
4040 private static final String VERSION = getVersion (Version .class , "" );
4141
4242 /**
4343 * For protocol compatibility purpose.
4444 * Because {@link #isSupportResponseAttatchment} is checked for every call, int compare expect to has higher performance than string.
4545 */
46- private static final int LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT = 202 ; // 2.0.2
46+ private static final int LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT = 20001 ; // 2.0.1
4747 private static final Map <String , Integer > VERSION2INT = new HashMap <String , Integer >();
4848
4949 static {
@@ -66,7 +66,13 @@ public static boolean isSupportResponseAttatchment(String version) {
6666 if (version == null || version .length () == 0 ) {
6767 return false ;
6868 }
69- return getIntVersion (version ) >= LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT ;
69+ // for previous dubbo version(2.0.10/020010~2.6.2/020602), this version is the jar's version, so they need to be ignore
70+ int iVersion = getIntVersion (version );
71+ if (iVersion >= 20010 && iVersion <= 20602 ) {
72+ return false ;
73+ }
74+
75+ return iVersion >= LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT ;
7076 }
7177
7278 public static int getIntVersion (String version ) {
@@ -82,12 +88,31 @@ private static int parseInt(String version) {
8288 int v = 0 ;
8389 String [] vArr = version .split ("\\ ." );
8490 int len = vArr .length ;
85- for (int i = 1 ; i <= len ; i ++) {
86- v += Integer .parseInt (vArr [len - i ]) * Math .pow (10 , i - 1 );
91+ for (int i = 0 ; i < len ; i ++) {
92+ v += Integer .parseInt (getDigital ( vArr [i ])) * Math .pow (10 , ( len - i - 1 ) * 2 );
8793 }
8894 return v ;
8995 }
9096
97+ private static String getDigital (String v ) {
98+ int index = 0 ;
99+ for (int i = 0 ; i < v .length (); i ++) {
100+ char c = v .charAt (i );
101+ if (Character .isDigit (c )) {
102+ if (i == v .length () - 1 ) {
103+ index = i + 1 ;
104+ } else {
105+ index = i ;
106+ }
107+ continue ;
108+ } else {
109+ index = i ;
110+ break ;
111+ }
112+ }
113+ return v .substring (0 , index );
114+ }
115+
91116 private static boolean hasResource (String path ) {
92117 try {
93118 return Version .class .getClassLoader ().getResource (path ) != null ;
0 commit comments