You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2018/11/23 02:39:18 UTC
[incubator-dubbo] 01/04: Add extra type match check when override
config value.
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch dev-metadata
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
commit 2d7b8c1f91be5eae057c3fd576e69d33809e6859
Author: ken.lj <ke...@gmail.com>
AuthorDate: Thu Nov 22 17:31:30 2018 +0800
Add extra type match check when override config value.
---
.../java/org/apache/dubbo/common/utils/ClassHelper.java | 15 +++++++++++++++
.../main/java/org/apache/dubbo/config/AbstractConfig.java | 2 +-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassHelper.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassHelper.java
index 2446e5f..b5aa79f 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassHelper.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassHelper.java
@@ -284,4 +284,19 @@ public class ClassHelper {
}
return value;
}
+
+ /**
+ * We only check boolean value at this moment.
+ *
+ * @param type
+ * @param value
+ * @return
+ */
+ public static boolean isTypeMatch(Class<?> type, String value) {
+ if ((type == boolean.class || type == Boolean.class)
+ && !("true".equals(value) || "false".equals(value))) {
+ return false;
+ }
+ return true;
+ }
}
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java
index 91e226d..0b5d86f 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java
@@ -495,7 +495,7 @@ public abstract class AbstractConfig implements Serializable {
try {
String value = compositeConfiguration.getString(extractPropertyName(getClass(), method));
// isTypeMatch() is called to avoid duplicate and incorrect update, for example, we have two 'setGeneric' methods in ReferenceConfig.
- if (value != null && isTypeMatch(method.getParameterTypes()[0], value)) {
+ if (value != null && ClassHelper.isTypeMatch(method.getParameterTypes()[0], value)) {
method.invoke(this, ClassHelper.convertPrimitive(method.getParameterTypes()[0], value));
}
} catch (NoSuchMethodException e) {