The following issues were found

src/test/java/com/alibaba/json/bvt/bug/Issue79.java
5 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: 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.

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

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.

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

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.

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

Line: 23

              
    public static class SearchResult {

        public Present present;
    }

    public static class Present {

        public List<PresentRecord> records;

            

Reported by PMD.

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

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
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 17

               * @date 2021/4/17 14:47
 */
public class Issue3638and3067Test {
    JSONObject jo;

    @Before
    public void init() {
        jo = new JSONObject();
    }

            

Reported by PMD.

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

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.

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

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.

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

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.

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

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
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

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.

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

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.

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

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.

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

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.

Private field 'dataToEncode' could be made final; it is only initialized in the declaration or constructor.
Design

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
System.out.println is used
Design

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.

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 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.

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

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.

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

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.

Ensure that resources like this InputStream object are closed after use
Error

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
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 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.

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

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.

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

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.

Avoid unused imports such as 'com.alibaba.fastjson.util.ASMClassLoader'
Design

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.

Found 'DD'-anomaly for variable 'error' (lines '24'-'28').
Error

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
System.out.println is used
Design

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.

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

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.

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

              
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.

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

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.

Avoid using implementation types like 'HashMap'; use the interface instead
Design

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
The String literal '{\n' appears 4 times in this file; the first occurrence is on line 19
Error

Line: 19

              
    @Test
    public void testIssue3493(){
        String json = "{\n" +
                "\"result\": [\n" +
                "{\n" +
                "\"puid\": \"21025318\"\n" +
                "},\n" +
                "{\n" +

            

Reported by PMD.

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

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.

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

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.

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

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.

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

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
System.out.println is used
Design

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.

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

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.

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 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.

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

Line: 27

                  }

    public static class User {
        public String name;
        public long id;

        public User() {

        }

            

Reported by PMD.

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

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
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 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.

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

Line: 22

                      JSON.parse(jsonData);
    }

    static class A {

        private byte[] a;
        private int    b;
        private String c;


            

Reported by PMD.

It is somewhat confusing to have a field name matching the declaring class name
Error

Line: 24

              
    static class A {

        private byte[] a;
        private int    b;
        private String c;

        public byte[] getA() {
            return a;

            

Reported by PMD.

Returning 'a' may expose an internal array.
Design

Line: 29

                      private String c;

        public byte[] getA() {
            return a;
        }

        public void setA(byte[] a) {
            this.a = a;
        }

            

Reported by PMD.

The user-supplied array 'a' is stored directly.
Design

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
Unit tests should not contain more than 1 assert(s).
Design

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.

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

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.

JUnit assertions should include a message
Design

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.

JUnit assertions should include a message
Design

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.

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

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.