The following issues were found
src/test/java/com/alibaba/json/bvt/kotlin/DataClassSimpleTest.java
6 issues
Line: 24
Class clazz = classLoader.loadClass("DataClassSimple");
String[] names = ASMUtils.lookupParameterNames(clazz.getConstructors()[0]);
System.out.println(JSON.toJSONString(names));
String json = "{\"a\":1001,\"b\":1002}";
Object obj = JSON.parseObject(json, clazz);
assertEquals("{\"a\":1001,\"b\":1002}", JSON.toJSONString(obj));
Reported by PMD.
Line: 19
*/
public class DataClassSimpleTest extends TestCase {
public void test_user() throws Exception {
ExtClassLoader classLoader = new ExtClassLoader();
Class clazz = classLoader.loadClass("DataClassSimple");
String[] names = ASMUtils.lookupParameterNames(clazz.getConstructors()[0]);
System.out.println(JSON.toJSONString(names));
Reported by PMD.
Line: 23
ExtClassLoader classLoader = new ExtClassLoader();
Class clazz = classLoader.loadClass("DataClassSimple");
String[] names = ASMUtils.lookupParameterNames(clazz.getConstructors()[0]);
System.out.println(JSON.toJSONString(names));
String json = "{\"a\":1001,\"b\":1002}";
Object obj = JSON.parseObject(json, clazz);
assertEquals("{\"a\":1001,\"b\":1002}", JSON.toJSONString(obj));
Reported by PMD.
Line: 28
String json = "{\"a\":1001,\"b\":1002}";
Object obj = JSON.parseObject(json, clazz);
assertEquals("{\"a\":1001,\"b\":1002}", JSON.toJSONString(obj));
}
public static class ExtClassLoader extends ClassLoader {
Map<String, byte[]> resources = new HashMap<String, byte[]>();
Reported by PMD.
Line: 33
}
public static class ExtClassLoader extends ClassLoader {
Map<String, byte[]> resources = new HashMap<String, byte[]>();
public ExtClassLoader() throws IOException {
super(Thread.currentThread().getContextClassLoader());
{
Reported by PMD.
Line: 40
{
byte[] bytes;
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/DataClassSimple.clazz");
bytes = IOUtils.toByteArray(is);
is.close();
resources.put("DataClassSimple.class", bytes);
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/TypeUtilsToJSONTest.java
6 issues
Line: 17
@SuppressWarnings("rawtypes")
public class TypeUtilsToJSONTest extends TestCase {
public void test_0() throws Exception {
HashMap map = new HashMap();
JSONObject json = (JSONObject) JSON.toJSON(map);
Assert.assertEquals(map.size(), json.size());
Reported by PMD.
Line: 22
JSONObject json = (JSONObject) JSON.toJSON(map);
Assert.assertEquals(map.size(), json.size());
}
public void test_1() throws Exception {
List list = new ArrayList();
Reported by PMD.
Line: 25
Assert.assertEquals(map.size(), json.size());
}
public void test_1() throws Exception {
List list = new ArrayList();
JSONArray json = (JSONArray) JSON.toJSON(list);
Assert.assertEquals(list.size(), json.size());
Reported by PMD.
Line: 30
JSONArray json = (JSONArray) JSON.toJSON(list);
Assert.assertEquals(list.size(), json.size());
}
public void test_null() throws Exception {
Assert.assertEquals(null, JSON.toJSON(null));
}
Reported by PMD.
Line: 33
Assert.assertEquals(list.size(), json.size());
}
public void test_null() throws Exception {
Assert.assertEquals(null, JSON.toJSON(null));
}
public static class User {
Reported by PMD.
Line: 37
Assert.assertEquals(null, JSON.toJSON(null));
}
public static class User {
private long id;
private String name;
public long getId() {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/TypeUtilsTest_compatibleWithJavaBean_boolean.java
6 issues
Line: 12
public class TypeUtilsTest_compatibleWithJavaBean_boolean extends TestCase {
private boolean origin_compatibleWithJavaBean;
protected void setUp() throws Exception {
origin_compatibleWithJavaBean = TypeUtils.compatibleWithJavaBean;
TypeUtils.compatibleWithJavaBean = true;
}
Reported by PMD.
Line: 14
private boolean origin_compatibleWithJavaBean;
protected void setUp() throws Exception {
origin_compatibleWithJavaBean = TypeUtils.compatibleWithJavaBean;
TypeUtils.compatibleWithJavaBean = true;
}
protected void tearDown() throws Exception {
Reported by PMD.
Line: 19
TypeUtils.compatibleWithJavaBean = true;
}
protected void tearDown() throws Exception {
TypeUtils.compatibleWithJavaBean = origin_compatibleWithJavaBean;
}
public void test_true() throws Exception {
String text = JSON.toJSONString(new VO(true));
Reported by PMD.
Line: 23
TypeUtils.compatibleWithJavaBean = origin_compatibleWithJavaBean;
}
public void test_true() throws Exception {
String text = JSON.toJSONString(new VO(true));
Assert.assertEquals("{\"ID\":true}", text);
Assert.assertEquals(true, JSON.parseObject(text, VO.class).isID());
}
Reported by PMD.
Line: 26
public void test_true() throws Exception {
String text = JSON.toJSONString(new VO(true));
Assert.assertEquals("{\"ID\":true}", text);
Assert.assertEquals(true, JSON.parseObject(text, VO.class).isID());
}
public static class VO {
private boolean id;
Reported by PMD.
Line: 31
public static class VO {
private boolean id;
public VO(){
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/TypeUtilsTest_compatibleWithJavaBean.java
6 issues
Line: 12
public class TypeUtilsTest_compatibleWithJavaBean extends TestCase {
private boolean origin_compatibleWithJavaBean;
protected void setUp() throws Exception {
origin_compatibleWithJavaBean = TypeUtils.compatibleWithJavaBean;
TypeUtils.compatibleWithJavaBean = true;
}
Reported by PMD.
Line: 14
private boolean origin_compatibleWithJavaBean;
protected void setUp() throws Exception {
origin_compatibleWithJavaBean = TypeUtils.compatibleWithJavaBean;
TypeUtils.compatibleWithJavaBean = true;
}
protected void tearDown() throws Exception {
Reported by PMD.
Line: 19
TypeUtils.compatibleWithJavaBean = true;
}
protected void tearDown() throws Exception {
TypeUtils.compatibleWithJavaBean = origin_compatibleWithJavaBean;
}
public void test_true() throws Exception {
String text = JSON.toJSONString(new VO(123));
Reported by PMD.
Line: 23
TypeUtils.compatibleWithJavaBean = origin_compatibleWithJavaBean;
}
public void test_true() throws Exception {
String text = JSON.toJSONString(new VO(123));
Assert.assertEquals("{\"ID\":123}", text);
Assert.assertEquals(123, JSON.parseObject(text, VO.class).getID());
}
Reported by PMD.
Line: 26
public void test_true() throws Exception {
String text = JSON.toJSONString(new VO(123));
Assert.assertEquals("{\"ID\":123}", text);
Assert.assertEquals(123, JSON.parseObject(text, VO.class).getID());
}
public static class VO {
private int id;
Reported by PMD.
Line: 31
public static class VO {
private int id;
public VO(){
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/feature/WriteNullStringAsEmptyTest.java
6 issues
Line: 26
Model model = new Model();
String json = JSON.toJSONString(model, filter, SerializerFeature.WriteNullStringAsEmpty);
System.out.println(json);
}
private static class Model {
@JSONField(serialzeFeatures = SerializerFeature.WriteNullStringAsEmpty)
Reported by PMD.
Line: 13
* Created by wenshao on 14/03/2017.
*/
public class WriteNullStringAsEmptyTest extends TestCase {
public void test_features() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object object, String name, Object value) {
if (value == null && object instanceof Model && "id".equals(name)) {
return false;
Reported by PMD.
Line: 13
* Created by wenshao on 14/03/2017.
*/
public class WriteNullStringAsEmptyTest extends TestCase {
public void test_features() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object object, String name, Object value) {
if (value == null && object instanceof Model && "id".equals(name)) {
return false;
Reported by PMD.
Line: 17
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object object, String name, Object value) {
if (value == null && object instanceof Model && "id".equals(name)) {
return false;
}
return true;
}
};
Reported by PMD.
Line: 14
*/
public class WriteNullStringAsEmptyTest extends TestCase {
public void test_features() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object object, String name, Object value) {
if (value == null && object instanceof Model && "id".equals(name)) {
return false;
}
Reported by PMD.
Line: 14
*/
public class WriteNullStringAsEmptyTest extends TestCase {
public void test_features() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object object, String name, Object value) {
if (value == null && object instanceof Model && "id".equals(name)) {
return false;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_2900/Issue2952.java
6 issues
Line: 12
import junit.framework.TestCase;
public class Issue2952 extends TestCase {
public void test_for_issue() throws Exception {
String expected = "{\"l\":null,\"s\":null,\"b\":null,\"i\":null,\"o\":null}";
SerializerFeature[] serializerFeatures = {
SerializerFeature.WriteNullListAsEmpty,
SerializerFeature.WriteNullStringAsEmpty,
SerializerFeature.WriteNullBooleanAsFalse,
Reported by PMD.
Line: 12
import junit.framework.TestCase;
public class Issue2952 extends TestCase {
public void test_for_issue() throws Exception {
String expected = "{\"l\":null,\"s\":null,\"b\":null,\"i\":null,\"o\":null}";
SerializerFeature[] serializerFeatures = {
SerializerFeature.WriteNullListAsEmpty,
SerializerFeature.WriteNullStringAsEmpty,
SerializerFeature.WriteNullBooleanAsFalse,
Reported by PMD.
Line: 22
};
SerializeConfig asmConfig = new SerializeConfig();
asmConfig.setAsmEnable(true);
assertEquals(expected, JSON.toJSONString(new Pojo(), asmConfig, serializerFeatures));
assertEquals(expected, JSON.toJSONString(new Pojo2(), asmConfig, serializerFeatures));
SerializeConfig noasmConfig = new SerializeConfig();
noasmConfig.setAsmEnable(false);
assertEquals(expected, JSON.toJSONString(new Pojo(), noasmConfig, serializerFeatures));
assertEquals(expected, JSON.toJSONString(new Pojo2(), noasmConfig, serializerFeatures));
Reported by PMD.
Line: 23
SerializeConfig asmConfig = new SerializeConfig();
asmConfig.setAsmEnable(true);
assertEquals(expected, JSON.toJSONString(new Pojo(), asmConfig, serializerFeatures));
assertEquals(expected, JSON.toJSONString(new Pojo2(), asmConfig, serializerFeatures));
SerializeConfig noasmConfig = new SerializeConfig();
noasmConfig.setAsmEnable(false);
assertEquals(expected, JSON.toJSONString(new Pojo(), noasmConfig, serializerFeatures));
assertEquals(expected, JSON.toJSONString(new Pojo2(), noasmConfig, serializerFeatures));
}
Reported by PMD.
Line: 26
assertEquals(expected, JSON.toJSONString(new Pojo2(), asmConfig, serializerFeatures));
SerializeConfig noasmConfig = new SerializeConfig();
noasmConfig.setAsmEnable(false);
assertEquals(expected, JSON.toJSONString(new Pojo(), noasmConfig, serializerFeatures));
assertEquals(expected, JSON.toJSONString(new Pojo2(), noasmConfig, serializerFeatures));
}
public static class Pojo {
@JSONField(serialzeFeatures=SerializerFeature.WriteMapNullValue, ordinal=0)
Reported by PMD.
Line: 27
SerializeConfig noasmConfig = new SerializeConfig();
noasmConfig.setAsmEnable(false);
assertEquals(expected, JSON.toJSONString(new Pojo(), noasmConfig, serializerFeatures));
assertEquals(expected, JSON.toJSONString(new Pojo2(), noasmConfig, serializerFeatures));
}
public static class Pojo {
@JSONField(serialzeFeatures=SerializerFeature.WriteMapNullValue, ordinal=0)
public Object[] l;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1900/Issue1941_JSONField_order.java
6 issues
Line: 10
public class Issue1941_JSONField_order extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\",\"name\":\"floorname2\"}";
FloorV2 a=(FloorV2) JSON.parseObject(json,Area.class);
assertEquals("floorname2", a.name);
assertEquals("x123", a.templateId);
}
Reported by PMD.
Line: 10
public class Issue1941_JSONField_order extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\",\"name\":\"floorname2\"}";
FloorV2 a=(FloorV2) JSON.parseObject(json,Area.class);
assertEquals("floorname2", a.name);
assertEquals("x123", a.templateId);
}
Reported by PMD.
Line: 13
public void test_for_issue() throws Exception {
String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\",\"name\":\"floorname2\"}";
FloorV2 a=(FloorV2) JSON.parseObject(json,Area.class);
assertEquals("floorname2", a.name);
assertEquals("x123", a.templateId);
}
@JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
public static interface Area {
Reported by PMD.
Line: 14
String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\",\"name\":\"floorname2\"}";
FloorV2 a=(FloorV2) JSON.parseObject(json,Area.class);
assertEquals("floorname2", a.name);
assertEquals("x123", a.templateId);
}
@JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
public static interface Area {
}
Reported by PMD.
Line: 25
public static class FloorV2 implements Area {
@JSONField(ordinal = -1)
public String type;
public String templateId;
public String name;
}
}
Reported by PMD.
Line: 26
@JSONField(ordinal = -1)
public String type;
public String templateId;
public String name;
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1900/Issue1941.java
6 issues
Line: 9
public class Issue1941 extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\",\"name\":\"floorname2\"}";
FloorV2 a=(FloorV2) JSON.parseObject(json,Area.class);
assertEquals("floorname2", a.name);
assertEquals("x123", a.templateId);
}
Reported by PMD.
Line: 9
public class Issue1941 extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\",\"name\":\"floorname2\"}";
FloorV2 a=(FloorV2) JSON.parseObject(json,Area.class);
assertEquals("floorname2", a.name);
assertEquals("x123", a.templateId);
}
Reported by PMD.
Line: 12
public void test_for_issue() throws Exception {
String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\",\"name\":\"floorname2\"}";
FloorV2 a=(FloorV2) JSON.parseObject(json,Area.class);
assertEquals("floorname2", a.name);
assertEquals("x123", a.templateId);
}
@JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
public static interface Area {
Reported by PMD.
Line: 13
String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\",\"name\":\"floorname2\"}";
FloorV2 a=(FloorV2) JSON.parseObject(json,Area.class);
assertEquals("floorname2", a.name);
assertEquals("x123", a.templateId);
}
@JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
public static interface Area {
}
Reported by PMD.
Line: 23
@JSONType(typeName = "floorV2")
public static class FloorV2 implements Area {
public String type;
public String templateId;
public String name;
}
}
Reported by PMD.
Line: 24
public static class FloorV2 implements Area {
public String type;
public String templateId;
public String name;
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_3000/Issue3082.java
6 issues
Line: 14
import java.util.Map;
public class Issue3082 extends TestCase {
public void test_for_issue_entry() throws Exception {
String str = "{\"k\":{\"k\":\"v\"}}";
Map.Entry<String, Map.Entry<String, String>> entry = JSON.parseObject(str, new TypeReference<Map.Entry<String, Map.Entry<String, String>>>() {});
assertEquals("v", entry.getValue().getValue());
}
Reported by PMD.
Line: 17
public void test_for_issue_entry() throws Exception {
String str = "{\"k\":{\"k\":\"v\"}}";
Map.Entry<String, Map.Entry<String, String>> entry = JSON.parseObject(str, new TypeReference<Map.Entry<String, Map.Entry<String, String>>>() {});
assertEquals("v", entry.getValue().getValue());
}
public void test_for_issue() throws Exception {
HashSet<Map.Entry<String, Map.Entry<String, String>>> nestedSet = new HashSet<Map.Entry<String, Map.Entry<String, String>>>();
nestedSet.add(new AbstractMap.SimpleEntry<String, Map.Entry<String, String>>("a", new AbstractMap.SimpleEntry<String, String>("b", "c")));
Reported by PMD.
Line: 17
public void test_for_issue_entry() throws Exception {
String str = "{\"k\":{\"k\":\"v\"}}";
Map.Entry<String, Map.Entry<String, String>> entry = JSON.parseObject(str, new TypeReference<Map.Entry<String, Map.Entry<String, String>>>() {});
assertEquals("v", entry.getValue().getValue());
}
public void test_for_issue() throws Exception {
HashSet<Map.Entry<String, Map.Entry<String, String>>> nestedSet = new HashSet<Map.Entry<String, Map.Entry<String, String>>>();
nestedSet.add(new AbstractMap.SimpleEntry<String, Map.Entry<String, String>>("a", new AbstractMap.SimpleEntry<String, String>("b", "c")));
Reported by PMD.
Line: 20
assertEquals("v", entry.getValue().getValue());
}
public void test_for_issue() throws Exception {
HashSet<Map.Entry<String, Map.Entry<String, String>>> nestedSet = new HashSet<Map.Entry<String, Map.Entry<String, String>>>();
nestedSet.add(new AbstractMap.SimpleEntry<String, Map.Entry<String, String>>("a", new AbstractMap.SimpleEntry<String, String>("b", "c")));
nestedSet.add(new AbstractMap.SimpleEntry<String, Map.Entry<String, String>>("d", new AbstractMap.SimpleEntry<String, String>("e", "f")));
String content = JSON.toJSONString(nestedSet);
Reported by PMD.
Line: 30
HashSet<Map.Entry<String, Map.Entry<String, String>>> deserializedNestedSet;
Type type = new TypeReference<HashSet<Map.Entry<String, Map.Entry<String, String>>>>() {}.getType();
deserializedNestedSet = JSON.parseObject(content, type);
assertEquals(nestedSet, deserializedNestedSet);
}
}
Reported by PMD.
Line: 5
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;
import java.lang.reflect.Type;
import java.util.AbstractMap;
import java.util.HashSet;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_3000/Issue3093.java
6 issues
Line: 13
public class Issue3093 extends TestCase {
public void test_for_issue() throws Exception {
Timestamp ts = new Timestamp(Calendar.getInstance().getTimeInMillis());
System.out.println(ts.toString());
String json = JSON.toJSONString(ts, SerializerFeature.UseISO8601DateFormat);
System.out.println(json);
}
}
Reported by PMD.
Line: 15
Timestamp ts = new Timestamp(Calendar.getInstance().getTimeInMillis());
System.out.println(ts.toString());
String json = JSON.toJSONString(ts, SerializerFeature.UseISO8601DateFormat);
System.out.println(json);
}
}
Reported by PMD.
Line: 11
import java.util.Calendar;
public class Issue3093 extends TestCase {
public void test_for_issue() throws Exception {
Timestamp ts = new Timestamp(Calendar.getInstance().getTimeInMillis());
System.out.println(ts.toString());
String json = JSON.toJSONString(ts, SerializerFeature.UseISO8601DateFormat);
System.out.println(json);
}
Reported by PMD.
Line: 11
import java.util.Calendar;
public class Issue3093 extends TestCase {
public void test_for_issue() throws Exception {
Timestamp ts = new Timestamp(Calendar.getInstance().getTimeInMillis());
System.out.println(ts.toString());
String json = JSON.toJSONString(ts, SerializerFeature.UseISO8601DateFormat);
System.out.println(json);
}
Reported by PMD.
Line: 12
public class Issue3093 extends TestCase {
public void test_for_issue() throws Exception {
Timestamp ts = new Timestamp(Calendar.getInstance().getTimeInMillis());
System.out.println(ts.toString());
String json = JSON.toJSONString(ts, SerializerFeature.UseISO8601DateFormat);
System.out.println(json);
}
}
Reported by PMD.
Line: 12
public class Issue3093 extends TestCase {
public void test_for_issue() throws Exception {
Timestamp ts = new Timestamp(Calendar.getInstance().getTimeInMillis());
System.out.println(ts.toString());
String json = JSON.toJSONString(ts, SerializerFeature.UseISO8601DateFormat);
System.out.println(json);
}
}
Reported by PMD.