You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/18 03:24:21 UTC
[dubbo] branch master updated: Remove needless toString convert
(#8092)
This is an automated email from the ASF dual-hosted git repository.
albumenj 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 d16d0e1 Remove needless toString convert (#8092)
d16d0e1 is described below
commit d16d0e15d8ffbf9b06c92639559f59dc29ddb42f
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Fri Jun 18 11:24:11 2021 +0800
Remove needless toString convert (#8092)
---
.../org/apache/dubbo/common/utils/PojoUtils.java | 24 +++++++++++++---------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java
index aa78a1e..a6eb767 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java
@@ -197,7 +197,7 @@ public class PojoUtils {
if (history.containsKey(pojo)) {
Object pojoGeneralizedValue = history.get(pojo);
if (pojoGeneralizedValue instanceof Map
- && ((Map) pojoGeneralizedValue).containsKey(field.getName())) {
+ && ((Map) pojoGeneralizedValue).containsKey(field.getName())) {
continue;
}
}
@@ -321,9 +321,9 @@ public class PojoUtils {
}
if (ReflectUtils.isPrimitives(pojo.getClass())
- && !(type != null && type.isArray()
- && type.getComponentType().isEnum()
- && pojo.getClass() == String[].class)) {
+ && !(type != null && type.isArray()
+ && type.getComponentType().isEnum()
+ && pojo.getClass() == String[].class)) {
return CompatibleTypeUtils.compatibleTypeConvert(pojo, type);
}
@@ -412,7 +412,11 @@ public class PojoUtils {
if (type.isEnum()) {
Object name = ((Map<Object, Object>) pojo).get("name");
if (name != null) {
- return Enum.valueOf((Class<Enum>) type, name.toString());
+ if (!(name instanceof String)) {
+ throw new IllegalArgumentException("`name` filed should be string!");
+ } else {
+ return Enum.valueOf((Class<Enum>) type, (String) name);
+ }
}
}
@@ -422,8 +426,8 @@ public class PojoUtils {
Type mapKeyType = getKeyTypeForMap(map.getClass());
Type typeKeyType = getGenericClassByIndex(genericType, 0);
boolean typeMismatch = mapKeyType instanceof Class
- && typeKeyType instanceof Class
- && !typeKeyType.getTypeName().equals(mapKeyType.getTypeName());
+ && typeKeyType instanceof Class
+ && !typeKeyType.getTypeName().equals(mapKeyType.getTypeName());
if (typeMismatch) {
result = createMap(new HashMap(0));
} else {
@@ -477,7 +481,7 @@ public class PojoUtils {
method.invoke(dest, value);
} catch (Exception e) {
String exceptionDescription = "Failed to set pojo " + dest.getClass().getSimpleName() + " property " + name
- + " value " + value + "(" + value.getClass() + "), cause: " + e.getMessage();
+ + " value " + value.getClass() + ", cause: " + e.getMessage();
logger.error(exceptionDescription, e);
throw new RuntimeException(exceptionDescription, e);
}
@@ -658,8 +662,8 @@ public class PojoUtils {
public static boolean isPojo(Class<?> cls) {
return !ReflectUtils.isPrimitives(cls)
- && !Collection.class.isAssignableFrom(cls)
- && !Map.class.isAssignableFrom(cls);
+ && !Collection.class.isAssignableFrom(cls)
+ && !Map.class.isAssignableFrom(cls);
}
/**