The following issues were found
src/test/java/com/alibaba/json/bvt/bug/TestDouble.java
7 issues
Line: 9
public class TestDouble extends TestCase {
public void test_doubleArray_2() throws Exception {
double[] array = new double[] { 1, 2 };
A a = new A();
a.setValue(array);
String text = JSON.toJSONString(a);
Reported by PMD.
Line: 9
public class TestDouble extends TestCase {
public void test_doubleArray_2() throws Exception {
double[] array = new double[] { 1, 2 };
A a = new A();
a.setValue(array);
String text = JSON.toJSONString(a);
Reported by PMD.
Line: 15
a.setValue(array);
String text = JSON.toJSONString(a);
A a1 = JSON.parseObject(text, A.class);
}
public static class A {
private double[] value;
Reported by PMD.
Line: 23
private double[] value;
public double[] getValue() {
return value;
}
public void setValue(double[] value) {
this.value = value;
}
Reported by PMD.
Line: 26
return value;
}
public void setValue(double[] value) {
this.value = value;
}
}
}
Reported by PMD.
Line: 26
return value;
}
public void setValue(double[] value) {
this.value = value;
}
}
}
Reported by PMD.
Line: 15
a.setValue(array);
String text = JSON.toJSONString(a);
A a1 = JSON.parseObject(text, A.class);
}
public static class A {
private double[] value;
Reported by PMD.
src/main/java/com/alibaba/fastjson/support/spring/JSONPResponseBodyAdvice.java
7 issues
Line: 42
@ControllerAdvice
public class JSONPResponseBodyAdvice implements ResponseBodyAdvice<Object> {
public final Log logger = LogFactory.getLog(this.getClass());
public JSONPResponseBodyAdvice() {
}
Reported by PMD.
Line: 42
@ControllerAdvice
public class JSONPResponseBodyAdvice implements ResponseBodyAdvice<Object> {
public final Log logger = LogFactory.getLog(this.getClass());
public JSONPResponseBodyAdvice() {
}
Reported by PMD.
Line: 53
return FastJsonHttpMessageConverter.class.isAssignableFrom(converterType)
&&
(returnType.getContainingClass().isAnnotationPresent(ResponseJSONP.class) || returnType.hasMethodAnnotation(ResponseJSONP.class));
}
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
ServerHttpResponse response) {
Reported by PMD.
Line: 62
ResponseJSONP responseJsonp = returnType.getMethodAnnotation(ResponseJSONP.class);
if(responseJsonp == null){
responseJsonp = returnType.getContainingClass().getAnnotation(ResponseJSONP.class);
}
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
String callbackMethodName = servletRequest.getParameter(responseJsonp.callback());
Reported by PMD.
Line: 66
}
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
String callbackMethodName = servletRequest.getParameter(responseJsonp.callback());
if (!IOUtils.isValidJsonpQueryParam(callbackMethodName)) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid jsonp parameter value:" + callbackMethodName);
}
Reported by PMD.
Line: 66
}
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
String callbackMethodName = servletRequest.getParameter(responseJsonp.callback());
if (!IOUtils.isValidJsonpQueryParam(callbackMethodName)) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid jsonp parameter value:" + callbackMethodName);
}
Reported by PMD.
Line: 72
if (logger.isDebugEnabled()) {
logger.debug("Invalid jsonp parameter value:" + callbackMethodName);
}
callbackMethodName = null;
}
JSONPObject jsonpObject = new JSONPObject(callbackMethodName);
jsonpObject.addParameter(body);
beforeBodyWriteInternal(jsonpObject, selectedContentType, returnType, request, response);
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Bug13.java
7 issues
Line: 15
public void test_0() throws Exception {
User user = new User("name1", "11");
String object = JSON.toJSONString(user);
System.out.println(object);
user = JSON.parseObject(object, User.class);//报错
}
public static class User {
public User() {
Reported by PMD.
Line: 12
public class Bug13 extends TestCase {
public void test_0() throws Exception {
User user = new User("name1", "11");
String object = JSON.toJSONString(user);
System.out.println(object);
user = JSON.parseObject(object, User.class);//报错
}
Reported by PMD.
Line: 12
public class Bug13 extends TestCase {
public void test_0() throws Exception {
User user = new User("name1", "11");
String object = JSON.toJSONString(user);
System.out.println(object);
user = JSON.parseObject(object, User.class);//报错
}
Reported by PMD.
Line: 16
User user = new User("name1", "11");
String object = JSON.toJSONString(user);
System.out.println(object);
user = JSON.parseObject(object, User.class);//报错
}
public static class User {
public User() {
}
Reported by PMD.
Line: 19
user = JSON.parseObject(object, User.class);//报错
}
public static class User {
public User() {
}
private String name, age;
private List<Object> group = new ArrayList<Object>(2);
Reported by PMD.
Line: 23
public User() {
}
private String name, age;
private List<Object> group = new ArrayList<Object>(2);
public List<Object> getGroup() {
return group;
}
Reported by PMD.
Line: 16
User user = new User("name1", "11");
String object = JSON.toJSONString(user);
System.out.println(object);
user = JSON.parseObject(object, User.class);//报错
}
public static class User {
public User() {
}
Reported by PMD.
src/test/java/com/alibaba/json/ByteArrayTest2.java
7 issues
Line: 42
writer.writeObject(file);
writer.flush();
System.out.println(bos);
byte[] data = bos.toByteArray();
Charset charset = Charset.forName("UTF-8");
CertFile convertFile = (CertFile)JSON.parse(data, 0, data.length, charset.newDecoder(), Feature.AllowArbitraryCommas,
Feature.IgnoreNotMatch, Feature.SortFeidFastMatch, Feature.DisableCircularReferenceDetect,
Reported by PMD.
Line: 20
public class ByteArrayTest2 extends TestCase {
public static class CertFile {
public String name;
public byte[] data;
}
public void test_0() throws Exception {
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
Reported by PMD.
Line: 21
public static class CertFile {
public String name;
public byte[] data;
}
public void test_0() throws Exception {
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
Reported by PMD.
Line: 24
public byte[] data;
}
public void test_0() throws Exception {
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
CertFile file = new CertFile();
file.name = "testname";
Reported by PMD.
Line: 25
}
public void test_0() throws Exception {
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
CertFile file = new CertFile();
file.name = "testname";
StringBuilder sb = new StringBuilder();
Reported by PMD.
Line: 32
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 2048; i++) {
sb.append("1");
}
file.data = sb.toString().getBytes();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JSONWriter writer = new JSONWriter(new OutputStreamWriter(bos));
Reported by PMD.
Line: 46
byte[] data = bos.toByteArray();
Charset charset = Charset.forName("UTF-8");
CertFile convertFile = (CertFile)JSON.parse(data, 0, data.length, charset.newDecoder(), Feature.AllowArbitraryCommas,
Feature.IgnoreNotMatch, Feature.SortFeidFastMatch, Feature.DisableCircularReferenceDetect,
Feature.AutoCloseSource);
Assert.assertEquals(file.name, convertFile.name);
Assert.assertArrayEquals(file.data, convertFile.data);
Reported by PMD.
src/test/java/com/alibaba/json/SerializerFeatureDistinctTest.java
7 issues
Line: 22
}
assertEquals(masks.size(), SerializerFeature.values().length);
System.out.println(SerializerFeature.values().length);
}
}
Reported by PMD.
Line: 13
* Created by wenshao on 24/06/2017.
*/
public class SerializerFeatureDistinctTest extends TestCase {
public void test_allfeatures() throws Exception {
Set<Object> masks = new HashSet<Object>();
for (SerializerFeature feature : SerializerFeature.values()) {
Object mask = feature.getMask();
assertFalse(masks.contains(mask));
masks.add(mask);
Reported by PMD.
Line: 13
* Created by wenshao on 24/06/2017.
*/
public class SerializerFeatureDistinctTest extends TestCase {
public void test_allfeatures() throws Exception {
Set<Object> masks = new HashSet<Object>();
for (SerializerFeature feature : SerializerFeature.values()) {
Object mask = feature.getMask();
assertFalse(masks.contains(mask));
masks.add(mask);
Reported by PMD.
Line: 17
Set<Object> masks = new HashSet<Object>();
for (SerializerFeature feature : SerializerFeature.values()) {
Object mask = feature.getMask();
assertFalse(masks.contains(mask));
masks.add(mask);
}
assertEquals(masks.size(), SerializerFeature.values().length);
System.out.println(SerializerFeature.values().length);
Reported by PMD.
Line: 20
assertFalse(masks.contains(mask));
masks.add(mask);
}
assertEquals(masks.size(), SerializerFeature.values().length);
System.out.println(SerializerFeature.values().length);
}
}
Reported by PMD.
Line: 20
assertFalse(masks.contains(mask));
masks.add(mask);
}
assertEquals(masks.size(), SerializerFeature.values().length);
System.out.println(SerializerFeature.values().length);
}
}
Reported by PMD.
Line: 22
}
assertEquals(masks.size(), SerializerFeature.values().length);
System.out.println(SerializerFeature.values().length);
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Bug_for_yanpei3.java
7 issues
Line: 14
import junit.framework.TestCase;
public class Bug_for_yanpei3 extends TestCase {
public void test_for_issue() throws Exception {
Map obj = new HashMap();
obj.put("desc", "\"Puck\"");
String text = JSON.toJSONString(obj);
// System.out.println(text);
// {"desc":"\"Puck\""}
Reported by PMD.
Line: 16
public class Bug_for_yanpei3 extends TestCase {
public void test_for_issue() throws Exception {
Map obj = new HashMap();
obj.put("desc", "\"Puck\"");
String text = JSON.toJSONString(obj);
// System.out.println(text);
// {"desc":"\"Puck\""}
Map root = new HashMap();
Reported by PMD.
Line: 28
// {"obj":"{\"desc\":\"\\\"Puck\\\"\"}"}
JSONObject root2 = JSON.parseObject(text2);
String text3 = (String) root2.get("obj");
// System.out.println(text3);
// {"desc":"\"Puck\""}
JSONObject obj2 = JSON.parseObject(text3);
String puck = (String) obj2.get("desc");
Reported by PMD.
Line: 33
// {"desc":"\"Puck\""}
JSONObject obj2 = JSON.parseObject(text3);
String puck = (String) obj2.get("desc");
Assert.assertEquals(obj.get("desc"), obj2.get("desc"));
// "Puck"
}
}
Reported by PMD.
Line: 33
// {"desc":"\"Puck\""}
JSONObject obj2 = JSON.parseObject(text3);
String puck = (String) obj2.get("desc");
Assert.assertEquals(obj.get("desc"), obj2.get("desc"));
// "Puck"
}
}
Reported by PMD.
Line: 34
JSONObject obj2 = JSON.parseObject(text3);
String puck = (String) obj2.get("desc");
Assert.assertEquals(obj.get("desc"), obj2.get("desc"));
// "Puck"
}
}
Reported by PMD.
Line: 33
// {"desc":"\"Puck\""}
JSONObject obj2 = JSON.parseObject(text3);
String puck = (String) obj2.get("desc");
Assert.assertEquals(obj.get("desc"), obj2.get("desc"));
// "Puck"
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/CurrencyTest3.java
7 issues
Line: 29
money.amount = new BigDecimal("10.03");
String json = JSON.toJSONString(money);
System.out.println("json = " + json);
Money moneyBack = JSON.parseObject(json, Money.class);
System.out.println("money = " + moneyBack);
JSONObject jsonObject = JSON.parseObject(json);
Reported by PMD.
Line: 32
System.out.println("json = " + json);
Money moneyBack = JSON.parseObject(json, Money.class);
System.out.println("money = " + moneyBack);
JSONObject jsonObject = JSON.parseObject(json);
Money moneyCast = JSON.toJavaObject(jsonObject, Money.class);
System.out.printf("money = " + moneyCast);
}
Reported by PMD.
Line: 36
JSONObject jsonObject = JSON.parseObject(json);
Money moneyCast = JSON.toJavaObject(jsonObject, Money.class);
System.out.printf("money = " + moneyCast);
}
}
Reported by PMD.
Line: 14
public class CurrencyTest3 extends TestCase {
public static class Money {
public Currency currency;
public BigDecimal amount;
@Override
public String toString() {
return "Money{currency=" + currency + ", amount=" + amount + '}';
Reported by PMD.
Line: 15
public class CurrencyTest3 extends TestCase {
public static class Money {
public Currency currency;
public BigDecimal amount;
@Override
public String toString() {
return "Money{currency=" + currency + ", amount=" + amount + '}';
}
Reported by PMD.
Line: 23
}
}
public void testJson() throws Exception {
Money money = new Money();
money.currency = Currency.getInstance("CNY");
money.amount = new BigDecimal("10.03");
String json = JSON.toJSONString(money);
Reported by PMD.
Line: 23
}
}
public void testJson() throws Exception {
Money money = new Money();
money.currency = Currency.getInstance("CNY");
money.amount = new BigDecimal("10.03");
String json = JSON.toJSONString(money);
Reported by PMD.
src/test/java/com/alibaba/json/bvt/ShortArrayFieldTest_primitive.java
7 issues
Line: 12
public class ShortArrayFieldTest_primitive extends TestCase {
public void test_array() throws Exception {
Assert.assertEquals("[1]", JSON.toJSONString(new short[] { 1 }));
}
public void test_codec_null() throws Exception {
Reported by PMD.
Line: 17
}
public void test_codec_null() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
Reported by PMD.
Line: 28
V0 v1 = JSON.parseObject(text, V0.class);
Assert.assertEquals(v1.getValue(), v.getValue());
}
public void test_codec_null_1() throws Exception {
V0 v = new V0();
Reported by PMD.
Line: 31
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: 46
private short[] value;
public short[] getValue() {
return value;
}
public void setValue(short[] value) {
this.value = value;
}
Reported by PMD.
Line: 49
return value;
}
public void setValue(short[] value) {
this.value = value;
}
}
}
Reported by PMD.
Line: 49
return value;
}
public void setValue(short[] value) {
this.value = value;
}
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/JSONTest_Bytes.java
7 issues
Line: 13
public class JSONTest_Bytes extends TestCase {
@SuppressWarnings("rawtypes")
public void test_bytes() throws Exception {
for (int i = 0; i < 10; ++i) {
String charset = "UTF-8";
String text = "{name:'张三', age:27}";
Reported by PMD.
Line: 19
String charset = "UTF-8";
String text = "{name:'张三', age:27}";
Map map = JSON.parseObject(text.getBytes(charset), Map.class);
Assert.assertEquals("张三", map.get("name"));
Assert.assertEquals(27, map.get("age"));
}
for (int i = 0; i < 10; ++i) {
Reported by PMD.
Line: 20
String text = "{name:'张三', age:27}";
Map map = JSON.parseObject(text.getBytes(charset), Map.class);
Assert.assertEquals("张三", map.get("name"));
Assert.assertEquals(27, map.get("age"));
}
for (int i = 0; i < 10; ++i) {
String charset = "UTF-8";
Reported by PMD.
Line: 21
Map map = JSON.parseObject(text.getBytes(charset), Map.class);
Assert.assertEquals("张三", map.get("name"));
Assert.assertEquals(27, map.get("age"));
}
for (int i = 0; i < 10; ++i) {
String charset = "UTF-8";
String text = "{name:'张三', age:27}";
Reported by PMD.
Line: 28
String charset = "UTF-8";
String text = "{name:'张三', age:27}";
JSONObject map = (JSONObject) JSON.parse(text.getBytes(charset));
Assert.assertEquals("张三", map.get("name"));
Assert.assertEquals(27, map.get("age"));
}
}
}
Reported by PMD.
Line: 29
String text = "{name:'张三', age:27}";
JSONObject map = (JSONObject) JSON.parse(text.getBytes(charset));
Assert.assertEquals("张三", map.get("name"));
Assert.assertEquals(27, map.get("age"));
}
}
}
Reported by PMD.
Line: 30
JSONObject map = (JSONObject) JSON.parse(text.getBytes(charset));
Assert.assertEquals("张三", map.get("name"));
Assert.assertEquals(27, map.get("age"));
}
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Bug2.java
7 issues
Line: 22
String jsonString = JSON.toJSONString(entity);
System.out.println(jsonString);
Entity entity2 = JSON.parseObject(jsonString, Entity.class);
Assert.assertEquals(entity.getArticles().size(), entity2.getArticles().size());
}
Reported by PMD.
Line: 15
public class Bug2 extends TestCase {
public void test_0() throws Exception {
Entity entity = new Entity();
entity.setArticles(Collections.singletonList(new Article()));
String jsonString = JSON.toJSONString(entity);
Reported by PMD.
Line: 25
System.out.println(jsonString);
Entity entity2 = JSON.parseObject(jsonString, Entity.class);
Assert.assertEquals(entity.getArticles().size(), entity2.getArticles().size());
}
public static class Entity {
private List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
Reported by PMD.
Line: 25
System.out.println(jsonString);
Entity entity2 = JSON.parseObject(jsonString, Entity.class);
Assert.assertEquals(entity.getArticles().size(), entity2.getArticles().size());
}
public static class Entity {
private List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
Reported by PMD.
Line: 25
System.out.println(jsonString);
Entity entity2 = JSON.parseObject(jsonString, Entity.class);
Assert.assertEquals(entity.getArticles().size(), entity2.getArticles().size());
}
public static class Entity {
private List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
Reported by PMD.
Line: 28
Assert.assertEquals(entity.getArticles().size(), entity2.getArticles().size());
}
public static class Entity {
private List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
private List<Article> articles = null;
public List<HashMap<String, String>> getList() {
Reported by PMD.
Line: 31
public static class Entity {
private List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
private List<Article> articles = null;
public List<HashMap<String, String>> getList() {
return list;
}
Reported by PMD.