The following issues were found
src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_ident.java
5 issues
Line: 11
public class JSONScannerTest_ident extends TestCase {
public void test_true() throws Exception {
JSONScanner lexer = new JSONScanner("true");
lexer.scanIdent();
Assert.assertEquals(JSONToken.TRUE, lexer.token());
}
Reported by PMD.
Line: 17
Assert.assertEquals(JSONToken.TRUE, lexer.token());
}
public void test_false() throws Exception {
JSONScanner lexer = new JSONScanner("false");
lexer.scanIdent();
Assert.assertEquals(JSONToken.FALSE, lexer.token());
}
Reported by PMD.
Line: 23
Assert.assertEquals(JSONToken.FALSE, lexer.token());
}
public void test_null() throws Exception {
JSONScanner lexer = new JSONScanner("null");
lexer.scanIdent();
Assert.assertEquals(JSONToken.NULL, lexer.token());
}
Reported by PMD.
Line: 29
Assert.assertEquals(JSONToken.NULL, lexer.token());
}
public void test_new() throws Exception {
JSONScanner lexer = new JSONScanner("new");
lexer.scanIdent();
Assert.assertEquals(JSONToken.NEW, lexer.token());
}
Reported by PMD.
Line: 35
Assert.assertEquals(JSONToken.NEW, lexer.token());
}
public void test_Date() throws Exception {
String text = "Date";
JSONScanner lexer = new JSONScanner(text);
lexer.scanIdent();
Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
Assert.assertEquals(text, lexer.stringVal());
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_2300/Issue2351.java
5 issues
Line: 13
import java.util.List;
public class Issue2351 extends TestCase {
public void test_for_issue() throws Exception {
// ParserConfig.getGlobalInstance().setAsmEnable(false);
// 创建空白对象
Bean1 c = new Bean1();
c.a = "";
Reported by PMD.
Line: 22
// 序列化
// 输出[null,null]
String s = JSON.toJSONString(c, SerializerFeature.BeanToArray);
assertEquals("[\"\",null]", s);
// 反序列化报错
// Exception in thread "main" com.alibaba.fastjson.JSONException: syntax error, expect [, actual [
JSON.parseObject(s, Bean1.class, Feature.SupportArrayToBean);
}
Reported by PMD.
Line: 31
public static class Bean1 {
public String a;
public List<Bean2> b;
}
public static class Bean2 {
Reported by PMD.
Line: 5
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.List;
Reported by PMD.
Line: 9
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.List;
public class Issue2351 extends TestCase {
public void test_for_issue() throws Exception {
// ParserConfig.getGlobalInstance().setAsmEnable(false);
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1500/Issue1588.java
5 issues
Line: 16
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
JSONObject jsonObject = new JSONObject();
jsonObject.put("test", date);
System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
System.out.println(JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd'T'HH:mm:ssXXX"));
}
}
Reported by PMD.
Line: 17
JSONObject jsonObject = new JSONObject();
jsonObject.put("test", date);
System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
System.out.println(JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd'T'HH:mm:ssXXX"));
}
}
Reported by PMD.
Line: 11
import java.util.Date;
public class Issue1588 extends TestCase {
public void test_for_issue() throws Exception {
String dateString = "2017-11-17 00:00:00";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
JSONObject jsonObject = new JSONObject();
jsonObject.put("test", date);
System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
Reported by PMD.
Line: 11
import java.util.Date;
public class Issue1588 extends TestCase {
public void test_for_issue() throws Exception {
String dateString = "2017-11-17 00:00:00";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
JSONObject jsonObject = new JSONObject();
jsonObject.put("test", date);
System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
Reported by PMD.
Line: 13
public class Issue1588 extends TestCase {
public void test_for_issue() throws Exception {
String dateString = "2017-11-17 00:00:00";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
JSONObject jsonObject = new JSONObject();
jsonObject.put("test", date);
System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
System.out.println(JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd'T'HH:mm:ssXXX"));
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1500/Issue1583.java
5 issues
Line: 26
List<Map.Entry<String, List<String>>> mapList = new ArrayList<Map.Entry<String, List<String>>>(totalMap.entrySet());
String jsonString = JSON.toJSONString(mapList, SerializerFeature.DisableCircularReferenceDetect);
System.out.println(jsonString);
List<Map.Entry<String, List<String>>> parse = JSON.parseObject(jsonString, new TypeReference<List<Map.Entry<String, List<String>>>>() {});
System.out.println(parse);
}
}
Reported by PMD.
Line: 28
System.out.println(jsonString);
List<Map.Entry<String, List<String>>> parse = JSON.parseObject(jsonString, new TypeReference<List<Map.Entry<String, List<String>>>>() {});
System.out.println(parse);
}
}
Reported by PMD.
Line: 14
import java.util.Map;
public class Issue1583 extends TestCase {
public void test_issue() throws Exception {
Map<String, List<String>> totalMap = new HashMap<String, List<String>>();
for (int i = 0; i < 10; i++) {
List<String> list = new ArrayList<String>();
for (int j = 0; j < 2; j++) {
list.add("list" + j);
Reported by PMD.
Line: 14
import java.util.Map;
public class Issue1583 extends TestCase {
public void test_issue() throws Exception {
Map<String, List<String>> totalMap = new HashMap<String, List<String>>();
for (int i = 0; i < 10; i++) {
List<String> list = new ArrayList<String>();
for (int j = 0; j < 2; j++) {
list.add("list" + j);
Reported by PMD.
Line: 17
public void test_issue() throws Exception {
Map<String, List<String>> totalMap = new HashMap<String, List<String>>();
for (int i = 0; i < 10; i++) {
List<String> list = new ArrayList<String>();
for (int j = 0; j < 2; j++) {
list.add("list" + j);
}
totalMap.put("map" + i, list);
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/lombok/LomBokTest.java
5 issues
Line: 30
ParserConfig.getGlobalInstance().addAccept("com.alibaba.json.bvt.lombok.LomBokTest.DaysCycleExeDecision");
JSONObject obj = JSON.parseObject(str);
IndicatorCycleRule cycleRule = obj.getObject("cycleRule", IndicatorCycleRule.class);
System.out.println(((DaysCycleExeDecision) cycleRule.decision).days);
}
@lombok.Data
public static class DaysCycleExeDecision implements ExeDecision {
private int days;
Reported by PMD.
Line: 9
import junit.framework.TestCase;
public class LomBokTest extends TestCase {
public void test_for_issue() throws Exception {
String str = "{\n" +
"\t\"target\": 1,\n" +
"\t\"current\": 0,\n" +
"\t\"step\": 1,\n" +
"\t\"uqcRule\": {\n" +
Reported by PMD.
Line: 9
import junit.framework.TestCase;
public class LomBokTest extends TestCase {
public void test_for_issue() throws Exception {
String str = "{\n" +
"\t\"target\": 1,\n" +
"\t\"current\": 0,\n" +
"\t\"step\": 1,\n" +
"\t\"uqcRule\": {\n" +
Reported by PMD.
Line: 27
"\t\t}\n" +
"\t}\n" +
"}";
ParserConfig.getGlobalInstance().addAccept("com.alibaba.json.bvt.lombok.LomBokTest.DaysCycleExeDecision");
JSONObject obj = JSON.parseObject(str);
IndicatorCycleRule cycleRule = obj.getObject("cycleRule", IndicatorCycleRule.class);
System.out.println(((DaysCycleExeDecision) cycleRule.decision).days);
}
Reported by PMD.
Line: 29
"}";
ParserConfig.getGlobalInstance().addAccept("com.alibaba.json.bvt.lombok.LomBokTest.DaysCycleExeDecision");
JSONObject obj = JSON.parseObject(str);
IndicatorCycleRule cycleRule = obj.getObject("cycleRule", IndicatorCycleRule.class);
System.out.println(((DaysCycleExeDecision) cycleRule.decision).days);
}
@lombok.Data
public static class DaysCycleExeDecision implements ExeDecision {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_3300/Issue3347.java
5 issues
Line: 15
* @Date :Created in 22:29 2020/7/15
*/
public class Issue3347 extends TestCase {
public void test_for_issue() throws Exception {
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(1, "hello");
String mapJSONString = JSON.toJSONString(map);
Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
Object mapKey = mapValues.keySet().iterator().next();
Reported by PMD.
Line: 20
map.put(1, "hello");
String mapJSONString = JSON.toJSONString(map);
Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
Object mapKey = mapValues.keySet().iterator().next();
assertTrue(mapKey instanceof Integer);
}
}
Reported by PMD.
Line: 20
map.put(1, "hello");
String mapJSONString = JSON.toJSONString(map);
Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
Object mapKey = mapValues.keySet().iterator().next();
assertTrue(mapKey instanceof Integer);
}
}
Reported by PMD.
Line: 20
map.put(1, "hello");
String mapJSONString = JSON.toJSONString(map);
Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
Object mapKey = mapValues.keySet().iterator().next();
assertTrue(mapKey instanceof Integer);
}
}
Reported by PMD.
Line: 21
String mapJSONString = JSON.toJSONString(map);
Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
Object mapKey = mapValues.keySet().iterator().next();
assertTrue(mapKey instanceof Integer);
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/JSONLexerTest_11.java
5 issues
Line: 43
public static class MyList<T> extends ArrayList<T> {
public MyList() {
throw new RuntimeException();
}
}
}
Reported by PMD.
Line: 13
public class JSONLexerTest_11 extends TestCase {
public void test_a() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"type\":[\"AAA\"]}", VO.class);
} catch (Exception ex) {
error = ex;
Reported by PMD.
Line: 17
Exception error = null;
try {
JSON.parseObject("{\"type\":[\"AAA\"]}", VO.class);
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
Reported by PMD.
Line: 41
}
public static class MyList<T> extends ArrayList<T> {
public MyList() {
throw new RuntimeException();
}
}
}
Reported by PMD.
Line: 14
public class JSONLexerTest_11 extends TestCase {
public void test_a() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"type\":[\"AAA\"]}", VO.class);
} catch (Exception ex) {
error = ex;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/date/DateTest.java
5 issues
Line: 15
import com.alibaba.fastjson.serializer.SerializerFeature;
public class DateTest extends TestCase {
protected void setUp() throws Exception {
JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
JSON.defaultLocale = Locale.CHINA;
}
public void test_date() throws Exception {
Reported by PMD.
Line: 20
JSON.defaultLocale = Locale.CHINA;
}
public void test_date() throws Exception {
long millis = 1324138987429L;
Date date = new Date(millis);
Assert.assertEquals("1324138987429", JSON.toJSONString(date));
Assert.assertEquals("new Date(1324138987429)", JSON.toJSONString(date, SerializerFeature.WriteClassName));
Reported by PMD.
Line: 36
SerializerFeature.UseSingleQuotes));
}
public void test_parse() throws Exception {
Date date = JSON.parseObject("\"2018-10-12 09:48:22 +0800\"", Date.class);
assertEquals(1539308902000L, date.getTime());
}
}
Reported by PMD.
Line: 38
public void test_parse() throws Exception {
Date date = JSON.parseObject("\"2018-10-12 09:48:22 +0800\"", Date.class);
assertEquals(1539308902000L, date.getTime());
}
}
Reported by PMD.
Line: 38
public void test_parse() throws Exception {
Date date = JSON.parseObject("\"2018-10-12 09:48:22 +0800\"", Date.class);
assertEquals(1539308902000L, date.getTime());
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/joda/JodaTest_7_DateTimeZone.java
5 issues
Line: 8
import org.joda.time.DateTimeZone;
public class JodaTest_7_DateTimeZone extends TestCase {
public void test_for_joda_0() throws Exception {
Model m = new Model();
m.zone = DateTimeZone.forID("Asia/Shanghai");
String json = JSON.toJSONString(m);
Reported by PMD.
Line: 8
import org.joda.time.DateTimeZone;
public class JodaTest_7_DateTimeZone extends TestCase {
public void test_for_joda_0() throws Exception {
Model m = new Model();
m.zone = DateTimeZone.forID("Asia/Shanghai");
String json = JSON.toJSONString(m);
Reported by PMD.
Line: 15
String json = JSON.toJSONString(m);
assertEquals("{\"zone\":\"Asia/Shanghai\"}", json);
Model m1 = JSON.parseObject(json, Model.class);
assertEquals(m.zone, m1.zone);
}
Reported by PMD.
Line: 18
assertEquals("{\"zone\":\"Asia/Shanghai\"}", json);
Model m1 = JSON.parseObject(json, Model.class);
assertEquals(m.zone, m1.zone);
}
public static class Model {
public DateTimeZone zone;
}
Reported by PMD.
Line: 22
}
public static class Model {
public DateTimeZone zone;
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1200/Issue1205.java
5 issues
Line: 14
* Created by wenshao on 11/06/2017.
*/
public class Issue1205 extends TestCase {
public void test_for_issue() throws Exception {
JSONArray array = new JSONArray();
array.add(new JSONObject());
List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
assertEquals(1, list.size());
Reported by PMD.
Line: 14
* Created by wenshao on 11/06/2017.
*/
public class Issue1205 extends TestCase {
public void test_for_issue() throws Exception {
JSONArray array = new JSONArray();
array.add(new JSONObject());
List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
assertEquals(1, list.size());
Reported by PMD.
Line: 19
array.add(new JSONObject());
List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
assertEquals(1, list.size());
assertEquals(Model.class, list.get(0).getClass());
}
public static class Model {
Reported by PMD.
Line: 20
List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
assertEquals(1, list.size());
assertEquals(Model.class, list.get(0).getClass());
}
public static class Model {
}
Reported by PMD.
Line: 20
List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
assertEquals(1, list.size());
assertEquals(Model.class, list.get(0).getClass());
}
public static class Model {
}
Reported by PMD.