You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by hu...@apache.org on 2019/07/16 08:57:15 UTC
[dubbo] branch master updated: Make code strong,
version check compatibility. Fix
https://github.com/apache/dubbo/pull/4488 (#4490)
This is an automated email from the ASF dual-hosted git repository.
huxing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 363cd0c Make code strong, version check compatibility. Fix https://github.com/apache/dubbo/pull/4488 (#4490)
363cd0c is described below
commit 363cd0c36bac074db1e2a00c368b57e5d2f22891
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Jul 16 16:57:03 2019 +0800
Make code strong, version check compatibility. Fix https://github.com/apache/dubbo/pull/4488 (#4490)
---
.../src/main/java/org/apache/dubbo/common/Version.java | 17 +++++++++++++----
.../org/apache/dubbo/common/version/VersionTest.java | 6 ++++++
2 files changed, 19 insertions(+), 4 deletions(-)
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 b67d32c..8494fed 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
@@ -42,6 +42,8 @@ public final class Version {
// 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.2";
+ // version 1.0.0 represents Dubbo rpc protocol before v2.6.2
+ public static final int LEGACY_DUBBO_PROTOCOL_VERSION = 10000; // 1.0.0
// Dubbo implementation version, usually is jar version.
private static final String VERSION = getVersion(Version.class, "");
@@ -115,10 +117,17 @@ public final class Version {
public static int getIntVersion(String version) {
Integer v = VERSION2INT.get(version);
if (v == null) {
- v = parseInt(version);
- // e.g., version number 2.6.3 will convert to 2060300
- if (version.split("\\.").length == 3) {
- v = v * 100;
+ try {
+ v = parseInt(version);
+ // e.g., version number 2.6.3 will convert to 2060300
+ if (version.split("\\.").length == 3) {
+ v = v * 100;
+ }
+ } catch (Exception e) {
+ logger.warn("Please make sure your version value has the right format: " +
+ "\n 1. only contains digital number: 2.0.0; \n 2. with string suffix: 2.6.7-stable. " +
+ "\nIf you are using Dubbo before v2.6.2, the version value is the same with the jar version.");
+ v = LEGACY_DUBBO_PROTOCOL_VERSION;
}
VERSION2INT.put(version, v);
}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java
index 419e5d8..19eea4d 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java
@@ -34,6 +34,12 @@ public class VersionTest {
Assertions.assertTrue(Version.isSupportResponseAttachment("2.0.2"));
Assertions.assertTrue(Version.isSupportResponseAttachment("2.0.3"));
Assertions.assertFalse(Version.isSupportResponseAttachment("2.0.0"));
+ Assertions.assertFalse(Version.isSupportResponseAttachment("1.0.0"));
+ Assertions.assertTrue(Version.isSupportResponseAttachment("2.6.6-stable"));
+
+ Assertions.assertFalse(Version.isSupportResponseAttachment("2.0.contains"));
+ Assertions.assertFalse(Version.isSupportResponseAttachment("version.string"));
+ Assertions.assertFalse(Version.isSupportResponseAttachment("prefix2.0"));
}
@Test