You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by me...@apache.org on 2019/07/08 09:16:37 UTC
[dubbo] branch 2.6.7-release updated: Make code strong,
version check compatibility. (#4488)
This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch 2.6.7-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.6.7-release by this push:
new 4054050 Make code strong, version check compatibility. (#4488)
4054050 is described below
commit 40540507f24396ad48ea68a878a630803d8a6407
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Jul 8 17:16:32 2019 +0800
Make code strong, version check compatibility. (#4488)
* 2.6.x test
* version check compatibility
* add comment
* revert demo changes
* update ut
* add error log
* change log level to warn
---
.../src/main/java/com/alibaba/dubbo/common/Version.java | 11 ++++++++++-
.../java/com/alibaba/dubbo/common/version/VersionTest.java | 7 ++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/Version.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/Version.java
index a096835..d93edc2 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/Version.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/Version.java
@@ -36,6 +36,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, "");
@@ -78,7 +80,14 @@ public final class Version {
public static int getIntVersion(String version) {
Integer v = VERSION2INT.get(version);
if (v == null) {
- v = parseInt(version);
+ try {
+ v = parseInt(version);
+ } 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);
}
return v;
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/version/VersionTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/version/VersionTest.java
index 139216b..088e980 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/version/VersionTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/version/VersionTest.java
@@ -18,7 +18,6 @@ package com.alibaba.dubbo.common.version;
import com.alibaba.dubbo.common.Version;
-
import org.junit.Assert;
import org.junit.Test;
@@ -34,5 +33,11 @@ public class VersionTest {
Assert.assertTrue(Version.isSupportResponseAttatchment("2.0.2"));
Assert.assertTrue(Version.isSupportResponseAttatchment("2.0.3"));
Assert.assertFalse(Version.isSupportResponseAttatchment("2.0.0"));
+ Assert.assertFalse(Version.isSupportResponseAttatchment("1.0.0"));
+ Assert.assertTrue(Version.isSupportResponseAttatchment("2.6.6-stable"));
+
+ Assert.assertFalse(Version.isSupportResponseAttatchment("2.0.contains"));
+ Assert.assertFalse(Version.isSupportResponseAttatchment("version.string"));
+ Assert.assertFalse(Version.isSupportResponseAttatchment("prefix2.0"));
}
}