The following issues were found

src/test/java/com/alibaba/fastjson/deserializer/issue2358/TestJson.java
3 issues
System.out.println is used
Design

Line: 62

                              "   \"test2\":\"2\"\n" +
                " }]";
        List<TestJson2> testJsons = JSONObject.parseArray(str, TestJson2.class);
        System.out.println(testJsons);
    }
}

            

Reported by PMD.

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

Line: 10

              /**
 * Created by liangchuyi on 2019/4/8.
 */
public class TestJson {

    private String test1;
    private String test2;

    public String getTest1() {

            

Reported by PMD.

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

Line: 31

                      this.test2 = test2;
    }

    class TestJson2 {
        private String test1;
        private String test2;

        public String getTest1() {
            return test1;

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/util/ThreadLocalCache.java
3 issues
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: 9

              /**
 * @deprecated
 */
public class ThreadLocalCache {

    public final static int                                 CHARS_CACH_INIT_SIZE = 1024;                                    // 1k, 2^10;
    public final static int 								CHARS_CACH_INIT_SIZE_EXP = 10;
    public final static int                                 CHARS_CACH_MAX_SIZE  = 1024 * 128;                              // 128k, 2^17;
    public final static int 								CHARS_CACH_MAX_SIZE_EXP = 17;

            

Reported by PMD.

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

Line: 39

                          return allocate(length);
        }

        char[] chars = ref.get();

        if (chars == null) {
            return allocate(length);
        }


            

Reported by PMD.

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

Line: 94

                          return allocateBytes(length);
        }

        byte[] bytes = ref.get();

        if (bytes == null) {
            return allocateBytes(length);
        }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/FastJsonSerializeIterableTest.java
3 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 17

