The following issues were found
src/test/java/com/alibaba/json/bvt/path/JSONPath_9.java
16 issues
Line: 14
public class JSONPath_9 extends TestCase {
public void test_paths() throws Exception {
Model m = new Model();
m.f0 = 101;
m.f1 = 102;
Map<String, Object> paths = JSONPath.paths(m);
Reported by PMD.
Line: 20
m.f1 = 102;
Map<String, Object> paths = JSONPath.paths(m);
assertEquals(3, paths.size());
}
public void test_paths_1() throws Exception {
Map map = new HashMap();
map.put("f0", 1001);
Reported by PMD.
Line: 20
m.f1 = 102;
Map<String, Object> paths = JSONPath.paths(m);
assertEquals(3, paths.size());
}
public void test_paths_1() throws Exception {
Map map = new HashMap();
map.put("f0", 1001);
Reported by PMD.
Line: 23
assertEquals(3, paths.size());
}
public void test_paths_1() throws Exception {
Map map = new HashMap();
map.put("f0", 1001);
map.put("f1", 1002);
Map<String, Object> paths = JSONPath.paths(map);
Reported by PMD.
Line: 29
map.put("f1", 1002);
Map<String, Object> paths = JSONPath.paths(map);
assertEquals(3, paths.size());
}
public void test_paths_2() throws Exception {
Map map = new HashMap();
map.put("f0", 1001);
Reported by PMD.
Line: 29
map.put("f1", 1002);
Map<String, Object> paths = JSONPath.paths(map);
assertEquals(3, paths.size());
}
public void test_paths_2() throws Exception {
Map map = new HashMap();
map.put("f0", 1001);
Reported by PMD.
Line: 32
assertEquals(3, paths.size());
}
public void test_paths_2() throws Exception {
Map map = new HashMap();
map.put("f0", 1001);
map.put("f1", 1002);
JSONPath path = new JSONPath("$.f0");
Reported by PMD.
Line: 32
assertEquals(3, paths.size());
}
public void test_paths_2() throws Exception {
Map map = new HashMap();
map.put("f0", 1001);
map.put("f1", 1002);
JSONPath path = new JSONPath("$.f0");
Reported by PMD.
Line: 38
map.put("f1", 1002);
JSONPath path = new JSONPath("$.f0");
assertEquals("$.f0", path.getPath());
assertEquals(1001, path.eval(map));
path.remove(null);
}
Reported by PMD.
Line: 39
JSONPath path = new JSONPath("$.f0");
assertEquals("$.f0", path.getPath());
assertEquals(1001, path.eval(map));
path.remove(null);
}
public void test_paths_3() throws Exception {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/path/JSONPath_field_access_filter_compare_int.java
16 issues
Line: 14
public class JSONPath_field_access_filter_compare_int extends TestCase {
List<Entity> entities = new ArrayList<Entity>();
public JSONPath_field_access_filter_compare_int(){
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, null));
Reported by PMD.
Line: 23
entities.add(new Entity(null, null));
}
public void test_list_map_le() throws Exception {
JSONPath path = new JSONPath("$[?(@.id <= 1002)]");
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Reported by PMD.
Line: 27
JSONPath path = new JSONPath("$[?(@.id <= 1002)]");
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Assert.assertSame(entities.get(1), result.get(1));
}
public void test_list_map_lt() throws Exception {
Reported by PMD.
Line: 28
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Assert.assertSame(entities.get(1), result.get(1));
}
public void test_list_map_lt() throws Exception {
JSONPath path = new JSONPath("$[?(@.id < 1002)]");
Reported by PMD.
Line: 29
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Assert.assertSame(entities.get(1), result.get(1));
}
public void test_list_map_lt() throws Exception {
JSONPath path = new JSONPath("$[?(@.id < 1002)]");
Reported by PMD.
Line: 32
Assert.assertSame(entities.get(1), result.get(1));
}
public void test_list_map_lt() throws Exception {
JSONPath path = new JSONPath("$[?(@.id < 1002)]");
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(1, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Reported by PMD.
Line: 36
JSONPath path = new JSONPath("$[?(@.id < 1002)]");
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(1, result.size());
Assert.assertSame(entities.get(0), result.get(0));
}
public void test_list_map_ge() throws Exception {
JSONPath path = new JSONPath("$[?(@.id >= 1002)]");
Reported by PMD.
Line: 37
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(1, result.size());
Assert.assertSame(entities.get(0), result.get(0));
}
public void test_list_map_ge() throws Exception {
JSONPath path = new JSONPath("$[?(@.id >= 1002)]");
Reported by PMD.
Line: 40
Assert.assertSame(entities.get(0), result.get(0));
}
public void test_list_map_ge() throws Exception {
JSONPath path = new JSONPath("$[?(@.id >= 1002)]");
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(1), result.get(0));
Reported by PMD.
Line: 44
JSONPath path = new JSONPath("$[?(@.id >= 1002)]");
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(1), result.get(0));
Assert.assertSame(entities.get(2), result.get(1));
}
public void test_list_map_gt() throws Exception {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/path/DLATest_0.java
16 issues
Line: 13
import java.io.InputStreamReader;
public class DLATest_0 extends TestCase {
public void test_dla() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
String json = IOUtils.readAll(reader);
Object object = JSON.parse(json, Feature.IgnoreAutoType, Feature.OrderedField);
Object result = JSONPath.eval(object, "$..elapsedTime");
Reported by PMD.
Line: 13
import java.io.InputStreamReader;
public class DLATest_0 extends TestCase {
public void test_dla() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
String json = IOUtils.readAll(reader);
Object object = JSON.parse(json, Feature.IgnoreAutoType, Feature.OrderedField);
Object result = JSONPath.eval(object, "$..elapsedTime");
Reported by PMD.
Line: 14
public class DLATest_0 extends TestCase {
public void test_dla() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
String json = IOUtils.readAll(reader);
Object object = JSON.parse(json, Feature.IgnoreAutoType, Feature.OrderedField);
Object result = JSONPath.eval(object, "$..elapsedTime");
assertEquals("[\"1.48s\",1031,1031,1005,1005,1011,1011]", JSON.toJSONString(result));
Reported by PMD.
Line: 14
public class DLATest_0 extends TestCase {
public void test_dla() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
String json = IOUtils.readAll(reader);
Object object = JSON.parse(json, Feature.IgnoreAutoType, Feature.OrderedField);
Object result = JSONPath.eval(object, "$..elapsedTime");
assertEquals("[\"1.48s\",1031,1031,1005,1005,1011,1011]", JSON.toJSONString(result));
Reported by PMD.
Line: 14
public class DLATest_0 extends TestCase {
public void test_dla() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
String json = IOUtils.readAll(reader);
Object object = JSON.parse(json, Feature.IgnoreAutoType, Feature.OrderedField);
Object result = JSONPath.eval(object, "$..elapsedTime");
assertEquals("[\"1.48s\",1031,1031,1005,1005,1011,1011]", JSON.toJSONString(result));
Reported by PMD.
Line: 15
public class DLATest_0 extends TestCase {
public void test_dla() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
String json = IOUtils.readAll(reader);
Object object = JSON.parse(json, Feature.IgnoreAutoType, Feature.OrderedField);
Object result = JSONPath.eval(object, "$..elapsedTime");
assertEquals("[\"1.48s\",1031,1031,1005,1005,1011,1011]", JSON.toJSONString(result));
Reported by PMD.
Line: 19
String json = IOUtils.readAll(reader);
Object object = JSON.parse(json, Feature.IgnoreAutoType, Feature.OrderedField);
Object result = JSONPath.eval(object, "$..elapsedTime");
assertEquals("[\"1.48s\",1031,1031,1005,1005,1011,1011]", JSON.toJSONString(result));
Object result2 = JSONPath.eval(object, "$..self");
assertEquals("[\"http://172.17.246.55:10001/v1/query/20181024_040507_3_f32vb\",\"http://172.17.246.55:10001/v1/stage/20181024_040507_3_f32vb.0\",\"http://172.17.246.56:14005/v1/task/20181024_040507_3_f32vb.0.0?shufferNettyServerPort=39524&commandNettyServerPort=37207\",\"http://172.17.246.55:10001/v1/stage/20181024_040507_3_f32vb.1\",\"http://172.17.246.55:14005/v1/task/20181024_040507_3_f32vb.1.0?shufferNettyServerPort=33921&commandNettyServerPort=45121\",\"http://172.17.246.56:14005/v1/task/20181024_040507_3_f32vb.1.1?shufferNettyServerPort=39524&commandNettyServerPort=37207\"]", JSON.toJSONString(result2));
}
Reported by PMD.
Line: 22
assertEquals("[\"1.48s\",1031,1031,1005,1005,1011,1011]", JSON.toJSONString(result));
Object result2 = JSONPath.eval(object, "$..self");
assertEquals("[\"http://172.17.246.55:10001/v1/query/20181024_040507_3_f32vb\",\"http://172.17.246.55:10001/v1/stage/20181024_040507_3_f32vb.0\",\"http://172.17.246.56:14005/v1/task/20181024_040507_3_f32vb.0.0?shufferNettyServerPort=39524&commandNettyServerPort=37207\",\"http://172.17.246.55:10001/v1/stage/20181024_040507_3_f32vb.1\",\"http://172.17.246.55:14005/v1/task/20181024_040507_3_f32vb.1.0?shufferNettyServerPort=33921&commandNettyServerPort=45121\",\"http://172.17.246.56:14005/v1/task/20181024_040507_3_f32vb.1.1?shufferNettyServerPort=39524&commandNettyServerPort=37207\"]", JSON.toJSONString(result2));
}
public void test_dla_extract() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
Reported by PMD.
Line: 25
assertEquals("[\"http://172.17.246.55:10001/v1/query/20181024_040507_3_f32vb\",\"http://172.17.246.55:10001/v1/stage/20181024_040507_3_f32vb.0\",\"http://172.17.246.56:14005/v1/task/20181024_040507_3_f32vb.0.0?shufferNettyServerPort=39524&commandNettyServerPort=37207\",\"http://172.17.246.55:10001/v1/stage/20181024_040507_3_f32vb.1\",\"http://172.17.246.55:14005/v1/task/20181024_040507_3_f32vb.1.0?shufferNettyServerPort=33921&commandNettyServerPort=45121\",\"http://172.17.246.56:14005/v1/task/20181024_040507_3_f32vb.1.1?shufferNettyServerPort=39524&commandNettyServerPort=37207\"]", JSON.toJSONString(result2));
}
public void test_dla_extract() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
String json = IOUtils.readAll(reader);
Object result = JSONPath.extract(json, "$..elapsedTime");
Reported by PMD.
Line: 25
assertEquals("[\"http://172.17.246.55:10001/v1/query/20181024_040507_3_f32vb\",\"http://172.17.246.55:10001/v1/stage/20181024_040507_3_f32vb.0\",\"http://172.17.246.56:14005/v1/task/20181024_040507_3_f32vb.0.0?shufferNettyServerPort=39524&commandNettyServerPort=37207\",\"http://172.17.246.55:10001/v1/stage/20181024_040507_3_f32vb.1\",\"http://172.17.246.55:14005/v1/task/20181024_040507_3_f32vb.1.0?shufferNettyServerPort=33921&commandNettyServerPort=45121\",\"http://172.17.246.56:14005/v1/task/20181024_040507_3_f32vb.1.1?shufferNettyServerPort=39524&commandNettyServerPort=37207\"]", JSON.toJSONString(result2));
}
public void test_dla_extract() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/dla_01.json");
InputStreamReader reader = new InputStreamReader(is);
String json = IOUtils.readAll(reader);
Object result = JSONPath.extract(json, "$..elapsedTime");
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/deser/HashtableFieldTest.java
16 issues
Line: 13
public class HashtableFieldTest extends TestCase {
public void test_null() throws Exception {
Entity value = JSON.parseObject("{value:null}", Entity.class);
Assert.assertNull(value.getValue());
}
public void test_empty() throws Exception {
Reported by PMD.
Line: 15
public void test_null() throws Exception {
Entity value = JSON.parseObject("{value:null}", Entity.class);
Assert.assertNull(value.getValue());
}
public void test_empty() throws Exception {
Entity value = JSON.parseObject("{value:{}}", Entity.class);
Assert.assertEquals(0, value.getValue().size());
Reported by PMD.
Line: 18
Assert.assertNull(value.getValue());
}
public void test_empty() throws Exception {
Entity value = JSON.parseObject("{value:{}}", Entity.class);
Assert.assertEquals(0, value.getValue().size());
}
public void test_null_2() throws Exception {
Reported by PMD.
Line: 20
public void test_empty() throws Exception {
Entity value = JSON.parseObject("{value:{}}", Entity.class);
Assert.assertEquals(0, value.getValue().size());
}
public void test_null_2() throws Exception {
Entity value = JSON.parseObject("{\"value\":null}", Entity.class);
Assert.assertNull(value.getValue());
Reported by PMD.
Line: 20
public void test_empty() throws Exception {
Entity value = JSON.parseObject("{value:{}}", Entity.class);
Assert.assertEquals(0, value.getValue().size());
}
public void test_null_2() throws Exception {
Entity value = JSON.parseObject("{\"value\":null}", Entity.class);
Assert.assertNull(value.getValue());
Reported by PMD.
Line: 23
Assert.assertEquals(0, value.getValue().size());
}
public void test_null_2() throws Exception {
Entity value = JSON.parseObject("{\"value\":null}", Entity.class);
Assert.assertNull(value.getValue());
}
public void test_empty_a() throws Exception {
Reported by PMD.
Line: 25
public void test_null_2() throws Exception {
Entity value = JSON.parseObject("{\"value\":null}", Entity.class);
Assert.assertNull(value.getValue());
}
public void test_empty_a() throws Exception {
A value = JSON.parseObject("{value:{\"@type\":\"java.util.Hashtable\"}}", A.class);
Assert.assertEquals(0, ((Hashtable)value.getValue()).size());
Reported by PMD.
Line: 28
Assert.assertNull(value.getValue());
}
public void test_empty_a() throws Exception {
A value = JSON.parseObject("{value:{\"@type\":\"java.util.Hashtable\"}}", A.class);
Assert.assertEquals(0, ((Hashtable)value.getValue()).size());
}
private static class Entity {
Reported by PMD.
Line: 30
public void test_empty_a() throws Exception {
A value = JSON.parseObject("{value:{\"@type\":\"java.util.Hashtable\"}}", A.class);
Assert.assertEquals(0, ((Hashtable)value.getValue()).size());
}
private static class Entity {
private Hashtable value;
Reported by PMD.
Line: 30
public void test_empty_a() throws Exception {
A value = JSON.parseObject("{value:{\"@type\":\"java.util.Hashtable\"}}", A.class);
Assert.assertEquals(0, ((Hashtable)value.getValue()).size());
}
private static class Entity {
private Hashtable value;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/deser/IntegerFieldDeserializerTest2.java
16 issues
Line: 16
public class IntegerFieldDeserializerTest2 extends TestCase {
protected void setUp() throws Exception {
// ParserConfig.getGlobalInstance().setAsmEnable(false);
}
public void test_integer() throws Exception {
String text = "{\"value\":{\"column1\":\"aa\"}}";
Reported by PMD.
Line: 20
// ParserConfig.getGlobalInstance().setAsmEnable(false);
}
public void test_integer() throws Exception {
String text = "{\"value\":{\"column1\":\"aa\"}}";
Map<String, Entity> map = JSON.parseObject(text, new TypeReference<Map<String, Entity>>(){});
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("value"));
Assert.assertNotNull("aa", map.get("value").getColumn1());
Reported by PMD.
Line: 24
String text = "{\"value\":{\"column1\":\"aa\"}}";
Map<String, Entity> map = JSON.parseObject(text, new TypeReference<Map<String, Entity>>(){});
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("value"));
Assert.assertNotNull("aa", map.get("value").getColumn1());
}
public void test_integer_2() throws Exception {
String text = "[{\"value\":{\"column1\":\"aa\"}}]";
Reported by PMD.
Line: 25
Map<String, Entity> map = JSON.parseObject(text, new TypeReference<Map<String, Entity>>(){});
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("value"));
Assert.assertNotNull("aa", map.get("value").getColumn1());
}
public void test_integer_2() throws Exception {
String text = "[{\"value\":{\"column1\":\"aa\"}}]";
List<Map<String, Entity>> mapList = JSON.parseObject(text, new TypeReference<List<Map<String, Entity>>>(){});
Reported by PMD.
Line: 28
Assert.assertNotNull("aa", map.get("value").getColumn1());
}
public void test_integer_2() throws Exception {
String text = "[{\"value\":{\"column1\":\"aa\"}}]";
List<Map<String, Entity>> mapList = JSON.parseObject(text, new TypeReference<List<Map<String, Entity>>>(){});
Map<String, Entity> map = mapList.get(0);
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("value"));
Reported by PMD.
Line: 33
List<Map<String, Entity>> mapList = JSON.parseObject(text, new TypeReference<List<Map<String, Entity>>>(){});
Map<String, Entity> map = mapList.get(0);
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("value"));
Assert.assertNotNull("aa", map.get("value").getColumn1());
}
public void test_integer_3() throws Exception {
String text = "{\"value\":{\"valueA\":{\"column1\":\"aa\"}, \"valueB\":{\"column1\":\"bb\"}}}";
Reported by PMD.
Line: 34
Map<String, Entity> map = mapList.get(0);
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("value"));
Assert.assertNotNull("aa", map.get("value").getColumn1());
}
public void test_integer_3() throws Exception {
String text = "{\"value\":{\"valueA\":{\"column1\":\"aa\"}, \"valueB\":{\"column1\":\"bb\"}}}";
Map<String, Map<String, Entity>> mapmap = JSON.parseObject(text, new TypeReference<Map<String, Map<String, Entity>>>(){});
Reported by PMD.
Line: 34
Map<String, Entity> map = mapList.get(0);
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("value"));
Assert.assertNotNull("aa", map.get("value").getColumn1());
}
public void test_integer_3() throws Exception {
String text = "{\"value\":{\"valueA\":{\"column1\":\"aa\"}, \"valueB\":{\"column1\":\"bb\"}}}";
Map<String, Map<String, Entity>> mapmap = JSON.parseObject(text, new TypeReference<Map<String, Map<String, Entity>>>(){});
Reported by PMD.
Line: 37
Assert.assertNotNull("aa", map.get("value").getColumn1());
}
public void test_integer_3() throws Exception {
String text = "{\"value\":{\"valueA\":{\"column1\":\"aa\"}, \"valueB\":{\"column1\":\"bb\"}}}";
Map<String, Map<String, Entity>> mapmap = JSON.parseObject(text, new TypeReference<Map<String, Map<String, Entity>>>(){});
Map<String, Entity> map = mapmap.get("value");
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("valueA"));
Reported by PMD.
Line: 42
Map<String, Map<String, Entity>> mapmap = JSON.parseObject(text, new TypeReference<Map<String, Map<String, Entity>>>(){});
Map<String, Entity> map = mapmap.get("value");
Assert.assertNotNull(map);
Assert.assertNotNull(map.get("valueA"));
Assert.assertNotNull("aa", map.get("valueA").getColumn1());
Assert.assertNotNull(map.get("valueB"));
Assert.assertNotNull("bb", map.get("valueB").getColumn1());
}
Reported by PMD.
src/main/java/com/alibaba/fastjson/parser/deserializer/OptionalCodec.java
16 issues
Line: 22
public static OptionalCodec instance = new OptionalCodec();
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
if (type == OptionalInt.class) {
Object obj = parser.parseObject(Integer.class);
Integer value = TypeUtils.castToInt(obj);
if (value == null) {
Reported by PMD.
Line: 17
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.util.TypeUtils;
public class OptionalCodec implements ObjectSerializer, ObjectDeserializer {
public static OptionalCodec instance = new OptionalCodec();
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
Reported by PMD.
Line: 17
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.util.TypeUtils;
public class OptionalCodec implements ObjectSerializer, ObjectDeserializer {
public static OptionalCodec instance = new OptionalCodec();
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
Reported by PMD.
Line: 68
return JSONToken.LBRACE;
}
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
int features) throws IOException {
if (object == null) {
serializer.writeNull();
return;
Reported by PMD.
Line: 68
return JSONToken.LBRACE;
}
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
int features) throws IOException {
if (object == null) {
serializer.writeNull();
return;
Reported by PMD.
Line: 68
return JSONToken.LBRACE;
}
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
int features) throws IOException {
if (object == null) {
serializer.writeNull();
return;
Reported by PMD.
Line: 78
if (object instanceof Optional) {
Optional<?> optional = (Optional<?>) object;
Object value = optional.isPresent() ? optional.get() : null;
serializer.write(value);
return;
}
if (object instanceof OptionalDouble) {
Reported by PMD.
Line: 78
if (object instanceof Optional) {
Optional<?> optional = (Optional<?>) object;
Object value = optional.isPresent() ? optional.get() : null;
serializer.write(value);
return;
}
if (object instanceof OptionalDouble) {
Reported by PMD.
Line: 85
if (object instanceof OptionalDouble) {
OptionalDouble optional = (OptionalDouble) object;
if (optional.isPresent()) {
double value = optional.getAsDouble();
serializer.write(value);
} else {
serializer.writeNull();
}
Reported by PMD.
Line: 86
if (object instanceof OptionalDouble) {
OptionalDouble optional = (OptionalDouble) object;
if (optional.isPresent()) {
double value = optional.getAsDouble();
serializer.write(value);
} else {
serializer.writeNull();
}
return;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue869_1.java
16 issues
Line: 14
* Created by wenshao on 2016/11/13.
*/
public class Issue869_1 extends TestCase {
public void test_for_issue() throws Exception {
List<DoublePoint> doublePointList = new ArrayList<DoublePoint>();
{
DoublePoint doublePoint = new DoublePoint();
doublePoint.startPoint = new Point(22, 35);
doublePoint.endPoint = doublePoint.startPoint;
Reported by PMD.
Line: 30
}
String json = JSON.toJSONString(doublePointList);
assertEquals("[{\"endPoint\":{\"x\":22,\"y\":35},\"startPoint\":{\"$ref\":\"$[0].endPoint\"}},{\"endPoint\":{\"x\":16,\"y\":18},\"startPoint\":{\"$ref\":\"$[1].endPoint\"}}]", json);
}
public void test_for_issue_parse() throws Exception {
String text = "[{\"endPoint\":{\"x\":22,\"y\":35},\"startPoint\":{\"$ref\":\"$[0].endPoint\"}},{\"endPoint\":{\"$ref\":\"$[1].startPoint\"},\"startPoint\":{\"x\":16,\"y\":18}}]";
Reported by PMD.
Line: 33
assertEquals("[{\"endPoint\":{\"x\":22,\"y\":35},\"startPoint\":{\"$ref\":\"$[0].endPoint\"}},{\"endPoint\":{\"x\":16,\"y\":18},\"startPoint\":{\"$ref\":\"$[1].endPoint\"}}]", json);
}
public void test_for_issue_parse() throws Exception {
String text = "[{\"endPoint\":{\"x\":22,\"y\":35},\"startPoint\":{\"$ref\":\"$[0].endPoint\"}},{\"endPoint\":{\"$ref\":\"$[1].startPoint\"},\"startPoint\":{\"x\":16,\"y\":18}}]";
List<Issue869.DoublePoint> doublePointList = JSON.parseObject(text, new TypeReference<List<Issue869.DoublePoint>>(){});
assertNotNull(doublePointList.get(0));
assertNotNull(doublePointList.get(1));
Reported by PMD.
Line: 33
assertEquals("[{\"endPoint\":{\"x\":22,\"y\":35},\"startPoint\":{\"$ref\":\"$[0].endPoint\"}},{\"endPoint\":{\"x\":16,\"y\":18},\"startPoint\":{\"$ref\":\"$[1].endPoint\"}}]", json);
}
public void test_for_issue_parse() throws Exception {
String text = "[{\"endPoint\":{\"x\":22,\"y\":35},\"startPoint\":{\"$ref\":\"$[0].endPoint\"}},{\"endPoint\":{\"$ref\":\"$[1].startPoint\"},\"startPoint\":{\"x\":16,\"y\":18}}]";
List<Issue869.DoublePoint> doublePointList = JSON.parseObject(text, new TypeReference<List<Issue869.DoublePoint>>(){});
assertNotNull(doublePointList.get(0));
assertNotNull(doublePointList.get(1));
Reported by PMD.
Line: 37
String text = "[{\"endPoint\":{\"x\":22,\"y\":35},\"startPoint\":{\"$ref\":\"$[0].endPoint\"}},{\"endPoint\":{\"$ref\":\"$[1].startPoint\"},\"startPoint\":{\"x\":16,\"y\":18}}]";
List<Issue869.DoublePoint> doublePointList = JSON.parseObject(text, new TypeReference<List<Issue869.DoublePoint>>(){});
assertNotNull(doublePointList.get(0));
assertNotNull(doublePointList.get(1));
assertSame(doublePointList.get(0).startPoint, doublePointList.get(0).endPoint);
assertSame(doublePointList.get(1).startPoint, doublePointList.get(1).endPoint);
}
Reported by PMD.
Line: 38
String text = "[{\"endPoint\":{\"x\":22,\"y\":35},\"startPoint\":{\"$ref\":\"$[0].endPoint\"}},{\"endPoint\":{\"$ref\":\"$[1].startPoint\"},\"startPoint\":{\"x\":16,\"y\":18}}]";
List<Issue869.DoublePoint> doublePointList = JSON.parseObject(text, new TypeReference<List<Issue869.DoublePoint>>(){});
assertNotNull(doublePointList.get(0));
assertNotNull(doublePointList.get(1));
assertSame(doublePointList.get(0).startPoint, doublePointList.get(0).endPoint);
assertSame(doublePointList.get(1).startPoint, doublePointList.get(1).endPoint);
}
public static class DoublePoint{
Reported by PMD.
Line: 39
List<Issue869.DoublePoint> doublePointList = JSON.parseObject(text, new TypeReference<List<Issue869.DoublePoint>>(){});
assertNotNull(doublePointList.get(0));
assertNotNull(doublePointList.get(1));
assertSame(doublePointList.get(0).startPoint, doublePointList.get(0).endPoint);
assertSame(doublePointList.get(1).startPoint, doublePointList.get(1).endPoint);
}
public static class DoublePoint{
public Point startPoint;
Reported by PMD.
Line: 39
List<Issue869.DoublePoint> doublePointList = JSON.parseObject(text, new TypeReference<List<Issue869.DoublePoint>>(){});
assertNotNull(doublePointList.get(0));
assertNotNull(doublePointList.get(1));
assertSame(doublePointList.get(0).startPoint, doublePointList.get(0).endPoint);
assertSame(doublePointList.get(1).startPoint, doublePointList.get(1).endPoint);
}
public static class DoublePoint{
public Point startPoint;
Reported by PMD.
Line: 39
List<Issue869.DoublePoint> doublePointList = JSON.parseObject(text, new TypeReference<List<Issue869.DoublePoint>>(){});
assertNotNull(doublePointList.get(0));
assertNotNull(doublePointList.get(1));
assertSame(doublePointList.get(0).startPoint, doublePointList.get(0).endPoint);
assertSame(doublePointList.get(1).startPoint, doublePointList.get(1).endPoint);
}
public static class DoublePoint{
public Point startPoint;
Reported by PMD.
Line: 40
assertNotNull(doublePointList.get(0));
assertNotNull(doublePointList.get(1));
assertSame(doublePointList.get(0).startPoint, doublePointList.get(0).endPoint);
assertSame(doublePointList.get(1).startPoint, doublePointList.get(1).endPoint);
}
public static class DoublePoint{
public Point startPoint;
public Point endPoint;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1400/Issue1424.java
16 issues
Line: 71
floatOverflowMap.put("v", floatOverflow + floatOverflow);
String sFloatOverflow = JSON.toJSONString(floatOverflowMap);
System.out.println(sFloatOverflow);
assertEquals("{\"v\":6.805646932770577E38}", sFloatOverflow);
FloatVal floatVal = JSON.parseObject(sFloatOverflow, FloatVal.class);
assertEquals(Float.parseFloat("6.805646932770577E38"), floatVal.v);
}
}
Reported by PMD.
Line: 12
public class Issue1424 extends TestCase {
public static class IntegerVal {
private int v;
public void setV(int v) {
this.v = v;
}
Reported by PMD.
Line: 25
}
public static class FloatVal {
private float v;
public void setV(float v) {
this.v = v;
}
Reported by PMD.
Line: 37
}
}
public void test_for_issue_int() {
Map<String, Long> intOverflowMap = new HashMap<String, Long>();
long intOverflow = Integer.MAX_VALUE;
intOverflowMap.put("v", intOverflow + 1);
String sIntOverflow = JSON.toJSONString(intOverflowMap);
Reported by PMD.
Line: 46
Exception error = null;
try {
JSON.parseObject(sIntOverflow, IntegerVal.class);
} catch (Exception e) {
error = e;
}
assertNotNull(error);
}
Reported by PMD.
Line: 49
} catch (Exception e) {
error = e;
}
assertNotNull(error);
}
public void test_for_issue_float() {
Map<String, Double> floatOverflowMap = new HashMap<String, Double>();
double floatOverflow = Float.MAX_VALUE;
Reported by PMD.
Line: 52
assertNotNull(error);
}
public void test_for_issue_float() {
Map<String, Double> floatOverflowMap = new HashMap<String, Double>();
double floatOverflow = Float.MAX_VALUE;
floatOverflowMap.put("v", floatOverflow + 1);
String sFloatOverflow = JSON.toJSONString(floatOverflowMap);
Reported by PMD.
Line: 52
assertNotNull(error);
}
public void test_for_issue_float() {
Map<String, Double> floatOverflowMap = new HashMap<String, Double>();
double floatOverflow = Float.MAX_VALUE;
floatOverflowMap.put("v", floatOverflow + 1);
String sFloatOverflow = JSON.toJSONString(floatOverflowMap);
Reported by PMD.
Line: 58
floatOverflowMap.put("v", floatOverflow + 1);
String sFloatOverflow = JSON.toJSONString(floatOverflowMap);
assertEquals("{\"v\":3.4028234663852886E38}", sFloatOverflow);
FloatVal floatVal = JSON.parseObject(sFloatOverflow, FloatVal.class);
assertEquals(3.4028235E38F, floatVal.v);
assertEquals(floatVal.v, Float.parseFloat("3.4028234663852886E38"));
}
Reported by PMD.
Line: 60
assertEquals("{\"v\":3.4028234663852886E38}", sFloatOverflow);
FloatVal floatVal = JSON.parseObject(sFloatOverflow, FloatVal.class);
assertEquals(3.4028235E38F, floatVal.v);
assertEquals(floatVal.v, Float.parseFloat("3.4028234663852886E38"));
}
public void test_for_issue_float_infinity() {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/mixins/MixinSerForMethodsTest.java
16 issues
Line: 13
@SuppressWarnings( "unused" )
static class BaseClass {
private String a;
private String b;
protected BaseClass() {
}
Reported by PMD.
Line: 14
@SuppressWarnings( "unused" )
static class BaseClass {
private String a;
private String b;
protected BaseClass() {
}
public BaseClass( String a,String b ) {
Reported by PMD.
Line: 31
}
static class BaseClass2 {
private String a;
private String b;
protected BaseClass2() {
}
Reported by PMD.
Line: 32
static class BaseClass2 {
private String a;
private String b;
protected BaseClass2() {
}
public BaseClass2( String a,String b ) {
Reported by PMD.
Line: 62
abstract String takeA();
}
public void test() throws Exception{
BaseClass bean = new BaseClass( "a1", "b2" );
String jsonString = JSON.toJSONString( bean );
JSONObject result = JSON.parseObject( jsonString );
assertEquals( 1, result.size() );
Reported by PMD.
Line: 62
abstract String takeA();
}
public void test() throws Exception{
BaseClass bean = new BaseClass( "a1", "b2" );
String jsonString = JSON.toJSONString( bean );
JSONObject result = JSON.parseObject( jsonString );
assertEquals( 1, result.size() );
Reported by PMD.
Line: 67
String jsonString = JSON.toJSONString( bean );
JSONObject result = JSON.parseObject( jsonString );
assertEquals( 1, result.size() );
assertEquals( "b2", result.get( "b" ) );
BaseClass2 bean2 = new BaseClass2( "a1", "b2" );
JSON.addMixInAnnotations( BaseClass2.class, MixIn.class );
jsonString = JSON.toJSONString( bean2 );
Reported by PMD.
Line: 67
String jsonString = JSON.toJSONString( bean );
JSONObject result = JSON.parseObject( jsonString );
assertEquals( 1, result.size() );
assertEquals( "b2", result.get( "b" ) );
BaseClass2 bean2 = new BaseClass2( "a1", "b2" );
JSON.addMixInAnnotations( BaseClass2.class, MixIn.class );
jsonString = JSON.toJSONString( bean2 );
Reported by PMD.
Line: 68
String jsonString = JSON.toJSONString( bean );
JSONObject result = JSON.parseObject( jsonString );
assertEquals( 1, result.size() );
assertEquals( "b2", result.get( "b" ) );
BaseClass2 bean2 = new BaseClass2( "a1", "b2" );
JSON.addMixInAnnotations( BaseClass2.class, MixIn.class );
jsonString = JSON.toJSONString( bean2 );
result = JSON.parseObject( jsonString );
Reported by PMD.
Line: 68
String jsonString = JSON.toJSONString( bean );
JSONObject result = JSON.parseObject( jsonString );
assertEquals( 1, result.size() );
assertEquals( "b2", result.get( "b" ) );
BaseClass2 bean2 = new BaseClass2( "a1", "b2" );
JSON.addMixInAnnotations( BaseClass2.class, MixIn.class );
jsonString = JSON.toJSONString( bean2 );
result = JSON.parseObject( jsonString );
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_2600/Issue2628.java
16 issues
Line: 9
import java.math.BigInteger;
public class Issue2628 extends TestCase {
public void test_for_issue() throws Exception {
long MAX_LONG = Long.MAX_VALUE; //9223372036854775807
long MIN_LONG = Long.MIN_VALUE; //-9223372036854775808
String s1 = "9423372036854775807"; //-9423372036854775808
BigInteger bi1 = JSON.parseObject(s1, BigInteger.class); //没问题
Reported by PMD.
Line: 9
import java.math.BigInteger;
public class Issue2628 extends TestCase {
public void test_for_issue() throws Exception {
long MAX_LONG = Long.MAX_VALUE; //9223372036854775807
long MIN_LONG = Long.MIN_VALUE; //-9223372036854775808
String s1 = "9423372036854775807"; //-9423372036854775808
BigInteger bi1 = JSON.parseObject(s1, BigInteger.class); //没问题
Reported by PMD.
Line: 10
public class Issue2628 extends TestCase {
public void test_for_issue() throws Exception {
long MAX_LONG = Long.MAX_VALUE; //9223372036854775807
long MIN_LONG = Long.MIN_VALUE; //-9223372036854775808
String s1 = "9423372036854775807"; //-9423372036854775808
BigInteger bi1 = JSON.parseObject(s1, BigInteger.class); //没问题
assertEquals("9423372036854775807", bi1.toString());
Reported by PMD.
Line: 11
public class Issue2628 extends TestCase {
public void test_for_issue() throws Exception {
long MAX_LONG = Long.MAX_VALUE; //9223372036854775807
long MIN_LONG = Long.MIN_VALUE; //-9223372036854775808
String s1 = "9423372036854775807"; //-9423372036854775808
BigInteger bi1 = JSON.parseObject(s1, BigInteger.class); //没问题
assertEquals("9423372036854775807", bi1.toString());
Reported by PMD.
Line: 13
long MAX_LONG = Long.MAX_VALUE; //9223372036854775807
long MIN_LONG = Long.MIN_VALUE; //-9223372036854775808
String s1 = "9423372036854775807"; //-9423372036854775808
BigInteger bi1 = JSON.parseObject(s1, BigInteger.class); //没问题
assertEquals("9423372036854775807", bi1.toString());
BigInteger bi2 = new BigInteger(s1); //没问题
assertEquals("9423372036854775807", bi2.toString());
Reported by PMD.
Line: 15
String s1 = "9423372036854775807"; //-9423372036854775808
BigInteger bi1 = JSON.parseObject(s1, BigInteger.class); //没问题
assertEquals("9423372036854775807", bi1.toString());
BigInteger bi2 = new BigInteger(s1); //没问题
assertEquals("9423372036854775807", bi2.toString());
Tobject tobj1 = new Tobject();
Reported by PMD.
Line: 15
String s1 = "9423372036854775807"; //-9423372036854775808
BigInteger bi1 = JSON.parseObject(s1, BigInteger.class); //没问题
assertEquals("9423372036854775807", bi1.toString());
BigInteger bi2 = new BigInteger(s1); //没问题
assertEquals("9423372036854775807", bi2.toString());
Tobject tobj1 = new Tobject();
Reported by PMD.
Line: 18
assertEquals("9423372036854775807", bi1.toString());
BigInteger bi2 = new BigInteger(s1); //没问题
assertEquals("9423372036854775807", bi2.toString());
Tobject tobj1 = new Tobject();
tobj1.setBi(bi2); //没问题
assertEquals("9423372036854775807", tobj1.getBi().toString());;
Reported by PMD.
Line: 22
Tobject tobj1 = new Tobject();
tobj1.setBi(bi2); //没问题
assertEquals("9423372036854775807", tobj1.getBi().toString());;
String s2 = JSON.toJSONString(tobj1);
Tobject tobj2 = JSON.parseObject(s2, Tobject.class); //有问题
assertEquals("9423372036854775807", tobj2.getBi().toString());
}
Reported by PMD.
Line: 22
Tobject tobj1 = new Tobject();
tobj1.setBi(bi2); //没问题
assertEquals("9423372036854775807", tobj1.getBi().toString());;
String s2 = JSON.toJSONString(tobj1);
Tobject tobj2 = JSON.parseObject(s2, Tobject.class); //有问题
assertEquals("9423372036854775807", tobj2.getBi().toString());
}
Reported by PMD.