diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java index 5721859d25f..c22242c817e 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java @@ -34,8 +34,8 @@ public final class Version { private static final Logger logger = LoggerFactory.getLogger(Version.class); - // Dubbo RPC protocol version - public static final String DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.2"; + // Dubbo RPC protocol version, for compatibility, it must not be between 2.0.10 ~ 2.6.2 + public static final String DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.1"; // Dubbo implementation version, usually is jar version. private static final String VERSION = getVersion(Version.class, ""); @@ -43,7 +43,7 @@ public final class Version { * For protocol compatibility purpose. * Because {@link #isSupportResponseAttatchment} is checked for every call, int compare expect to has higher performance than string. */ - private static final int LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT = 202; // 2.0.2 + private static final int LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT = 20001; // 2.0.1 private static final Map VERSION2INT = new HashMap(); static { @@ -66,7 +66,13 @@ public static boolean isSupportResponseAttatchment(String version) { if (version == null || version.length() == 0) { return false; } - return getIntVersion(version) >= LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT; + // 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 + int iVersion = getIntVersion(version); + if (iVersion >= 20010 && iVersion <= 20602) { + return false; + } + + return iVersion >= LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT; } public static int getIntVersion(String version) { @@ -82,12 +88,31 @@ private static int parseInt(String version) { int v = 0; String[] vArr = version.split("\\."); int len = vArr.length; - for (int i = 1; i <= len; i++) { - v += Integer.parseInt(vArr[len - i]) * Math.pow(10, i - 1); + for (int i = 0; i < len; i++) { + v += Integer.parseInt(getDigital(vArr[i])) * Math.pow(10, (len - i - 1) * 2); } return v; } + private static String getDigital(String v) { + int index = 0; + for (int i = 0; i < v.length(); i++) { + char c = v.charAt(i); + if (Character.isDigit(c)) { + if (i == v.length() - 1) { + index = i + 1; + } else { + index = i; + } + continue; + } else { + index = i; + break; + } + } + return v.substring(0, index); + } + private static boolean hasResource(String path) { try { return Version.class.getClassLoader().getResource(path) != null;