The following issues were found
src/test/java/com/alibaba/json/bvt/issue_1600/Issue1660.java
5 issues
Line: 10
import java.util.*;
public class Issue1660 extends TestCase {
protected void setUp() throws Exception {
JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
JSON.defaultLocale = Locale.CHINA;
}
public void test_for_issue() throws Exception {
Reported by PMD.
Line: 15
JSON.defaultLocale = Locale.CHINA;
}
public void test_for_issue() throws Exception {
Model model = new Model();
model.values.add(new Date(1513755213202L));
String json = JSON.toJSONString(model);
assertEquals("{\"values\":[\"2017-12-20\"]}", json);
Reported by PMD.
Line: 20
model.values.add(new Date(1513755213202L));
String json = JSON.toJSONString(model);
assertEquals("{\"values\":[\"2017-12-20\"]}", json);
}
public static class Model {
@JSONField(format = "yyyy-MM-dd")
private List<Date> values = new ArrayList<Date>();
Reported by PMD.
Line: 25
public static class Model {
@JSONField(format = "yyyy-MM-dd")
private List<Date> values = new ArrayList<Date>();
public List<Date> getValues() {
return values;
}
}
Reported by PMD.
Line: 25
public static class Model {
@JSONField(format = "yyyy-MM-dd")
private List<Date> values = new ArrayList<Date>();
public List<Date> getValues() {
return values;
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_2100/Issue2150.java
5 issues
Line: 7
import junit.framework.TestCase;
public class Issue2150 extends TestCase {
public void test_for_issue() throws Exception {
int [][][] arr = new int[100][100][100];
JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
assertNotNull(jsonObj);
assertNotNull(jsonObj.getJSONArray(0));
}
Reported by PMD.
Line: 7
import junit.framework.TestCase;
public class Issue2150 extends TestCase {
public void test_for_issue() throws Exception {
int [][][] arr = new int[100][100][100];
JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
assertNotNull(jsonObj);
assertNotNull(jsonObj.getJSONArray(0));
}
Reported by PMD.
Line: 10
public void test_for_issue() throws Exception {
int [][][] arr = new int[100][100][100];
JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
assertNotNull(jsonObj);
assertNotNull(jsonObj.getJSONArray(0));
}
}
Reported by PMD.
Line: 11
int [][][] arr = new int[100][100][100];
JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
assertNotNull(jsonObj);
assertNotNull(jsonObj.getJSONArray(0));
}
}
Reported by PMD.
Line: 11
int [][][] arr = new int[100][100][100];
JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
assertNotNull(jsonObj);
assertNotNull(jsonObj.getJSONArray(0));
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/jdk8/LocalTimeTest2.java
5 issues
Line: 13
public class LocalTimeTest2 extends TestCase {
public void test_for_issue() throws Exception {
VO vo1 = JSON.parseObject("{\"date\":\"20:30:55\"}", VO.class);
Assert.assertEquals(20, vo1.date.getHour());
Assert.assertEquals(30, vo1.date.getMinute());
Assert.assertEquals(55, vo1.date.getSecond());
Reported by PMD.
Line: 16
public void test_for_issue() throws Exception {
VO vo1 = JSON.parseObject("{\"date\":\"20:30:55\"}", VO.class);
Assert.assertEquals(20, vo1.date.getHour());
Assert.assertEquals(30, vo1.date.getMinute());
Assert.assertEquals(55, vo1.date.getSecond());
}
public static class VO {
Reported by PMD.
Line: 17
VO vo1 = JSON.parseObject("{\"date\":\"20:30:55\"}", VO.class);
Assert.assertEquals(20, vo1.date.getHour());
Assert.assertEquals(30, vo1.date.getMinute());
Assert.assertEquals(55, vo1.date.getSecond());
}
public static class VO {
Reported by PMD.
Line: 18
Assert.assertEquals(20, vo1.date.getHour());
Assert.assertEquals(30, vo1.date.getMinute());
Assert.assertEquals(55, vo1.date.getSecond());
}
public static class VO {
public LocalTime date;
Reported by PMD.
Line: 23
public static class VO {
public LocalTime date;
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1600/Issue1662.java
5 issues
Line: 18
import java.lang.reflect.Type;
public class Issue1662 extends TestCase {
public void test_for_issue() throws Exception {
ParserConfig.getGlobalInstance().putDeserializer(Model.class, new ModelValueDeserializer());
String json = "{\"value\":123}";
Model model = JSON.parseObject(json, Model.class);
assertEquals("{\"value\":\"12300元\"}",JSON.toJSONString(model));
Reported by PMD.
Line: 23
ParserConfig.getGlobalInstance().putDeserializer(Model.class, new ModelValueDeserializer());
String json = "{\"value\":123}";
Model model = JSON.parseObject(json, Model.class);
assertEquals("{\"value\":\"12300元\"}",JSON.toJSONString(model));
}
public static class Model {
@JSONField(serializeUsing = ModelValueSerializer.class, deserializeUsing = ModelValueDeserializer.class)
Reported by PMD.
Line: 29
public static class Model {
@JSONField(serializeUsing = ModelValueSerializer.class, deserializeUsing = ModelValueDeserializer.class)
public int value;
}
public static class ModelValueSerializer implements ObjectSerializer {
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
int features) throws IOException {
Reported by PMD.
Line: 46
public Model deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONObject obj = (JSONObject)parser.parse();
Model model = new Model();
model.value = obj.getInteger("value") * 100;
return model;
}
public int getFastMatchToken() {
return 0;
Reported by PMD.
Line: 4
package com.alibaba.json.bvt.issue_1600;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_2000/Issue2012.java
5 issues
Line: 9
import junit.framework.TestCase;
public class Issue2012 extends TestCase {
public void test_for_issue() throws Exception {
Model foo = new Model();
foo.bytes = new byte[0];
String str = JSON.toJSONString(foo, SerializerFeature.WriteClassName);
assertEquals("{\"@type\":\"com.alibaba.json.bvt.issue_2000.Issue2012$Model\",\"bytes\":x''}", str);
Reported by PMD.
Line: 9
import junit.framework.TestCase;
public class Issue2012 extends TestCase {
public void test_for_issue() throws Exception {
Model foo = new Model();
foo.bytes = new byte[0];
String str = JSON.toJSONString(foo, SerializerFeature.WriteClassName);
assertEquals("{\"@type\":\"com.alibaba.json.bvt.issue_2000.Issue2012$Model\",\"bytes\":x''}", str);
Reported by PMD.
Line: 13
Model foo = new Model();
foo.bytes = new byte[0];
String str = JSON.toJSONString(foo, SerializerFeature.WriteClassName);
assertEquals("{\"@type\":\"com.alibaba.json.bvt.issue_2000.Issue2012$Model\",\"bytes\":x''}", str);
ParserConfig config = new ParserConfig();
config.setAutoTypeSupport(true);
foo = JSON.parseObject(str, Object.class,config);
assertEquals(0, foo.bytes.length);
Reported by PMD.
Line: 18
ParserConfig config = new ParserConfig();
config.setAutoTypeSupport(true);
foo = JSON.parseObject(str, Object.class,config);
assertEquals(0, foo.bytes.length);
}
public static class Model {
public byte[] bytes;
}
Reported by PMD.
Line: 22
}
public static class Model {
public byte[] bytes;
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/JSONReaderScannerTest__entity_string.java
5 issues
Line: 16
public class JSONReaderScannerTest__entity_string extends TestCase {
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 10; ++i) {
if (i != 0) {
buf.append(',');
Reported by PMD.
Line: 25
}
//1000000000000
//
buf.append("{\"id\":\"" + i + "\"}");
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
Reported by PMD.
Line: 30
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
List<VO> array = parser.parseArray(VO.class);
Reported by PMD.
Line: 37
DefaultJSONParser parser = new DefaultJSONParser(scanner);
List<VO> array = parser.parseArray(VO.class);
for (int i = 0; i < array.size(); ++i) {
Assert.assertEquals(Integer.toString(i), array.get(i).getId());
}
}
public static class VO {
Reported by PMD.
Line: 10
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONReaderScanner;
public class JSONReaderScannerTest__entity_string extends TestCase {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/TestInitStringFieldAsEmpty2.java
5 issues
Line: 11
public class TestInitStringFieldAsEmpty2 extends TestCase {
public void test_public() throws Exception {
VO1 vo1 = JSON.parseObject("{\"id\":0,\"value\":33, \"o\":{}}", VO1.class, Feature.InitStringFieldAsEmpty);
Assert.assertEquals("", vo1.getName());
Assert.assertEquals("", vo1.getO().getValue());
}
Reported by PMD.
Line: 13
public void test_public() throws Exception {
VO1 vo1 = JSON.parseObject("{\"id\":0,\"value\":33, \"o\":{}}", VO1.class, Feature.InitStringFieldAsEmpty);
Assert.assertEquals("", vo1.getName());
Assert.assertEquals("", vo1.getO().getValue());
}
public static class VO1 {
Reported by PMD.
Line: 14
public void test_public() throws Exception {
VO1 vo1 = JSON.parseObject("{\"id\":0,\"value\":33, \"o\":{}}", VO1.class, Feature.InitStringFieldAsEmpty);
Assert.assertEquals("", vo1.getName());
Assert.assertEquals("", vo1.getO().getValue());
}
public static class VO1 {
private int id;
Reported by PMD.
Line: 14
public void test_public() throws Exception {
VO1 vo1 = JSON.parseObject("{\"id\":0,\"value\":33, \"o\":{}}", VO1.class, Feature.InitStringFieldAsEmpty);
Assert.assertEquals("", vo1.getName());
Assert.assertEquals("", vo1.getO().getValue());
}
public static class VO1 {
private int id;
Reported by PMD.
Line: 17
Assert.assertEquals("", vo1.getO().getValue());
}
public static class VO1 {
private int id;
private String name;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/TestException.java
5 issues
Line: 28
}
public void f() {
throw new RuntimeException();
}
}
Reported by PMD.
Line: 11
public class TestException extends TestCase {
public void test_0() throws Exception {
Exception error = null;
try {
f();
} catch (Exception ex) {
Reported by PMD.
Line: 11
public class TestException extends TestCase {
public void test_0() throws Exception {
Exception error = null;
try {
f();
} catch (Exception ex) {
Reported by PMD.
Line: 16
try {
f();
} catch (Exception ex) {
error = ex;
}
String text = JSON.toJSONString(new Exception[] { error });
Reported by PMD.
Line: 12
public class TestException extends TestCase {
public void test_0() throws Exception {
Exception error = null;
try {
f();
} catch (Exception ex) {
error = ex;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/JSONReaderScannerTest__entity_long.java
5 issues
Line: 16
public class JSONReaderScannerTest__entity_long extends TestCase {
public void test_scanInt() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < 10; ++i) {
if (i != 0) {
buf.append(',');
Reported by PMD.
Line: 26
//1000000000000
//
long value = (long) 1000000000000L + 1L + (long) i;
buf.append("{\"id\":" + value + "}");
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
Reported by PMD.
Line: 30
}
buf.append(']');
Reader reader = new StringReader(buf.toString());
JSONReaderScanner scanner = new JSONReaderScanner(reader);
DefaultJSONParser parser = new DefaultJSONParser(scanner);
List<VO> array = parser.parseArray(VO.class);
Reported by PMD.
Line: 38
List<VO> array = parser.parseArray(VO.class);
for (int i = 0; i < array.size(); ++i) {
long value = (long) 1000000000000L + 1L + (long) i;
Assert.assertEquals(value, array.get(i).getId());
}
}
public static class VO {
Reported by PMD.
Line: 10
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONReaderScanner;
public class JSONReaderScannerTest__entity_long extends TestCase {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/SafeModeTest.java
5 issues
Line: 11
import junit.framework.TestCase;
public class SafeModeTest extends TestCase {
public void test_for_safeMode() throws Exception {
ParserConfig config = new ParserConfig();
String str = "{\"@type\":\"com.alibaba.json.bvt.parser.SafeModeTest$Entity\"}";
JSON.parse(str);
Reported by PMD.
Line: 11
import junit.framework.TestCase;
public class SafeModeTest extends TestCase {
public void test_for_safeMode() throws Exception {
ParserConfig config = new ParserConfig();
String str = "{\"@type\":\"com.alibaba.json.bvt.parser.SafeModeTest$Entity\"}";
JSON.parse(str);
Reported by PMD.
Line: 25
catch (JSONException ex) {
error = ex;
}
assertNotNull(error);
}
{
Exception error = null;
try {
Reported by PMD.
Line: 37
catch (JSONException ex) {
error = ex;
}
assertNotNull(error);
}
}
@JSONType
public static class Entity {
Reported by PMD.
Line: 18
JSON.parse(str);
{
Exception error = null;
try {
JSON.parse(str, config, Feature.SafeMode);
}
catch (JSONException ex) {
error = ex;
Reported by PMD.