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

fix #3656. #3703

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1816,7 +1816,7 @@ public int var(String name, int increment) {
variantIndex += increment;
}
i = variants.get(name);
return i.intValue();
return i;
}

public int var(String name) {
Expand All @@ -1825,7 +1825,7 @@ public int var(String name) {
variants.put(name, variantIndex++);
}
i = variants.get(name);
return i.intValue();
return i;
}

public int var_asm(FieldInfo fieldInfo) {
Expand Down
Expand Up @@ -53,14 +53,14 @@ public void setValue(Object object, String value) {
setValue(object, (Object) value);
}

private static final String Collections_Unmodifiable = "java.util.Collections$Unmodifiable";
@SuppressWarnings({"rawtypes", "unchecked"})
public void setValue(Object object, Object value) {
if (value == null //
&& fieldInfo.fieldClass.isPrimitive()) {
return;
} else if (fieldInfo.fieldClass == String.class
&& fieldInfo.format != null
&& fieldInfo.format.equals("trim")) {
&& "trim".equals(fieldInfo.format)) {
value = ((String) value).trim();
}

Expand Down Expand Up @@ -107,15 +107,15 @@ public void setValue(Object object, Object value) {
}

String mapClassName = map.getClass().getName();
if (mapClassName.equals("java.util.ImmutableCollections$Map1")
|| mapClassName.equals("java.util.ImmutableCollections$MapN")
|| mapClassName.startsWith("java.util.Collections$Unmodifiable")) {
if ("java.util.ImmutableCollections$Map1".equals(mapClassName)
|| "java.util.ImmutableCollections$MapN".equals(mapClassName)
|| mapClassName.startsWith(Collections_Unmodifiable)) {
// skip

return;
}

if (map.getClass().getName().equals("kotlin.collections.EmptyMap")) {
if ("kotlin.collections.EmptyMap".equals(map.getClass().getName())) {
degradeValueAssignment(fieldInfo.field, method, object, value);
return;
}
Expand All @@ -137,9 +137,9 @@ public void setValue(Object object, Object value) {

if (collection == Collections.emptySet()
|| collection == Collections.emptyList()
|| collectionClassName == "java.util.ImmutableCollections$ListN"
|| collectionClassName == "java.util.ImmutableCollections$List12"
|| collectionClassName.startsWith("java.util.Collections$Unmodifiable")) {
|| "java.util.ImmutableCollections$ListN".equals(collectionClassName)
|| "java.util.ImmutableCollections$List12".equals(collectionClassName)
|| collectionClassName.startsWith(Collections_Unmodifiable)) {
// skip
return;
}
Expand All @@ -151,8 +151,8 @@ public void setValue(Object object, Object value) {
}


if (collectionClassName.equals("kotlin.collections.EmptyList")
|| collectionClassName.equals("kotlin.collections.EmptySet")) {
if ("kotlin.collections.EmptyList".equals(collectionClassName)
|| "kotlin.collections.EmptySet".equals(collectionClassName)) {
degradeValueAssignment(fieldInfo.field, method, object, value);
return;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public void setValue(Object object, Object value) {
Map map = (Map) field.get(object);
if (map != null) {
if (map == Collections.emptyMap()
|| map.getClass().getName().startsWith("java.util.Collections$Unmodifiable")) {
|| map.getClass().getName().startsWith(Collections_Unmodifiable)) {
// skip
return;
}
Expand All @@ -198,7 +198,7 @@ public void setValue(Object object, Object value) {
if (collection != null && value != null) {
if (collection == Collections.emptySet()
|| collection == Collections.emptyList()
|| collection.getClass().getName().startsWith("java.util.Collections$Unmodifiable")) {
|| collection.getClass().getName().startsWith(Collections_Unmodifiable)) {
// skip
return;
}
Expand Down
Expand Up @@ -1524,13 +1524,13 @@ public Object createInstance(Map<String, Object> map, ParserConfig config) //
} else if (fieldClass == long.class) {
param = 0L;
} else if (fieldClass == short.class) {
param = Short.valueOf((short) 0);
param = (short) 0;
} else if (fieldClass == byte.class) {
param = Byte.valueOf((byte) 0);
param = (byte) 0;
} else if (fieldClass == float.class) {
param = Float.valueOf(0);
param = (float) 0;
} else if (fieldClass == double.class) {
param = Double.valueOf(0);
param = (double) 0;
} else if (fieldClass == char.class) {
param = '0';
} else if (fieldClass == boolean.class) {
Expand Down
Expand Up @@ -390,10 +390,10 @@ protected LocalDate parseLocalDate(String text, String format, DateTimeFormatter
} else {
String country = Locale.getDefault().getCountry();

if (country.equals("US")) {
if ("US".equals(country)) {
formatter = formatter_d10_us;
} else if (country.equals("BR") //
|| country.equals("AU")) {
} else if ("BR".equals(country) //
|| "AU".equals(country)) {
formatter = formatter_d10_eur;
}
}
Expand Down
Expand Up @@ -12,17 +12,17 @@
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.*;
import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;
import com.alibaba.fastjson.util.ParameterizedTypeImpl;

public class MapDeserializer extends ContextObjectDeserializer implements ObjectDeserializer {
public static MapDeserializer instance = new MapDeserializer();

@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, String format, int features)
{
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, String format, int features) {
if (type == JSONObject.class && parser.getFieldTypeResolver() == null) {
return (T) parser.parseObject();
}

final JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.NULL) {
lexer.nextToken(JSONToken.COMMA);
Expand Down Expand Up @@ -54,15 +54,15 @@ protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldNam
return deserialze(parser, type, fieldName, map, 0);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldName, Map map, int features) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
Type keyType = parameterizedType.getActualTypeArguments()[0];
Type valueType = null;
if(map.getClass().getName().equals("org.springframework.util.LinkedMultiValueMap")){
if (map.getClass().getName().equals("org.springframework.util.LinkedMultiValueMap")) {
valueType = List.class;
}else{
} else {
valueType = parameterizedType.getActualTypeArguments()[1];
}
if (String.class == keyType) {
Expand All @@ -78,7 +78,7 @@ protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldNam
public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Type valueType, Object fieldName) {
return parseMap(parser, map, valueType, fieldName, 0);
}

@SuppressWarnings("rawtypes")
public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Type valueType, Object fieldName, int features) {
JSONLexer lexer = parser.lexer;
Expand All @@ -102,12 +102,12 @@ public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Ty

if (token != JSONToken.LITERAL_STRING) {
JSONArray array = new JSONArray();
parser.parseArray(array, fieldName);

ParameterizedTypeImpl type = new ParameterizedTypeImpl(new Type[]{String.class, valueType}, null, Map.class);
parser.parseArray(type, array, fieldName);
if (array.size() == 1) {
Object first = array.get(0);
if (first instanceof JSONObject) {
return (JSONObject) first;
if (first instanceof Map) {
return (Map)first;
}
}
}
Expand All @@ -117,7 +117,7 @@ public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Ty

ParseContext context = parser.getContext();
try {
for (int i = 0;;++i) {
for (int i = 0; ; ++i) {
lexer.skipWhitespace();
char ch = lexer.getCurrent();
if (lexer.isEnabled(Feature.AllowArbitraryCommas)) {
Expand Down Expand Up @@ -171,7 +171,7 @@ public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Ty

lexer.resetStringPosition();

if (key == JSON.DEFAULT_TYPE_KEY
if (key.equals(JSON.DEFAULT_TYPE_KEY)
&& !lexer.isEnabled(Feature.DisableSpecialKeyDetect)
&& !Feature.isEnabled(features, Feature.DisableSpecialKeyDetect)
) {
Expand All @@ -188,7 +188,7 @@ public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Ty
clazz = config.checkAutoType(typeName, null, lexer.getFeatures());
}

if (Map.class.isAssignableFrom(clazz) ) {
if (Map.class.isAssignableFrom(clazz)) {
lexer.nextToken(JSONToken.COMMA);
if (lexer.token() == JSONToken.RBRACE) {
lexer.nextToken(JSONToken.COMMA);
Expand Down Expand Up @@ -216,7 +216,7 @@ public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Ty
if (i != 0) {
parser.setContext(context);
}

if (lexer.token() == JSONToken.NULL) {
value = null;
lexer.nextToken();
Expand Down Expand Up @@ -245,7 +245,7 @@ public static Map parseMap(DefaultJSONParser parser, Map<String, Object> map, Ty
}

}

public static Object parseMap(DefaultJSONParser parser, Map<Object, Object> map, Type keyType, Type valueType,
Object fieldName) {
JSONLexer lexer = parser.lexer;
Expand All @@ -260,15 +260,15 @@ public static Object parseMap(DefaultJSONParser parser, Map<Object, Object> map,

ParseContext context = parser.getContext();
try {
for (;;) {
for (; ; ) {
if (lexer.token() == JSONToken.RBRACE) {
lexer.nextToken(JSONToken.COMMA);
break;
}

if (lexer.token() == JSONToken.LITERAL_STRING //
&& lexer.isRef() //
&& !lexer.isEnabled(Feature.DisableSpecialKeyDetect) //
&& lexer.isRef() //
&& !lexer.isEnabled(Feature.DisableSpecialKeyDetect) //
) {
Object object = null;

Expand Down Expand Up @@ -306,9 +306,9 @@ public static Object parseMap(DefaultJSONParser parser, Map<Object, Object> map,
}

if (map.size() == 0 //
&& lexer.token() == JSONToken.LITERAL_STRING //
&& JSON.DEFAULT_TYPE_KEY.equals(lexer.stringVal()) //
&& !lexer.isEnabled(Feature.DisableSpecialKeyDetect)) {
&& lexer.token() == JSONToken.LITERAL_STRING //
&& JSON.DEFAULT_TYPE_KEY.equals(lexer.stringVal()) //
&& !lexer.isEnabled(Feature.DisableSpecialKeyDetect)) {
lexer.nextTokenWithColon(JSONToken.LITERAL_STRING);
lexer.nextToken(JSONToken.COMMA);
if (lexer.token() == JSONToken.RBRACE) {
Expand Down Expand Up @@ -357,7 +357,7 @@ public Map<Object, Object> createMap(Type type) {
return createMap(type, JSON.DEFAULT_GENERATE_FEATURE);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public Map<Object, Object> createMap(Type type, int featrues) {
if (type == Properties.class) {
return new Properties();
Expand All @@ -378,7 +378,7 @@ public Map<Object, Object> createMap(Type type, int featrues) {
if (type == ConcurrentMap.class || type == ConcurrentHashMap.class) {
return new ConcurrentHashMap();
}

if (type == Map.class) {
return (featrues & Feature.OrderedField.mask) != 0
? new LinkedHashMap()
Expand Down Expand Up @@ -413,14 +413,14 @@ public Map<Object, Object> createMap(Type type, int featrues) {
if ("java.util.Collections$UnmodifiableMap".equals(clazz.getName())) {
return new HashMap();
}

try {
return (Map<Object, Object>) clazz.newInstance();
} catch (Exception e) {
throw new JSONException("unsupport type " + type, e);
}
}


public int getFastMatchToken() {
return JSONToken.LBRACE;
Expand Down
Expand Up @@ -30,7 +30,7 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
return (T) OptionalInt.of(value);
}
}

if (type == OptionalLong.class) {
Object obj = parser.parseObject(Long.class);
Long value = TypeUtils.castToLong(obj);
Expand All @@ -40,7 +40,7 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
return (T) OptionalLong.of(value);
}
}

if (type == OptionalDouble.class) {
Object obj = parser.parseObject(Double.class);
Double value = TypeUtils.castToDouble(obj);
Expand All @@ -50,14 +50,14 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
return (T) OptionalDouble.of(value);
}
}

type = TypeUtils.unwrapOptional(type);
Object value = parser.parseObject(type);

if (value == null) {
return (T) Optional.empty();
}

return (T) Optional.of(value);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty
}
return;
}

if (object instanceof OptionalInt) {
OptionalInt optional = (OptionalInt) object;
if (optional.isPresent()) {
Expand All @@ -101,7 +101,7 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty
}
return;
}

if (object instanceof OptionalLong) {
OptionalLong optional = (OptionalLong) object;
if (optional.isPresent()) {
Expand All @@ -112,7 +112,7 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty
}
return;
}

throw new JSONException("not support optional : " + object.getClass());
}

Expand Down
Expand Up @@ -116,7 +116,7 @@ protected <T> T castTimestamp(DefaultJSONParser parser, Type clazz, Object field
&& strVal.charAt(16) == ':'
&& strVal.charAt(19) == '.') {
String dateFomartPattern = parser.getDateFomartPattern();
if (dateFomartPattern.length() != strVal.length() && dateFomartPattern == JSON.DEFFAULT_DATE_FORMAT) {
if (dateFomartPattern.length() != strVal.length() && JSON.DEFFAULT_DATE_FORMAT.equals(dateFomartPattern)) {
return (T) java.sql.Timestamp.valueOf(strVal);
}
}
Expand Down
Expand Up @@ -92,10 +92,10 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
} else {
throw new JSONException("syntax error");
}
} else if (key == JSON.DEFAULT_TYPE_KEY) {
} else if (JSON.DEFAULT_TYPE_KEY.equals(key)) {
if (lexer.token() == JSONToken.LITERAL_STRING) {
String elementType = lexer.stringVal();
if (!elementType.equals("java.lang.StackTraceElement")) {
if (!"java.lang.StackTraceElement".equals(elementType)) {
throw new JSONException("syntax error : " + elementType);
}
} else {
Expand Down
Expand Up @@ -41,7 +41,7 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
Throwable cause = null;
Class<?> exClass = null;

if (type != null && type instanceof Class) {
if (type instanceof Class) {
Class<?> clazz = (Class<?>) type;
if (Throwable.class.isAssignableFrom(clazz)) {
exClass = clazz;
Expand Down