The following issues were found

src/test/java/com/alibaba/json/bvt/path/JSONPath_12.java
10 issues
System.out.println is used
Design

Line: 44

              
        assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

System.out.println is used
Design

Line: 45

                      assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 12

              public class JSONPath_12
        extends TestCase {

    public void test(){
        JSONObject schemaResult = JSON.parseObject("{\n" +
                "  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n" +
                "  \"title\": \"AE product schema\",\n" +
                "  \"description\": \"AE product schema\",\n" +
                "  \"type\": \"object\",\n" +

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 12

              public class JSONPath_12
        extends TestCase {

    public void test(){
        JSONObject schemaResult = JSON.parseObject("{\n" +
                "  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n" +
                "  \"title\": \"AE product schema\",\n" +
                "  \"description\": \"AE product schema\",\n" +
                "  \"type\": \"object\",\n" +

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 38

                              "  \"title\": \"Brand Name\",\n" +
                "  \"type\": \"String\"\n" +
                "}");
        assertTrue(
                JSONPath.set(schemaResult, jsonPath + "['" + attributeName + "']" , attributeValue)
        );

        assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 42

                              JSONPath.set(schemaResult, jsonPath + "['" + attributeName + "']" , attributeValue)
        );

        assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 45

                      assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 46

                      JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

                      JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONArray'
Design

Line: 4

              package com.alibaba.json.bvt.path;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import junit.framework.TestCase;

public class JSONPath_12

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/JSONLibDataFormatSerializer.java
10 issues
Potential violation of Law of Demeter (static property access)
Design

Line: 17

                  @SuppressWarnings("deprecation")
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    	if (object == null) {
    		serializer.out.writeNull();
    		return;
    	}
    	
        Date date = (Date) object;
       

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 24

                      Date date = (Date) object;
       
        JSONObject json = new JSONObject();
        json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 25

                     
        JSONObject json = new JSONObject();
        json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 26

                      JSONObject json = new JSONObject();
        json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 27

                      json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 28

                      json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 29

                      json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

        serializer.write(json);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 30

                      json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

        serializer.write(json);
    }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 31

                      json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

        serializer.write(json);
    }
}

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 32

                      json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

        serializer.write(json);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/path/JSONPath_14.java
10 issues
System.out.println is used
Design

Line: 32

              
        // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));
        assertEquals(10, paths.size());

        JSONObject destJson = JSON.parseObject("{\n" +
                "\t\"boolean1\":true,\n" +
                "\t\"boolean2\":false,\n" +

            

Reported by PMD.

System.out.println is used
Design

Line: 47

                          }
            if (!JSONPath.contains(destJson, stringObjectEntry.getKey())) {
                JSONPath.set(destJson, stringObjectEntry.getKey(), stringObjectEntry.getValue());
                System.out.println("key=" + stringObjectEntry.getKey() + " ,value=" + stringObjectEntry.getValue());
            }
        }

        System.out.println(destJson.toJSONString());
    }

            

Reported by PMD.

System.out.println is used
Design

Line: 51

                          }
        }

        System.out.println(destJson.toJSONString());
    }


}

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 16

              public class JSONPath_14
        extends TestCase {

    public void test_0() {
        JSONObject sourceJson = JSON.parseObject("{\n" +
                "\t\"boolean1\":true,\n" +
                "\t\"boolean2\":false,\n" +
                "\t\"boolean3\":true,\n" +
                "\t\"boolean4\":true,\n" +

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 26

                              "\t\"name1\":\"str\"\n" +
                "}");

        sourceJson.put("enum1", TimeUnit.SECONDS);
        sourceJson.put("character1", 'A');
        sourceJson.put("uuid1", UUID.randomUUID());

        // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 27

                              "}");

        sourceJson.put("enum1", TimeUnit.SECONDS);
        sourceJson.put("character1", 'A');
        sourceJson.put("uuid1", UUID.randomUUID());

        // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 28

              
        sourceJson.put("enum1", TimeUnit.SECONDS);
        sourceJson.put("character1", 'A');
        sourceJson.put("uuid1", UUID.randomUUID());

        // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));
        assertEquals(10, paths.size());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                      // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));
        assertEquals(10, paths.size());

        JSONObject destJson = JSON.parseObject("{\n" +
                "\t\"boolean1\":true,\n" +
                "\t\"boolean2\":false,\n" +
                "\t\"name\":\"str\"\n" +

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 33

                      // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));
        assertEquals(10, paths.size());

        JSONObject destJson = JSON.parseObject("{\n" +
                "\t\"boolean1\":true,\n" +
                "\t\"boolean2\":false,\n" +
                "\t\"name\":\"str\"\n" +

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 51

                          }
        }

        System.out.println(destJson.toJSONString());
    }


}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_256.java
10 issues
System.out.println is used
Design

