Skip to content

Commit

Permalink
Make code strong, version check compatibility. Fix #4488 (#4490)
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj authored and ralf0131 committed Jul 16, 2019
1 parent aab3a05 commit 363cd0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 13 additions & 4 deletions dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");

Expand Down Expand Up @@ -115,10 +117,17 @@ public static boolean isSupportResponseAttachment(String 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public void testSupportResponseAttachment() {
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
Expand Down

0 comments on commit 363cd0c

Please sign in to comment.