Skip to content

Commit

Permalink
Remove needless toString convert & Enable checking by default (#8073)
Browse files Browse the repository at this point in the history
* Remove needless toString convert & Enable checking by default

* enable check
  • Loading branch information
AlbumenJ authored Jun 16, 2021
1 parent b6af8bf commit 16b3d42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private static Object generalize(Object pojo, Map<Object, Object> history) {
if (history.containsKey(pojo)) {
Object pojoGeneralizedValue = history.get(pojo);
if (pojoGeneralizedValue instanceof Map
&& ((Map) pojoGeneralizedValue).containsKey(field.getName())) {
&& ((Map) pojoGeneralizedValue).containsKey(field.getName())) {
continue;
}
}
Expand Down Expand Up @@ -312,9 +312,9 @@ private static Object realize0(Object pojo, Class<?> type, Type genericType, fin
}

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);
}

Expand Down Expand Up @@ -399,7 +399,11 @@ private static Object realize0(Object pojo, Class<?> type, Type genericType, fin
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);
}
}
}
Map<Object, Object> map;
Expand All @@ -426,8 +430,8 @@ private static Object realize0(Object pojo, Class<?> type, Type genericType, fin
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 {
Expand Down Expand Up @@ -485,7 +489,7 @@ private static Object realize0(Object pojo, Class<?> type, Type genericType, fin
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);
}
Expand Down Expand Up @@ -663,8 +667,8 @@ private static Field getField(Class<?> cls, String fieldName) {

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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Object decode(Channel channel, InputStream input) throws IOException {
setParameterTypesDesc(desc);

try {
if (ConfigurationUtils.getSystemConfiguration().getBoolean(SERIALIZATION_SECURITY_CHECK_KEY, false)) {
if (ConfigurationUtils.getSystemConfiguration().getBoolean(SERIALIZATION_SECURITY_CHECK_KEY, true)) {
CodecSupport.checkSerialization(path, version, serializationType);
}
Object[] args = DubboCodec.EMPTY_OBJECT_ARRAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Object decode(Channel channel, InputStream input) throws IOException {
public void decode() throws Exception {
if (!hasDecoded && channel != null && inputStream != null) {
try {
if (ConfigurationUtils.getSystemConfiguration().getBoolean(SERIALIZATION_SECURITY_CHECK_KEY, false)) {
if (ConfigurationUtils.getSystemConfiguration().getBoolean(SERIALIZATION_SECURITY_CHECK_KEY, true)) {
Object serializationType_obj = invocation.get(SERIALIZATION_ID_KEY);
if (serializationType_obj != null) {
if ((byte) serializationType_obj != serializationType) {
Expand Down

0 comments on commit 16b3d42

Please sign in to comment.