Line: 42

              
        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }
    
    public static class AisleDeployInfo {

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 17

              
public class Bug_for_issue_256 extends TestCase {

    public void test_for_issue() throws Exception {
        List<AisleDeployInfo> list3 = new ArrayList<AisleDeployInfo>();
        AisleDeployInfo aisleDeployInfo = new AisleDeployInfo();
        aisleDeployInfo.setId(1L);
        aisleDeployInfo.setProvinceArea("3,4,5");
        list3.add(aisleDeployInfo);

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 17

              
public class Bug_for_issue_256 extends TestCase {

    public void test_for_issue() throws Exception {
        List<AisleDeployInfo> list3 = new ArrayList<AisleDeployInfo>();
        AisleDeployInfo aisleDeployInfo = new AisleDeployInfo();
        aisleDeployInfo.setId(1L);
        aisleDeployInfo.setProvinceArea("3,4,5");
        list3.add(aisleDeployInfo);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 40

                      Map<String, List<AisleDeployInfo>> map1 = JSON.parseObject(str, new TypeReference<Map<String, List<AisleDeployInfo>>>(){});
        List<AisleDeployInfo> aList = map1.get("1");

        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 40

                      Map<String, List<AisleDeployInfo>> map1 = JSON.parseObject(str, new TypeReference<Map<String, List<AisleDeployInfo>>>(){});
        List<AisleDeployInfo> aList = map1.get("1");

        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }

            

Reported by PMD.

This for loop can be replaced by a foreach loop
Design

Line: 41

                      List<AisleDeployInfo> aList = map1.get("1");

        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }
    

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 42

              
        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }
    
    public static class AisleDeployInfo {

            

Reported by PMD.

The class 'AisleDeployInfo' is suspected to be a Data Class (WOC=0.000%, NOPA=0, NOAM=4, WMC=4)
Design

Line: 47

                      }
    }
    
    public static class AisleDeployInfo {
        private long id;
        private String provinceArea;
        
        public long getId() {
            return id;

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 75

                      
    }

    public static class Model extends HashMap {

    }
}

            

Reported by PMD.

Avoid unused imports such as 'org.junit.Assert'
Design

Line: 8

              import java.util.List;
import java.util.Map;

import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import junit.framework.TestCase;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue1017.java
10 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 13

               * Created by wenshao on 11/02/2017.
 */
public class Issue1017 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 13

               * Created by wenshao on 11/02/2017.
 */
public class Issue1017 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 18

              
        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 19

                      User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 20

                      assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 23

                      assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {
            return pictureList;
        }
        public User setPictureList(List<String> pictureList) {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1300/Issue1300.java
10 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 14

               * Created by wenshao on 01/07/2017.
 */
public class Issue1300 extends TestCase {
    public void testFullJSON() {
        JSONObject data = new JSONObject();
        data.put("name", "string");
        data.put("code", 1);
        data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 14

               * Created by wenshao on 01/07/2017.
 */
public class Issue1300 extends TestCase {
    public void testFullJSON() {
        JSONObject data = new JSONObject();
        data.put("name", "string");
        data.put("code", 1);
        data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);

            

Reported by PMD.

The String literal 'pinyin' appears 4 times in this file; the first occurrence is on line 18
Error

Line: 18

                      JSONObject data = new JSONObject();
        data.put("name", "string");
        data.put("code", 1);
        data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);
        assertEquals("string", object.name);
        assertEquals(1, object.code);
        assertEquals("pinyin", object.pinyin);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      data.put("code", 1);
        data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);
        assertEquals("string", object.name);
        assertEquals(1, object.code);
        assertEquals("pinyin", object.pinyin);
    }

    public void testEmptyJSON() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);
        assertEquals("string", object.name);
        assertEquals(1, object.code);
        assertEquals("pinyin", object.pinyin);
    }

    public void testEmptyJSON() {
        City object = TypeUtils.castToJavaBean(new JSONObject(), City.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      City object = TypeUtils.castToJavaBean(data, City.class);
        assertEquals("string", object.name);
        assertEquals(1, object.code);
        assertEquals("pinyin", object.pinyin);
    }

    public void testEmptyJSON() {
        City object = TypeUtils.castToJavaBean(new JSONObject(), City.class);
        Assert.assertEquals(null, object.name);

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 25

                      assertEquals("pinyin", object.pinyin);
    }

    public void testEmptyJSON() {
        City object = TypeUtils.castToJavaBean(new JSONObject(), City.class);
        Assert.assertEquals(null, object.name);
        Assert.assertEquals(0, object.code);
    }


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 33

              

    public static class City implements Parcelable {
        public final int code;
        public final String name;
        public final String pinyin;

        @JSONCreator
        public City(@JSONField(name = "code") int code,

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 34

              
    public static class City implements Parcelable {
        public final int code;
        public final String name;
        public final String pinyin;

        @JSONCreator
        public City(@JSONField(name = "code") int code,
                    @JSONField(name = "name") String name,

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 35

                  public static class City implements Parcelable {
        public final int code;
        public final String name;
        public final String pinyin;

        @JSONCreator
        public City(@JSONField(name = "code") int code,
                    @JSONField(name = "name") String name,
                    @JSONField(name = "pinyin") String pinyin) {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Set2.java
10 issues
System.out.println is used
Design

Line: 26

                      set.add(new B1());
        a.setList(set);
        String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
        System.out.println(text);
//        Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2$A\",\"list\":[{},{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2$B1\"}]}",
//                            text);

        ParserConfig parserConfig = new ParserConfig();
        parserConfig.addAccept("com.alibaba.json.bvt");

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 15

              import com.alibaba.fastjson.serializer.SerializerFeature;

public class WriteClassNameTest_Set2 extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2");
    }

    public void test_list() throws Exception {
        A a = new A();

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 16

              
public class WriteClassNameTest_Set2 extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2");
    }

    public void test_list() throws Exception {
        A a = new A();
        Set<B> set = new LinkedHashSet<B>();

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 19

                      ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2");
    }

    public void test_list() throws Exception {
        A a = new A();
        Set<B> set = new LinkedHashSet<B>();
        set.add(new B());
        set.add(new B1());
        a.setList(set);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 34

                      parserConfig.addAccept("com.alibaba.json.bvt");
        A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 34

                      parserConfig.addAccept("com.alibaba.json.bvt");
        A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 35

                      A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 35

                      A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 36

              
        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

        private Set<B> list;

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 36

              
        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

        private Set<B> list;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/InetAddressDeserializerTest.java
10 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 15

              
public class InetAddressDeserializerTest extends TestCase {

    public void test_null() throws Exception {
        String input = "null";
        DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);

        MiscCodec deser = new MiscCodec();


            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 24

                      Assert.assertNull(deser.deserialze(parser, null, null));
    }
    
    public void test_string_null() throws Exception {
        String input = "null";
        DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
        
        StringCodec deser = new StringCodec();
        

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 33

                      Assert.assertNull(deser.deserialze(parser, null, null));
    }

    public void test_error_0() throws Exception {
        String input = "'[&中国-^]'";
        DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);

        MiscCodec deser = new MiscCodec();


            

Reported by PMD.

The initializer for variable 'value' is never used (overwritten on line 43)
Design

Line: 41

              
        Throwable error = null;

        Object value = null;
        try {
            value = deser.deserialze(parser, null, null);
        } catch (Throwable ex) {
            error = ex;
        }

            

Reported by PMD.

Avoid unused local variables such as 'value'.
Design

Line: 41

              
        Throwable error = null;

        Object value = null;
        try {
            value = deser.deserialze(parser, null, null);
        } catch (Throwable ex) {
            error = ex;
        }

            

Reported by PMD.

The value assigned to variable 'value' is never used
Design

Line: 43

              
        Object value = null;
        try {
            value = deser.deserialze(parser, null, null);
        } catch (Throwable ex) {
            error = ex;
        }

        Assert.assertNotNull(error);

            

Reported by PMD.

A catch statement should never catch throwable since it includes errors.
Error

Line: 44

                      Object value = null;
        try {
            value = deser.deserialze(parser, null, null);
        } catch (Throwable ex) {
            error = ex;
        }

        Assert.assertNotNull(error);
    }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '39'-'45').
Error

Line: 39

              
        MiscCodec deser = new MiscCodec();

        Throwable error = null;

        Object value = null;
        try {
            value = deser.deserialze(parser, null, null);
        } catch (Throwable ex) {

            

Reported by PMD.

Found 'DD'-anomaly for variable 'value' (lines '41'-'43').
Error

Line: 41

              
        Throwable error = null;

        Object value = null;
        try {
            value = deser.deserialze(parser, null, null);
        } catch (Throwable ex) {
            error = ex;
        }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'value' (lines '43'-'49').
Error

Line: 43

              
        Object value = null;
        try {
            value = deser.deserialze(parser, null, null);
        } catch (Throwable ex) {
            error = ex;
        }

        Assert.assertNotNull(error);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/SpecialTest.java
10 issues
System.out.println is used
Design

Line: 16

                              count++;
            }
        }
        System.out.println(count);
    }
    
    final static long flags;
    static {
        long val = 0L;

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 5

              
import com.alibaba.fastjson.serializer.SerializerFeature;

public class SpecialTest {
    
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 7

              
public class SpecialTest {
    
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 28

                  }
    
    static boolean isSpecial(char ch) {
        if (ch <= 31) {
            return true;
        }
        
        if (ch > '\\') { // 92
            return false;

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 32

                          return true;
        }
        
        if (ch > '\\') { // 92
            return false;
        }
        
        return ((1L << (ch - 31)) & flags) != 0;
    }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 44

                      // return false;
        // }
        
        if (ch == ' ') { // 32
            return false;
        }

        if (ch == '/') { // 47
            return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 48

                          return false;
        }

        if (ch == '/') { // 47
            return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);
        }

        if (ch > '#' // 35
            && ch != '\\' // 92

            

Reported by PMD.

Avoid unnecessary if..then..else statements when returning booleans
Design

Line: 58

                          return false;
        }

        if (ch <= 0x1F // 31
                || ch == '\\' // 92
                || ch == '"' // 34
                ) {
            return true;
        }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'count' (lines '9'-'13').
Error

Line: 9

                  
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {
                count++;
            }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'count' (lines '13'-'13').
Error

Line: 13

                      for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {
                count++;
            }
        }
        System.out.println(count);
    }
    

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2300/Issue2343.java
10 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 9

              import junit.framework.TestCase;

public class Issue2343 extends TestCase {
    public void test_for_issue() throws Exception {
        A a = new A();
        a.f1 = 101;
        a.f2 = 102;
        a.f3 = 103;


            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 9

              import junit.framework.TestCase;

public class Issue2343 extends TestCase {
    public void test_for_issue() throws Exception {
        A a = new A();
        a.f1 = 101;
        a.f2 = 102;
        a.f3 = 103;


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      a.f3 = 103;

        String str = JSON.toJSONString(a);
        assertEquals("{\"f2\":102,\"f1\":101,\"f3\":103}", str);

        JSONObject object = JSON.parseObject(str);
        A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 19

                      assertEquals("{\"f2\":102,\"f1\":101,\"f3\":103}", str);

        JSONObject object = JSON.parseObject(str);
        A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);
        assertEquals(a.f3, a1.f3);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        JSONObject object = JSON.parseObject(str);
        A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);
        assertEquals(a.f3, a1.f3);
    }

    public static class A {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      JSONObject object = JSON.parseObject(str);
        A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);
        assertEquals(a.f3, a1.f3);
    }

    public static class A {
        @JSONField(ordinal = 1)

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);
        assertEquals(a.f3, a1.f3);
    }

    public static class A {
        @JSONField(ordinal = 1)
        public int f1;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 27

              
    public static class A {
        @JSONField(ordinal = 1)
        public int f1;

        @JSONField(ordinal = 0)
        public int f2;

        @JSONField(ordinal = 2)

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 30

                      public int f1;

        @JSONField(ordinal = 0)
        public int f2;

        @JSONField(ordinal = 2)
        public int f3;
    }
}

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 33

                      public int f2;

        @JSONField(ordinal = 2)
        public int f3;
    }
}

            

Reported by PMD.