Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make code strong, version check compatibility. #4488

Merged
merged 8 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion dubbo-common/src/main/java/com/alibaba/dubbo/common/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");

Expand Down Expand Up @@ -78,7 +80,14 @@ public static boolean isSupportResponseAttatchment(String 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


import com.alibaba.dubbo.common.Version;

import org.junit.Assert;
import org.junit.Test;

Expand All @@ -34,5 +33,11 @@ public void testSupportResponseAttatchment() {
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"));
}
}