The following issues were found
src/test/java/com/alibaba/json/bvt/ArrayRefTest.java
8 issues
Line: 33
text = JSON.toJSONString(groups);
}
System.out.println(text);
List<Group> groups = JSON.parseObject(text, new TypeReference<List<Group>>() {});
Assert.assertEquals(6, groups.size());
Assert.assertEquals(0, groups.get(0).getId());
Reported by PMD.
Line: 14
public class ArrayRefTest extends TestCase {
public void test_0() throws Exception {
String text;
{
List<Group> groups = new ArrayList<Group>();
Group g0 = new Group(0);
Reported by PMD.
Line: 38
List<Group> groups = JSON.parseObject(text, new TypeReference<List<Group>>() {});
Assert.assertEquals(6, groups.size());
Assert.assertEquals(0, groups.get(0).getId());
Assert.assertEquals(1, groups.get(1).getId());
Assert.assertEquals(2, groups.get(2).getId());
Assert.assertEquals(0, groups.get(3).getId());
Assert.assertEquals(1, groups.get(4).getId());
Assert.assertEquals(2, groups.get(5).getId());
Reported by PMD.
Line: 39
Assert.assertEquals(6, groups.size());
Assert.assertEquals(0, groups.get(0).getId());
Assert.assertEquals(1, groups.get(1).getId());
Assert.assertEquals(2, groups.get(2).getId());
Assert.assertEquals(0, groups.get(3).getId());
Assert.assertEquals(1, groups.get(4).getId());
Assert.assertEquals(2, groups.get(5).getId());
}
Reported by PMD.
Line: 40
Assert.assertEquals(0, groups.get(0).getId());
Assert.assertEquals(1, groups.get(1).getId());
Assert.assertEquals(2, groups.get(2).getId());
Assert.assertEquals(0, groups.get(3).getId());
Assert.assertEquals(1, groups.get(4).getId());
Assert.assertEquals(2, groups.get(5).getId());
}
Reported by PMD.
Line: 41
Assert.assertEquals(0, groups.get(0).getId());
Assert.assertEquals(1, groups.get(1).getId());
Assert.assertEquals(2, groups.get(2).getId());
Assert.assertEquals(0, groups.get(3).getId());
Assert.assertEquals(1, groups.get(4).getId());
Assert.assertEquals(2, groups.get(5).getId());
}
public static class Group {
Reported by PMD.
Line: 42
Assert.assertEquals(1, groups.get(1).getId());
Assert.assertEquals(2, groups.get(2).getId());
Assert.assertEquals(0, groups.get(3).getId());
Assert.assertEquals(1, groups.get(4).getId());
Assert.assertEquals(2, groups.get(5).getId());
}
public static class Group {
Reported by PMD.
Line: 43
Assert.assertEquals(2, groups.get(2).getId());
Assert.assertEquals(0, groups.get(3).getId());
Assert.assertEquals(1, groups.get(4).getId());
Assert.assertEquals(2, groups.get(5).getId());
}
public static class Group {
private int id;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue1063.java
8 issues
Line: 14
* Created by wenshao on 11/03/2017.
*/
public class Issue1063 extends TestCase {
public void test_for_issue() throws Exception {
long currentMillis = System.currentTimeMillis();
TimestampBean bean = new TimestampBean();
bean.setTimestamp(new Timestamp(currentMillis));
String timestampJson = JSON.toJSONString(bean);
Reported by PMD.
Line: 21
String timestampJson = JSON.toJSONString(bean);
// 这里能转换成功
TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
Reported by PMD.
Line: 25
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
}
public static class TimestampBean {
private Timestamp timestamp = null;
Reported by PMD.
Line: 26
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
}
public static class TimestampBean {
private Timestamp timestamp = null;
Reported by PMD.
Line: 26
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
}
public static class TimestampBean {
private Timestamp timestamp = null;
Reported by PMD.
Line: 30
}
public static class TimestampBean {
private Timestamp timestamp = null;
public Timestamp getTimestamp() {
return timestamp;
}
Reported by PMD.
Line: 5
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;
import java.sql.Timestamp;
/**
Reported by PMD.
Line: 21
String timestampJson = JSON.toJSONString(bean);
// 这里能转换成功
TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue87_treeset.java
8 issues
Line: 17
to.add("test1");
to.add("test2");
String text = JSON.toJSONString(to);
System.out.println(text);
JSONObject jo = JSON.parseObject(text);
to = JSON.toJavaObject(jo, TestObject.class);
}
public static class TestObject {
Reported by PMD.
Line: 12
public class Issue87_treeset extends TestCase {
public void test_for_issue() throws Exception {
TestObject to = new TestObject();
to.add("test1");
to.add("test2");
String text = JSON.toJSONString(to);
System.out.println(text);
Reported by PMD.
Line: 12
public class Issue87_treeset extends TestCase {
public void test_for_issue() throws Exception {
TestObject to = new TestObject();
to.add("test1");
to.add("test2");
String text = JSON.toJSONString(to);
System.out.println(text);
Reported by PMD.
Line: 19
String text = JSON.toJSONString(to);
System.out.println(text);
JSONObject jo = JSON.parseObject(text);
to = JSON.toJavaObject(jo, TestObject.class);
}
public static class TestObject {
private TreeSet<String> set = new TreeSet<String>();
Reported by PMD.
Line: 24
public static class TestObject {
private TreeSet<String> set = new TreeSet<String>();
public TreeSet<String> getSet() {
return set;
}
Reported by PMD.
Line: 26
private TreeSet<String> set = new TreeSet<String>();
public TreeSet<String> getSet() {
return set;
}
public void setSet(TreeSet<String> set) {
this.set = set;
Reported by PMD.
Line: 30
return set;
}
public void setSet(TreeSet<String> set) {
this.set = set;
}
public void add(String str) {
set.add(str);
Reported by PMD.
Line: 19
String text = JSON.toJSONString(to);
System.out.println(text);
JSONObject jo = JSON.parseObject(text);
to = JSON.toJavaObject(jo, TestObject.class);
}
public static class TestObject {
private TreeSet<String> set = new TreeSet<String>();
Reported by PMD.
src/test/java/com/alibaba/json/bvt/LongFieldTest_primitive.java
8 issues
Line: 13
public class LongFieldTest_primitive extends TestCase {
public void test_codec() throws Exception {
V0 v = new V0();
v.setValue(1001L);
String text = JSON.toJSONString(v);
Reported by PMD.
Line: 21
V0 v1 = JSON.parseObject(text, V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_codec_null() throws Exception {
V0 v = new V0();
Reported by PMD.
Line: 24
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_codec_null() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
Reported by PMD.
Line: 36
V0 v1 = JSON.parseObject(text, V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_codec_null_asm() throws Exception {
V0 v = new V0();
Reported by PMD.
Line: 39
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_codec_null_asm() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(true);
Reported by PMD.
Line: 55
V0 v1 = JSON.parseObject(text, V0.class, config,
JSON.DEFAULT_PARSER_FEATURE);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_codec_null_1() throws Exception {
V0 v = new V0();
Reported by PMD.
Line: 58
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_codec_null_1() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
Reported by PMD.
Line: 71
V0 v1 = JSON.parseObject(text, V0.class);
Assert.assertEquals(123, v1.getValue());
}
public static class V0 {
private long value = 123L;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/LongFieldTest_2_stream.java
8 issues
Line: 16
public class LongFieldTest_2_stream extends TestCase {
public void test_min() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
String text = JSON.toJSONString(v);
Reported by PMD.
Line: 24
JSONReader reader = new JSONReader(new StringReader(text));
V0 v1 = reader.readObject(V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
reader.close();
}
public void test_max() throws Exception {
V0 v = new V0();
Reported by PMD.
Line: 28
reader.close();
}
public void test_max() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
String text = JSON.toJSONString(v);
Reported by PMD.
Line: 37
JSONReader reader = new JSONReader(new StringReader(text));
V0 v1 = reader.readObject(V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_min_array() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
Reported by PMD.
Line: 40
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_min_array() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
Reported by PMD.
Line: 49
JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
V0 v1 = reader.readObject(V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_max_array() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
Reported by PMD.
Line: 52
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_max_array() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
Reported by PMD.
Line: 61
JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
V0 v1 = reader.readObject(V0.class);
Assert.assertEquals(v.getValue(), v1.getValue());
}
public static class V0 {
private Long value;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/LongFieldTest_2_private.java
8 issues
Line: 14
public class LongFieldTest_2_private extends TestCase {
public void test_min() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
String text = JSON.toJSONString(v);
Reported by PMD.
Line: 22
V0 v1 = JSON.parseObject(text, V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_max() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
Reported by PMD.
Line: 25
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_max() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
String text = JSON.toJSONString(v);
Reported by PMD.
Line: 33
V0 v1 = JSON.parseObject(text, V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_min_array() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
Reported by PMD.
Line: 36
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_min_array() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
Reported by PMD.
Line: 44
V0 v1 = JSON.parseObject(text, V0.class, Feature.SupportArrayToBean);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_max_array() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
Reported by PMD.
Line: 47
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_max_array() throws Exception {
V0 v = new V0();
v.setValue(Long.MIN_VALUE);
String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
Reported by PMD.
Line: 55
V0 v1 = JSON.parseObject(text, V0.class, Feature.SupportArrayToBean);
Assert.assertEquals(v1.getValue(), v.getValue());
}
private static class V0 {
private Long value;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue821.java
8 issues
Line: 14
public class Issue821 extends TestCase {
public void test_for_issue() throws Exception {
String str1 = "{\"v\":[\" \",\"a\",\"x\",\"a\"]}";
System.out.println(str1);
char[] c = JSON.parseObject(str1, new com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
assertEquals(4, c.length);
assertEquals(c[0], ' ');
assertEquals(c[1], 'a');
Reported by PMD.
Line: 12
* Created by wenshao on 10/03/2017.
*/
public class Issue821 extends TestCase {
public void test_for_issue() throws Exception {
String str1 = "{\"v\":[\" \",\"a\",\"x\",\"a\"]}";
System.out.println(str1);
char[] c = JSON.parseObject(str1, new com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
assertEquals(4, c.length);
Reported by PMD.
Line: 12
* Created by wenshao on 10/03/2017.
*/
public class Issue821 extends TestCase {
public void test_for_issue() throws Exception {
String str1 = "{\"v\":[\" \",\"a\",\"x\",\"a\"]}";
System.out.println(str1);
char[] c = JSON.parseObject(str1, new com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
assertEquals(4, c.length);
Reported by PMD.
Line: 17
System.out.println(str1);
char[] c = JSON.parseObject(str1, new com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
assertEquals(4, c.length);
assertEquals(c[0], ' ');
assertEquals(c[1], 'a');
assertEquals(c[2], 'x');
assertEquals(c[3], 'a');
}
Reported by PMD.
Line: 18
char[] c = JSON.parseObject(str1, new com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
assertEquals(4, c.length);
assertEquals(c[0], ' ');
assertEquals(c[1], 'a');
assertEquals(c[2], 'x');
assertEquals(c[3], 'a');
}
}
Reported by PMD.
Line: 19
char[] c = JSON.parseObject(str1, new com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
assertEquals(4, c.length);
assertEquals(c[0], ' ');
assertEquals(c[1], 'a');
assertEquals(c[2], 'x');
assertEquals(c[3], 'a');
}
}
Reported by PMD.
Line: 20
assertEquals(4, c.length);
assertEquals(c[0], ' ');
assertEquals(c[1], 'a');
assertEquals(c[2], 'x');
assertEquals(c[3], 'a');
}
}
Reported by PMD.
Line: 21
assertEquals(c[0], ' ');
assertEquals(c[1], 'a');
assertEquals(c[2], 'x');
assertEquals(c[3], 'a');
}
}
Reported by PMD.
src/main/java/com/alibaba/fastjson/util/ASMClassLoader.java
8 issues
Line: 1
package com.alibaba.fastjson.util;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONAware;
Reported by PMD.
Line: 1
package com.alibaba.fastjson.util;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONAware;
Reported by PMD.
Line: 148
}
static ClassLoader getParentClassLoader() {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (contextClassLoader != null) {
try {
contextClassLoader.loadClass(JSON.class.getName());
return contextClassLoader;
} catch (ClassNotFoundException e) {
Reported by PMD.
Line: 153
try {
contextClassLoader.loadClass(JSON.class.getName());
return contextClassLoader;
} catch (ClassNotFoundException e) {
// skip
}
}
return JSON.class.getClassLoader();
}
Reported by PMD.
Line: 157
// skip
}
}
return JSON.class.getClassLoader();
}
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class<?> mappingClass = classMapping.get(name);
if (mappingClass != null) {
Reported by PMD.
Line: 168
try {
return super.loadClass(name, resolve);
} catch (ClassNotFoundException e) {
throw e;
}
}
public Class<?> defineClassPublic(String name, byte[] b, int off, int len) throws ClassFormatError {
Reported by PMD.
Line: 180
}
public boolean isExternalClass(Class<?> clazz) {
ClassLoader classLoader = clazz.getClassLoader();
if (classLoader == null) {
return false;
}
Reported by PMD.
Line: 188
ClassLoader current = this;
while (current != null) {
if (current == classLoader) {
return false;
}
current = current.getParent();
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue208.java
8 issues
Line: 9
public class Issue208 extends TestCase {
public void test_for_issue() throws Exception {
VO vo = new VO ();
vo.序号 = 1001;
vo.名称 = "张三";
String text = JSON.toJSONString(vo);
Reported by PMD.
Line: 9
public class Issue208 extends TestCase {
public void test_for_issue() throws Exception {
VO vo = new VO ();
vo.序号 = 1001;
vo.名称 = "张三";
String text = JSON.toJSONString(vo);
Reported by PMD.
Line: 19
}
public void test_for_issue_1() throws Exception {
实体 vo = new 实体 ();
vo.序号 = 1001;
vo.名称 = "张三";
String text = JSON.toJSONString(vo);
Reported by PMD.
Line: 19
}
public void test_for_issue_1() throws Exception {
实体 vo = new 实体 ();
vo.序号 = 1001;
vo.名称 = "张三";
String text = JSON.toJSONString(vo);
Reported by PMD.
Line: 30
public static class VO {
public int 序号;
public String 名称;
}
public static class 实体 {
Reported by PMD.
Line: 31
public static class VO {
public int 序号;
public String 名称;
}
public static class 实体 {
public int 序号;
Reported by PMD.
Line: 36
public static class 实体 {
public int 序号;
public String 名称;
}
}
Reported by PMD.
Line: 37
public static class 实体 {
public int 序号;
public String 名称;
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue1063_date.java
8 issues
Line: 15
* Created by wenshao on 11/03/2017.
*/
public class Issue1063_date extends TestCase {
public void test_for_issue() throws Exception {
long currentMillis = System.currentTimeMillis();
TimestampBean bean = new TimestampBean();
bean.setTimestamp(new Date(currentMillis));
String timestampJson = JSON.toJSONString(bean);
Reported by PMD.
Line: 22
String timestampJson = JSON.toJSONString(bean);
// 这里能转换成功
TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
Reported by PMD.
Line: 26
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
}
public static class TimestampBean {
private Date timestamp = null;
Reported by PMD.
Line: 27
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
}
public static class TimestampBean {
private Date timestamp = null;
Reported by PMD.
Line: 27
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
}
public static class TimestampBean {
private Date timestamp = null;
Reported by PMD.
Line: 31
}
public static class TimestampBean {
private Date timestamp = null;
public Date getTimestamp() {
return timestamp;
}
Reported by PMD.
Line: 5
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;
import java.sql.Date;
import java.sql.Timestamp;
Reported by PMD.
Line: 22
String timestampJson = JSON.toJSONString(bean);
// 这里能转换成功
TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);
// 这里抛异常 java.lang.NumberFormatException
JSONObject jsonObject = JSON.parseObject(timestampJson);
Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
Reported by PMD.