The following issues were found
src/test/java/com/alibaba/json/bvt/parser/fieldTypeResolver/FieldTypeResolverTest.java
6 issues
Line: 15
public class FieldTypeResolverTest extends TestCase {
public void test_0() throws Exception {
String text = "{\"item_0\":{},\"item_1\":{}}";
FieldTypeResolver fieldResolver = new FieldTypeResolver() {
public Type resolve(Object object, String fieldName) {
Reported by PMD.
Line: 30
};
JSONObject jsonObject = JSON.parseObject(text, JSONObject.class, fieldResolver);
Assert.assertTrue(jsonObject.get("item_0") instanceof Item);
}
public static class Item {
}
Reported by PMD.
Line: 16
public class FieldTypeResolverTest extends TestCase {
public void test_0() throws Exception {
String text = "{\"item_0\":{},\"item_1\":{}}";
FieldTypeResolver fieldResolver = new FieldTypeResolver() {
public Type resolve(Object object, String fieldName) {
if (fieldName.startsWith("item_")) {
Reported by PMD.
Line: 16
public class FieldTypeResolverTest extends TestCase {
public void test_0() throws Exception {
String text = "{\"item_0\":{},\"item_1\":{}}";
FieldTypeResolver fieldResolver = new FieldTypeResolver() {
public Type resolve(Object object, String fieldName) {
if (fieldName.startsWith("item_")) {
Reported by PMD.
Line: 18
public void test_0() throws Exception {
String text = "{\"item_0\":{},\"item_1\":{}}";
FieldTypeResolver fieldResolver = new FieldTypeResolver() {
public Type resolve(Object object, String fieldName) {
if (fieldName.startsWith("item_")) {
return Item.class;
}
Reported by PMD.
Line: 18
public void test_0() throws Exception {
String text = "{\"item_0\":{},\"item_1\":{}}";
FieldTypeResolver fieldResolver = new FieldTypeResolver() {
public Type resolve(Object object, String fieldName) {
if (fieldName.startsWith("item_")) {
return Item.class;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/serializer/PrettyFormatTest2.java
6 issues
Line: 12
public class PrettyFormatTest2 extends TestCase {
public void test_0() throws Exception {
Model model = new Model();
model.id = 123;
model.name = "wenshao";
String text = JSON.toJSONString(model, SerializerFeature.PrettyFormat);
assertEquals("{\n" +
Reported by PMD.
Line: 17
model.id = 123;
model.name = "wenshao";
String text = JSON.toJSONString(model, SerializerFeature.PrettyFormat);
assertEquals("{\n" +
"\t\"id\":123,\n" +
"\t\"name\":\"wenshao\"\n" +
"}", text);
Assert.assertEquals("[\n\t{},\n\t{}\n]", JSON.toJSONString(new Object[] { new Object(), new Object() }, SerializerFeature.PrettyFormat));
Reported by PMD.
Line: 26
}
public static class Model {
public int id;
public String name;
}
}
Reported by PMD.
Line: 27
public static class Model {
public int id;
public String name;
}
}
Reported by PMD.
Line: 4
package com.alibaba.json.bvt.serializer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;
import org.junit.Assert;
Reported by PMD.
Line: 5
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;
import org.junit.Assert;
public class PrettyFormatTest2 extends TestCase {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/serializer/filters/NameFilterTest_IntegerKey.java
6 issues
Line: 16
public class NameFilterTest_IntegerKey extends TestCase {
public void test_namefilter() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("1001")) {
return "ID";
Reported by PMD.
Line: 20
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("1001")) {
return "ID";
}
return name;
}
Reported by PMD.
Line: 20
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("1001")) {
return "ID";
}
return name;
}
Reported by PMD.
Line: 31
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Map map = new HashMap();
map.put(1001, 0);
serializer.write(map);
Reported by PMD.
Line: 17
public class NameFilterTest_IntegerKey extends TestCase {
public void test_namefilter() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("1001")) {
return "ID";
}
Reported by PMD.
Line: 17
public class NameFilterTest_IntegerKey extends TestCase {
public void test_namefilter() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("1001")) {
return "ID";
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/taobao/TradeTest.java
6 issues
Line: 9
import junit.framework.TestCase;
public class TradeTest extends TestCase {
public void test_cast() {
String s
= "{\"period\":{\"label\":\"最近30天\",\"value\":\"30d\"},\"data\":{\"gmv\":{\"min\":-2},\"id\":3712312925}}";
Param param;
param = JSON.parseObject(s, Param.class); // 从字符串直接转化,OK
assertNotNull(param);
Reported by PMD.
Line: 14
= "{\"period\":{\"label\":\"最近30天\",\"value\":\"30d\"},\"data\":{\"gmv\":{\"min\":-2},\"id\":3712312925}}";
Param param;
param = JSON.parseObject(s, Param.class); // 从字符串直接转化,OK
assertNotNull(param);
JSONObject jobj = JSON.parseObject(s);
param = jobj.toJavaObject(Param.class);
}
Reported by PMD.
Line: 17
assertNotNull(param);
JSONObject jobj = JSON.parseObject(s);
param = jobj.toJavaObject(Param.class);
}
public static class Param extends BaseObject {
private static final long serialVersionUID = 5180807854744861824L;
Reported by PMD.
Line: 17
assertNotNull(param);
JSONObject jobj = JSON.parseObject(s);
param = jobj.toJavaObject(Param.class);
}
public static class Param extends BaseObject {
private static final long serialVersionUID = 5180807854744861824L;
Reported by PMD.
Line: 4
package com.alibaba.json.bvt.taobao;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import junit.framework.TestCase;
public class TradeTest extends TestCase {
public void test_cast() {
Reported by PMD.
Line: 17
assertNotNull(param);
JSONObject jobj = JSON.parseObject(s);
param = jobj.toJavaObject(Param.class);
}
public static class Param extends BaseObject {
private static final long serialVersionUID = 5180807854744861824L;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/typeRef/TypeReferenceTest7.java
6 issues
Line: 13
public class TypeReferenceTest7 extends TestCase {
public void test_typeRef() throws Exception {
TypeReference<Map<String, Entity>> typeRef = new TypeReference<Map<String, Entity>>() {
};
Map<String, Entity> map = JSON
.parseObject(
Reported by PMD.
Line: 22
"{\"value\":{\"id\":\"abc\",\"a\":{\"id\":123}}}",
typeRef);
Entity entity = map.get("value");
Assert.assertNotNull(entity);
Assert.assertEquals("abc", entity.getId());
Assert.assertEquals(123, entity.getA().getId());
}
Reported by PMD.
Line: 24
Entity entity = map.get("value");
Assert.assertNotNull(entity);
Assert.assertEquals("abc", entity.getId());
Assert.assertEquals(123, entity.getA().getId());
}
public static class Entity {
private String id;
Reported by PMD.
Line: 25
Entity entity = map.get("value");
Assert.assertNotNull(entity);
Assert.assertEquals("abc", entity.getId());
Assert.assertEquals(123, entity.getA().getId());
}
public static class Entity {
private String id;
Reported by PMD.
Line: 25
Entity entity = map.get("value");
Assert.assertNotNull(entity);
Assert.assertEquals("abc", entity.getId());
Assert.assertEquals(123, entity.getA().getId());
}
public static class Entity {
private String id;
Reported by PMD.
Line: 28
Assert.assertEquals(123, entity.getA().getId());
}
public static class Entity {
private String id;
private A a;
public String getId() {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/path/JSONPath_1.java
6 issues
Line: 12
public class JSONPath_1 extends TestCase {
public void test_path_empty() throws Exception {
Throwable error = null;
try {
JSONPath.compile("");
} catch (JSONPathException ex) {
error = ex;
Reported by PMD.
Line: 22
Assert.assertNotNull(error);
}
public void test_path_null() throws Exception {
Throwable error = null;
try {
JSONPath.compile(null);
} catch (JSONPathException ex) {
error = ex;
Reported by PMD.
Line: 32
Assert.assertNotNull(error);
}
public void test_path_null_1() throws Exception {
Throwable error = null;
try {
new JSONPath(null);
} catch (JSONPathException ex) {
error = ex;
Reported by PMD.
Line: 13
public class JSONPath_1 extends TestCase {
public void test_path_empty() throws Exception {
Throwable error = null;
try {
JSONPath.compile("");
} catch (JSONPathException ex) {
error = ex;
}
Reported by PMD.
Line: 23
}
public void test_path_null() throws Exception {
Throwable error = null;
try {
JSONPath.compile(null);
} catch (JSONPathException ex) {
error = ex;
}
Reported by PMD.
Line: 33
}
public void test_path_null_1() throws Exception {
Throwable error = null;
try {
new JSONPath(null);
} catch (JSONPathException ex) {
error = ex;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/serializer/ObjectWriteTest.java
6 issues
Line: 13
* Created by wenshao on 15/03/2017.
*/
public class ObjectWriteTest extends TestCase {
public void test_objectWriteTest() throws Exception {
ObjectSerializer serializer = SerializeConfig.getGlobalInstance().getObjectWriter(Model.class);
JSONSerializer jsonSerializer = new JSONSerializer();
serializer.write(jsonSerializer, null, "a", Model.class, 0);
Reported by PMD.
Line: 14
*/
public class ObjectWriteTest extends TestCase {
public void test_objectWriteTest() throws Exception {
ObjectSerializer serializer = SerializeConfig.getGlobalInstance().getObjectWriter(Model.class);
JSONSerializer jsonSerializer = new JSONSerializer();
serializer.write(jsonSerializer, null, "a", Model.class, 0);
String text = jsonSerializer.out.toString();
Reported by PMD.
Line: 17
ObjectSerializer serializer = SerializeConfig.getGlobalInstance().getObjectWriter(Model.class);
JSONSerializer jsonSerializer = new JSONSerializer();
serializer.write(jsonSerializer, null, "a", Model.class, 0);
String text = jsonSerializer.out.toString();
assertEquals("null", text);
}
Reported by PMD.
Line: 19
JSONSerializer jsonSerializer = new JSONSerializer();
serializer.write(jsonSerializer, null, "a", Model.class, 0);
String text = jsonSerializer.out.toString();
assertEquals("null", text);
}
public static class Model {
public int id;
Reported by PMD.
Line: 20
serializer.write(jsonSerializer, null, "a", Model.class, 0);
String text = jsonSerializer.out.toString();
assertEquals("null", text);
}
public static class Model {
public int id;
}
Reported by PMD.
Line: 3
package com.alibaba.json.bvt.serializer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;
import junit.framework.TestCase;
/**
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/deser/deny/DenyTest15.java
6 issues
Line: 10
* Created by wenshao on 29/01/2017.
*/
public class DenyTest15 extends TestCase {
public void test_deny() throws Exception {
String text = "{\"value\":{\"@type\":\"com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase\"}}";
Exception error = null;
try {
Model model = JSON.parseObject(text, Model.class);
} catch (Exception ex) {
Reported by PMD.
Line: 14
String text = "{\"value\":{\"@type\":\"com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase\"}}";
Exception error = null;
try {
Model model = JSON.parseObject(text, Model.class);
} catch (Exception ex) {
error = ex;
}
assertNotNull(error);
}
Reported by PMD.
Line: 15
Exception error = null;
try {
Model model = JSON.parseObject(text, Model.class);
} catch (Exception ex) {
error = ex;
}
assertNotNull(error);
}
Reported by PMD.
Line: 18
} catch (Exception ex) {
error = ex;
}
assertNotNull(error);
}
public static class Model {
public Throwable value;
}
Reported by PMD.
Line: 12
public class DenyTest15 extends TestCase {
public void test_deny() throws Exception {
String text = "{\"value\":{\"@type\":\"com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase\"}}";
Exception error = null;
try {
Model model = JSON.parseObject(text, Model.class);
} catch (Exception ex) {
error = ex;
}
Reported by PMD.
Line: 14
String text = "{\"value\":{\"@type\":\"com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase\"}}";
Exception error = null;
try {
Model model = JSON.parseObject(text, Model.class);
} catch (Exception ex) {
error = ex;
}
assertNotNull(error);
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/deser/UUIDDeserializerTest.java
6 issues
Line: 18
public class UUIDDeserializerTest extends TestCase {
public void test_url() throws Exception {
UUID id = UUID.randomUUID();
Assert.assertEquals(id, JSON.parseObject("'" + id.toString() + "'", UUID.class));
Assert.assertEquals(null, JSON.parseObject("null", UUID.class));
Reported by PMD.
Line: 20
public void test_url() throws Exception {
UUID id = UUID.randomUUID();
Assert.assertEquals(id, JSON.parseObject("'" + id.toString() + "'", UUID.class));
Assert.assertEquals(null, JSON.parseObject("null", UUID.class));
DefaultJSONParser parser = new DefaultJSONParser("null", ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
Assert.assertEquals(null, MiscCodec.instance.deserialze(parser, null, null));
Reported by PMD.
Line: 25
Assert.assertEquals(null, JSON.parseObject("null", UUID.class));
DefaultJSONParser parser = new DefaultJSONParser("null", ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
Assert.assertEquals(null, MiscCodec.instance.deserialze(parser, null, null));
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
}
public void test_url_error() throws Exception {
Reported by PMD.
Line: 26
DefaultJSONParser parser = new DefaultJSONParser("null", ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
Assert.assertEquals(null, MiscCodec.instance.deserialze(parser, null, null));
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
}
public void test_url_error() throws Exception {
JSONException ex = null;
Reported by PMD.
Line: 30
}
public void test_url_error() throws Exception {
JSONException ex = null;
try {
JSON.parseObject("'123'", UUID.class);
} catch (JSONException e) {
ex = e;
Reported by PMD.
Line: 31
}
public void test_url_error() throws Exception {
JSONException ex = null;
try {
JSON.parseObject("'123'", UUID.class);
} catch (JSONException e) {
ex = e;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/deser/MyMapFieldTest.java
6 issues
Line: 13
public class MyMapFieldTest extends TestCase {
public void test_null() throws Exception {
Entity value = JSON.parseObject("{value:null}", Entity.class);
Assert.assertNull(value.getValue());
}
public void test_empty() throws Exception {
Reported by PMD.
Line: 15
public void test_null() throws Exception {
Entity value = JSON.parseObject("{value:null}", Entity.class);
Assert.assertNull(value.getValue());
}
public void test_empty() throws Exception {
Exception error = null;
try {
Reported by PMD.
Line: 18
Assert.assertNull(value.getValue());
}
public void test_empty() throws Exception {
Exception error = null;
try {
JSON.parseObject("{value:{}}", Entity.class);
} catch (Exception ex) {
error = ex;
Reported by PMD.
Line: 22
Exception error = null;
try {
JSON.parseObject("{value:{}}", Entity.class);
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
Reported by PMD.
Line: 41
}
}
public class MyMap<K, V> extends HashMap<K, V> {
}
}
Reported by PMD.
Line: 19
}
public void test_empty() throws Exception {
Exception error = null;
try {
JSON.parseObject("{value:{}}", Entity.class);
} catch (Exception ex) {
error = ex;
}
Reported by PMD.