The following issues were found
src/test/java/com/alibaba/json/bvt/bug/Issue79.java
5 issues
Line: 13
public class Issue79 extends TestCase {
public void test_for_issue_79() throws Exception {
SearchResult result = JSON.parseObject("{\"present\":{\"records\":[{}]}}", SearchResult.class);
Assert.assertNotNull(result.present);
Assert.assertNotNull(result.present.records);
Assert.assertNotNull(result.present.records.get(0));
Assert.assertNotNull(result.present.records.get(0) instanceof PresentRecord);
Reported by PMD.
Line: 17
SearchResult result = JSON.parseObject("{\"present\":{\"records\":[{}]}}", SearchResult.class);
Assert.assertNotNull(result.present);
Assert.assertNotNull(result.present.records);
Assert.assertNotNull(result.present.records.get(0));
Assert.assertNotNull(result.present.records.get(0) instanceof PresentRecord);
}
public static class SearchResult {
Reported by PMD.
Line: 18
Assert.assertNotNull(result.present);
Assert.assertNotNull(result.present.records);
Assert.assertNotNull(result.present.records.get(0));
Assert.assertNotNull(result.present.records.get(0) instanceof PresentRecord);
}
public static class SearchResult {
public Present present;
Reported by PMD.
Line: 23
public static class SearchResult {
public Present present;
}
public static class Present {
public List<PresentRecord> records;
Reported by PMD.
Line: 28
public static class Present {
public List<PresentRecord> records;
}
public static class PresentRecord {
}
Reported by PMD.
src/test/java/com/alibaba/fastjson/serializer/issue3638and3067/Issue3638and3067Test.java
5 issues
Line: 17
* @date 2021/4/17 14:47
*/
public class Issue3638and3067Test {
JSONObject jo;
@Before
public void init() {
jo = new JSONObject();
}
Reported by PMD.
Line: 27
@Test
public void testTime1() {
jo.put("d1", "2021-04-17 15:14:00");
Assert.assertEquals(new Timestamp(jo.getDate("d1").getTime()), jo.getTimestamp("d1"));
}
@Test
public void testTime2() {
jo.put("d2", "1970-01-01 08:00:00");
Reported by PMD.
Line: 33
@Test
public void testTime2() {
jo.put("d2", "1970-01-01 08:00:00");
Assert.assertEquals(new Timestamp(jo.getDate("d2").getTime()), jo.getTimestamp("d2"));
}
@Test
public void testTime3() {
jo.put("d3", "1970-01-01 07:00:00");
Reported by PMD.
Line: 39
@Test
public void testTime3() {
jo.put("d3", "1970-01-01 07:00:00");
Assert.assertEquals(new Timestamp(jo.getDate("d3").getTime()), jo.getTimestamp("d3"));
}
@Test
public void testTime4() {
jo.put("d4", "1900-01-01");
Reported by PMD.
Line: 45
@Test
public void testTime4() {
jo.put("d4", "1900-01-01");
Assert.assertEquals(new Timestamp(jo.getDate("d4").getTime()), jo.getTimestamp("d4"));
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue771.java
5 issues
Line: 18
public class Issue771 extends TestCase {
public void test_for_issue() throws Exception {
SerializeWriter writer = new SerializeWriter(null, JSON.DEFAULT_GENERATE_FEATURE, new SerializerFeature[0]);
int defaultBufferSize = writer.getBufferLength();
String encoded = JSON.toJSONString(new FooBar(defaultBufferSize));
JSONObject decoded = (JSONObject) JSON.parse(encoded);
JSONArray dataToEncode = decoded.getJSONArray("dataToEncode");
Reported by PMD.
Line: 23
int defaultBufferSize = writer.getBufferLength();
String encoded = JSON.toJSONString(new FooBar(defaultBufferSize));
JSONObject decoded = (JSONObject) JSON.parse(encoded);
JSONArray dataToEncode = decoded.getJSONArray("dataToEncode");
Assert.assertEquals(5, dataToEncode.size());
writer.close();
}
public static class FooBar {
Reported by PMD.
Line: 24
String encoded = JSON.toJSONString(new FooBar(defaultBufferSize));
JSONObject decoded = (JSONObject) JSON.parse(encoded);
JSONArray dataToEncode = decoded.getJSONArray("dataToEncode");
Assert.assertEquals(5, dataToEncode.size());
writer.close();
}
public static class FooBar {
Reported by PMD.
Line: 30
public static class FooBar {
private List<String> dataToEncode;
protected FooBar(int buffLen){
dataToEncode = new ArrayList<String>();
dataToEncode.add("foo");
dataToEncode.add("bar");
Reported by PMD.
Line: 30
public static class FooBar {
private List<String> dataToEncode;
protected FooBar(int buffLen){
dataToEncode = new ArrayList<String>();
dataToEncode.add("foo");
dataToEncode.add("bar");
Reported by PMD.
src/test/java/com/alibaba/json/bvt/TestExternal.java
5 issues
Line: 23
method.invoke(obj, "jobs");
String text = JSON.toJSONString(obj);
System.out.println(text);
JSON.parseObject(text, clazz);
}
public static class ExtClassLoader extends ClassLoader {
public ExtClassLoader() throws IOException{
Reported by PMD.
Line: 15
public class TestExternal extends TestCase {
public void test_0 () throws Exception {
ExtClassLoader classLoader = new ExtClassLoader();
Class<?> clazz = classLoader.loadClass("external.VO");
Method method = clazz.getMethod("setName", new Class[] {String.class});
Object obj = clazz.newInstance();
method.invoke(obj, "jobs");
Reported by PMD.
Line: 15
public class TestExternal extends TestCase {
public void test_0 () throws Exception {
ExtClassLoader classLoader = new ExtClassLoader();
Class<?> clazz = classLoader.loadClass("external.VO");
Method method = clazz.getMethod("setName", new Class[] {String.class});
Object obj = clazz.newInstance();
method.invoke(obj, "jobs");
Reported by PMD.
Line: 19
ExtClassLoader classLoader = new ExtClassLoader();
Class<?> clazz = classLoader.loadClass("external.VO");
Method method = clazz.getMethod("setName", new Class[] {String.class});
Object obj = clazz.newInstance();
method.invoke(obj, "jobs");
String text = JSON.toJSONString(obj);
System.out.println(text);
JSON.parseObject(text, clazz);
Reported by PMD.
Line: 32
super(Thread.currentThread().getContextClassLoader());
byte[] bytes;
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("external/VO.clazz");
bytes = IOUtils.toByteArray(is);
is.close();
super.defineClass("external.VO", bytes, 0, bytes.length);
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/ClassFieldTest.java
5 issues
Line: 12
public class ClassFieldTest extends TestCase {
public void test_codec() throws Exception {
User user = new User();
user.setValue(Object.class);
String text = JSON.toJSONString(user);
Reported by PMD.
Line: 20
User user1 = JSON.parseObject(text, User.class);
Assert.assertEquals(user1.getValue(), user.getValue());
}
public void test_error() throws Exception {
Exception error = null;
try {
Reported by PMD.
Line: 23
Assert.assertEquals(user1.getValue(), user.getValue());
}
public void test_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"value\":123}", User.class);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 8
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.util.ASMClassLoader;
public class ClassFieldTest extends TestCase {
public void test_codec() throws Exception {
User user = new User();
Reported by PMD.
Line: 24
}
public void test_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"value\":123}", User.class);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue763.java
5 issues
Line: 26
// SerializeConfig.getGlobalInstance().addFilter(Map.class, filter);
SerializeConfig config = new SerializeConfig();
config.addFilter(HashMap.class, filter);
System.out.println(JSON.toJSONString(reqDto, config));
}
}
Reported by PMD.
Line: 14
public class Issue763 extends TestCase {
public void test_0() throws Exception {
Map<String, Object> reqDto = new HashMap<String, Object>();
reqDto.put("name", "aaaa");
reqDto.put("age", 50);
reqDto.put("address", "深圳南山");
Reported by PMD.
Line: 14
public class Issue763 extends TestCase {
public void test_0() throws Exception {
Map<String, Object> reqDto = new HashMap<String, Object>();
reqDto.put("name", "aaaa");
reqDto.put("age", 50);
reqDto.put("address", "深圳南山");
Reported by PMD.
Line: 21
reqDto.put("address", "深圳南山");
SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
filter.getExcludes().add("name");
// SerializeConfig.getGlobalInstance().addFilter(Map.class, filter);
SerializeConfig config = new SerializeConfig();
config.addFilter(HashMap.class, filter);
System.out.println(JSON.toJSONString(reqDto, config));
Reported by PMD.
Line: 25
// SerializeConfig.getGlobalInstance().addFilter(Map.class, filter);
SerializeConfig config = new SerializeConfig();
config.addFilter(HashMap.class, filter);
System.out.println(JSON.toJSONString(reqDto, config));
}
}
Reported by PMD.
src/test/java/com/alibaba/fastjson/jsonpath/issue3493/TestIssue3493.java
5 issues
Line: 19
@Test
public void testIssue3493(){
String json = "{\n" +
"\"result\": [\n" +
"{\n" +
"\"puid\": \"21025318\"\n" +
"},\n" +
"{\n" +
Reported by PMD.
Line: 34
"\"state\": 0\n" +
"}";
Object list = JSONPath.extract(json, "$.result[0,2].puid");
JSONArray jsonArray = JSON.parseArray(list.toString());
Assert.assertEquals(jsonArray.size(), 2);
Assert.assertEquals(jsonArray.get(0), "21025318");
Assert.assertEquals(jsonArray.get(1), "21025345");
}
}
Reported by PMD.
Line: 35
"}";
Object list = JSONPath.extract(json, "$.result[0,2].puid");
JSONArray jsonArray = JSON.parseArray(list.toString());
Assert.assertEquals(jsonArray.size(), 2);
Assert.assertEquals(jsonArray.get(0), "21025318");
Assert.assertEquals(jsonArray.get(1), "21025345");
}
}
Reported by PMD.
Line: 36
Object list = JSONPath.extract(json, "$.result[0,2].puid");
JSONArray jsonArray = JSON.parseArray(list.toString());
Assert.assertEquals(jsonArray.size(), 2);
Assert.assertEquals(jsonArray.get(0), "21025318");
Assert.assertEquals(jsonArray.get(1), "21025345");
}
}
Reported by PMD.
Line: 37
JSONArray jsonArray = JSON.parseArray(list.toString());
Assert.assertEquals(jsonArray.size(), 2);
Assert.assertEquals(jsonArray.get(0), "21025318");
Assert.assertEquals(jsonArray.get(1), "21025345");
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue688.java
5 issues
Line: 23
userMap.put(monther, grandma);
String json = JSON.toJSONString(userMap);
System.out.println(json);
}
public static class User {
public String name;
public long id;
Reported by PMD.
Line: 13
* Created by wenshao on 2016/11/13.
*/
public class Issue688 extends TestCase {
public void test_for_issue() throws Exception {
User monther = new User("HanMeiMei", 29L);
User child = new User("liLei", 2L);
User grandma = new User("zhangHua", 60L);
Map<User, User> userMap = new HashMap<User, User>();
Reported by PMD.
Line: 13
* Created by wenshao on 2016/11/13.
*/
public class Issue688 extends TestCase {
public void test_for_issue() throws Exception {
User monther = new User("HanMeiMei", 29L);
User child = new User("liLei", 2L);
User grandma = new User("zhangHua", 60L);
Map<User, User> userMap = new HashMap<User, User>();
Reported by PMD.
Line: 27
}
public static class User {
public String name;
public long id;
public User() {
}
Reported by PMD.
Line: 28
public static class User {
public String name;
public long id;
public User() {
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue62.java
5 issues
Line: 12
public class Issue62 extends TestCase {
public void test_for_issue() throws Exception {
A a = new A();
a.setA("aaaaaaaaaa".getBytes());
a.setB(1);
a.setC("aaaa");
String jsonData = JSON.toJSONString(a, SerializerFeature.UseSingleQuotes);
Reported by PMD.
Line: 22
JSON.parse(jsonData);
}
static class A {
private byte[] a;
private int b;
private String c;
Reported by PMD.
Line: 24
static class A {
private byte[] a;
private int b;
private String c;
public byte[] getA() {
return a;
Reported by PMD.
Line: 29
private String c;
public byte[] getA() {
return a;
}
public void setA(byte[] a) {
this.a = a;
}
Reported by PMD.
Line: 32
return a;
}
public void setA(byte[] a) {
this.a = a;
}
public int getB() {
return b;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue569_1.java
5 issues
Line: 8
import junit.framework.TestCase;
public class Issue569_1 extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"result\":{}}";
InterfaceResult<Value> result = JSON.parseObject(json, new TypeReference<InterfaceResult<Value>>() {});
assertNotNull(result.getResult());
assertEquals(Value.class, result.getResult().getClass());
}
Reported by PMD.
Line: 8
import junit.framework.TestCase;
public class Issue569_1 extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"result\":{}}";
InterfaceResult<Value> result = JSON.parseObject(json, new TypeReference<InterfaceResult<Value>>() {});
assertNotNull(result.getResult());
assertEquals(Value.class, result.getResult().getClass());
}
Reported by PMD.
Line: 11
public void test_for_issue() throws Exception {
String json = "{\"result\":{}}";
InterfaceResult<Value> result = JSON.parseObject(json, new TypeReference<InterfaceResult<Value>>() {});
assertNotNull(result.getResult());
assertEquals(Value.class, result.getResult().getClass());
}
public static class BaseInterfaceResult {
Reported by PMD.
Line: 12
String json = "{\"result\":{}}";
InterfaceResult<Value> result = JSON.parseObject(json, new TypeReference<InterfaceResult<Value>>() {});
assertNotNull(result.getResult());
assertEquals(Value.class, result.getResult().getClass());
}
public static class BaseInterfaceResult {
}
Reported by PMD.
Line: 12
String json = "{\"result\":{}}";
InterfaceResult<Value> result = JSON.parseObject(json, new TypeReference<InterfaceResult<Value>>() {});
assertNotNull(result.getResult());
assertEquals(Value.class, result.getResult().getClass());
}
public static class BaseInterfaceResult {
}
Reported by PMD.