                  @Test
    public void testWithIterable() {
        class Person {
            private String name;
            public Person(String s) {
                this.name = s;
            }
            public String getName() {
                return name;

            

Reported by PMD.

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

Line: 17

                  @Test
    public void testWithIterable() {
        class Person {
            private String name;
            public Person(String s) {
                this.name = s;
            }
            public String getName() {
                return name;

            

Reported by PMD.

Avoid using redundant field initializer for 'cursor'
Performance

Line: 31

                          @Override
            public Iterator<Person> iterator() {
                return new Iterator<Person>() {
                    int cursor = 0;
                    @Override
                    public boolean hasNext() {
                        return cursor < 2;
                    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue1036.java
3 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

                   * @see BeanToArrayTest3_private#test_array()
     * @see com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer#parseField
     * */
    public void test_for_issue() throws Exception {
        NullPointerException exception = new NullPointerException("test");
        Result<String> result = new Result<String>();
        result.setException(exception);

        String json = JSON.toJSONString(result);

            

Reported by PMD.

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

Line: 28

                      Result<String> a = JSON.parseObject(json, new TypeReference<Result<String>>() {
        });

        Assert.assertEquals("test", a.getException().getMessage());
    }

    public static class Result<T> {
        private T data;


            

Reported by PMD.

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

Line: 31

                      Assert.assertEquals("test", a.getException().getMessage());
    }

    public static class Result<T> {
        private T data;

        private Throwable exception;

        public Result() {

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/support/spring/FastJsonViewResponseBodyAdvice.java
3 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 46

                                                         MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {
        FastJsonView annotation = returnType.getMethodAnnotation(FastJsonView.class);

        FastJsonFilter[] include = annotation.include();
        FastJsonFilter[] exclude = annotation.exclude();
        PropertyPreFilters filters = new PropertyPreFilters();
        for (FastJsonFilter item : include) {
            filters.addFilter(item.clazz(),item.props());
        }

            

Reported by PMD.

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

Line: 47

                      FastJsonView annotation = returnType.getMethodAnnotation(FastJsonView.class);

        FastJsonFilter[] include = annotation.include();
        FastJsonFilter[] exclude = annotation.exclude();
        PropertyPreFilters filters = new PropertyPreFilters();
        for (FastJsonFilter item : include) {
            filters.addFilter(item.clazz(),item.props());
        }
        for (FastJsonFilter item : exclude) {

            

Reported by PMD.

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

Line: 53

                          filters.addFilter(item.clazz(),item.props());
        }
        for (FastJsonFilter item : exclude) {
            filters.addFilter(item.clazz()).addExcludes(item.props());
        }
        container.setFilters(filters);
    }
}

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/parser/Feature.java
3 issues
Avoid reassigning parameters such as 'features'
Design

Line: 170

                      return (features & feature.mask) != 0;
    }

    public static int config(int features, Feature feature, boolean state) {
        if (state) {
            features |= feature.mask;
        } else {
            features &= ~feature.mask;
        }

            

Reported by PMD.

Avoid reassigning parameters such as 'features'
Design

Line: 170

                      return (features & feature.mask) != 0;
    }

    public static int config(int features, Feature feature, boolean state) {
        if (state) {
            features |= feature.mask;
        } else {
            features &= ~feature.mask;
        }

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 180

                      return features;
    }
    
    public static int of(Feature[] features) {
        if (features == null) {
            return 0;
        }
        
        int value = 0;

            

Reported by PMD.

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

Line: 13

                      JSONObject j = new JSONObject();
        j.put("content",
              "爸爸去哪儿-第十期-萌娃比赛小猪快跑 爸爸上演\"百变大咖秀\"-【湖南卫视官方版1080P】20131213: http://youtu.be/ajvaXKAduJ4  via @youtube");
        System.out.println(j.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: 9

              
public class Issue126 extends TestCase {

    public void test_for_issue() throws Exception {
        JSONObject j = new JSONObject();
        j.put("content",
              "爸爸去哪儿-第十期-萌娃比赛小猪快跑 爸爸上演\"百变大咖秀\"-【湖南卫视官方版1080P】20131213: http://youtu.be/ajvaXKAduJ4  via @youtube");
        System.out.println(j.toJSONString());
    }

            

Reported by PMD.

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

Line: 9

              
public class Issue126 extends TestCase {

    public void test_for_issue() throws Exception {
        JSONObject j = new JSONObject();
        j.put("content",
              "爸爸去哪儿-第十期-萌娃比赛小猪快跑 爸爸上演\"百变大咖秀\"-【湖南卫视官方版1080P】20131213: http://youtu.be/ajvaXKAduJ4  via @youtube");
        System.out.println(j.toJSONString());
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue1296.java
3 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: 11

               * Created by wenshao on 02/07/2017.
 */
public class Issue1296 extends TestCase {
    public void test_for_issue() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("1");
        } catch (JSONException e) {
            error = e;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      } catch (JSONException e) {
            error = e;
        }
        assertNotNull(error);
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '12'-'16').
Error

Line: 12

               */
public class Issue1296 extends TestCase {
    public void test_for_issue() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("1");
        } catch (JSONException e) {
            error = e;
        }

            

Reported by PMD.

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

Line: 14

                      JSONObject json = new JSONObject();
        json.put("介绍", m);
        String content = json.toJSONString();
        System.out.println(content);
    }
}

            

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: 9

              

public class Issue157 extends TestCase {
    public void test_for_issue() throws Exception {
        String m = "2、95开头靓号,呼出显号,对方可以打回,即使不在线亦可设置呼转手机,不错过任何重要电话,不暴露真实身份。\r\n3、应用内完全免费发送文字消息、语音对讲。\r\n4、建议WIFI 或 3G 环境下使用以获得最佳通话体验";
        JSONObject json = new JSONObject();
        json.put("介绍", m);
        String content = json.toJSONString();
        System.out.println(content);

            

Reported by PMD.

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

Line: 9

              

public class Issue157 extends TestCase {
    public void test_for_issue() throws Exception {
        String m = "2、95开头靓号,呼出显号,对方可以打回,即使不在线亦可设置呼转手机,不错过任何重要电话,不暴露真实身份。\r\n3、应用内完全免费发送文字消息、语音对讲。\r\n4、建议WIFI 或 3G 环境下使用以获得最佳通话体验";
        JSONObject json = new JSONObject();
        json.put("介绍", m);
        String content = json.toJSONString();
        System.out.println(content);

            

Reported by PMD.

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

Line: 16

                      Map m = new HashMap();
        m.put("a", "\u000B");
        String json = JSON.toJSONString(m);
        System.out.println(json);
        JSON.parse(json);
    }
}

            

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 Issue171 extends TestCase {

    public void test_for_issue() throws Exception {
        Map m = new HashMap();
        m.put("a", "\u000B");
        String json = JSON.toJSONString(m);
        System.out.println(json);
        JSON.parse(json);

            

Reported by PMD.

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

Line: 12

              
public class Issue171 extends TestCase {

    public void test_for_issue() throws Exception {
        Map m = new HashMap();
        m.put("a", "\u000B");
        String json = JSON.toJSONString(m);
        System.out.println(json);
        JSON.parse(json);

            

Reported by PMD.