The following issues were found

src/test/java/com/alibaba/json/bvt/annotation/CustomSerializerTest.java
4 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: 17

              import junit.framework.TestCase;

public class CustomSerializerTest extends TestCase {
    public void test_0() throws Exception {
        Model model = new Model();
        model.id = 1001;
        String text = JSON.toJSONString(model);
        Assert.assertEquals("{\"ID\":1001}", text);
    }

            

Reported by PMD.

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

Line: 26

                  
    @JSONType(serializer=ModelSerializer.class)
    public static class Model {
        public int id;
    }
    
    public static class ModelSerializer implements ObjectSerializer {

        @Override

            

Reported by PMD.

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

Line: 36

                                        int features) throws IOException {
            Model model = (Model) object;
            SerializeWriter out = serializer.getWriter();
            out.writeFieldValue('{', "ID", model.id);
            out.write('}');
        }
        
    }
}

            

Reported by PMD.

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

Line: 37

                          Model model = (Model) object;
            SerializeWriter out = serializer.getWriter();
            out.writeFieldValue('{', "ID", model.id);
            out.write('}');
        }
        
    }
}

            

Reported by PMD.

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

Line: 13

                  public void test_for_issue() throws Exception {
        String content = "{\"data\":\"sfasfasdfasdfas\\r" + String.valueOf((char) 160) + "\\rasdfasdfasd\"}";
        JSONObject jsonObject = JSON.parseObject(content);
        System.out.println(jsonObject);
    }
}

            

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

              
public class Issue125 extends TestCase {

    public void test_for_issue() throws Exception {
        String content = "{\"data\":\"sfasfasdfasdfas\\r" + String.valueOf((char) 160) + "\\rasdfasdfasd\"}";
        JSONObject jsonObject = JSON.parseObject(content);
        System.out.println(jsonObject);
    }
}

            

Reported by PMD.

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

Line: 10

              
public class Issue125 extends TestCase {

    public void test_for_issue() throws Exception {
        String content = "{\"data\":\"sfasfasdfasdfas\\r" + String.valueOf((char) 160) + "\\rasdfasdfasd\"}";
        JSONObject jsonObject = JSON.parseObject(content);
        System.out.println(jsonObject);
    }
}

            

Reported by PMD.

No need to call String.valueOf to append to a string.
Performance

Line: 11

              public class Issue125 extends TestCase {

    public void test_for_issue() throws Exception {
        String content = "{\"data\":\"sfasfasdfasdfas\\r" + String.valueOf((char) 160) + "\\rasdfasdfasd\"}";
        JSONObject jsonObject = JSON.parseObject(content);
        System.out.println(jsonObject);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Mogujie_02.java
4 issues
This class has a bunch of public methods and attributes
Design

Line: 1

              package com.alibaba.json.bvt.bug;

import com.alibaba.fastjson.JSON;
import junit.framework.TestCase;

/**
 * Created by wenshao on 16/03/2017.
 */
public class Mogujie_02 extends TestCase {

            

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

               * Created by wenshao on 16/03/2017.
 */
public class Mogujie_02 extends TestCase {
    public void test_for_issue() throws Exception {
        JSON.parseObject("{}", Model.class);


    }
    public static class Model {

            

Reported by PMD.

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

Line: 10

               * Created by wenshao on 16/03/2017.
 */
public class Mogujie_02 extends TestCase {
    public void test_for_issue() throws Exception {
        JSON.parseObject("{}", Model.class);


    }
    public static class Model {

            

Reported by PMD.

Too many fields
Design

Line: 15

              

    }
    public static class Model {
        public int f0;
        public int f1;
        public int f2;
        public int f3;
        public int f4;

            

Reported by PMD.

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

Line: 14

              
        Parser parser = JSON.parseObject(jsonStr, Parser.class);

        System.out.println(JSON.toJSONString(parser));
    }

    public static class Parser {

        public int    state;

            

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

    public void test_bug() throws Exception {
        String jsonStr = "{\"state\":0,\"data\":[{\"items\":[{\"tip\":\"\u5218\u82e5\u82f1\",\"url\":\"xiami:\\/\\/artist\\/1930\"},{\"tip\":\"\u5218\u5fb7\u534e\",\"url\":\"xiami:\\/\\/artist\\/648\"}],\"type\":\"artist\"},{\"items\":[{\"tip\":\"\u6f02\u6d0b\u8fc7\u6d77\u6765\u770b\u4f60 (Live) - \u5218\u660e\u6e58\",\"url\":\"xiami:\\/\\/song\\/1773431302\"},{\"tip\":\"\\u6211\\u4eec\\u6ca1\\u6709\\u5728\\u4e00\\u8d77 - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/song\\/1769471863\"},{\"tip\":\"\\u54ed\u7802 (Live)(\\u5218\\u660e\\u6e58\\u80dc\\u51fa) - \\u5218\u660e\u6e58\",\"url\":\"xiami:\\/\\/ song\\/1773484887\"}],\"type\":\"song\"},{\"items\":[{\"tip\":\"\\u4eb2\\u7231\\u7684\\u8def\\u4eba - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/album\\/55230\"},{\"tip\":\"\\u5728\\u4e00\\u8d77 - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/album\\/377241\"}],\"type\":\"album\"}],\"status\":\"ok\",\"err\":null} ";

        Parser parser = JSON.parseObject(jsonStr, Parser.class);

        System.out.println(JSON.toJSONString(parser));

            

Reported by PMD.

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

Line: 9

              
public class Bug_for_json_array extends TestCase {

    public void test_bug() throws Exception {
        String jsonStr = "{\"state\":0,\"data\":[{\"items\":[{\"tip\":\"\u5218\u82e5\u82f1\",\"url\":\"xiami:\\/\\/artist\\/1930\"},{\"tip\":\"\u5218\u5fb7\u534e\",\"url\":\"xiami:\\/\\/artist\\/648\"}],\"type\":\"artist\"},{\"items\":[{\"tip\":\"\u6f02\u6d0b\u8fc7\u6d77\u6765\u770b\u4f60 (Live) - \u5218\u660e\u6e58\",\"url\":\"xiami:\\/\\/song\\/1773431302\"},{\"tip\":\"\\u6211\\u4eec\\u6ca1\\u6709\\u5728\\u4e00\\u8d77 - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/song\\/1769471863\"},{\"tip\":\"\\u54ed\u7802 (Live)(\\u5218\\u660e\\u6e58\\u80dc\\u51fa) - \\u5218\u660e\u6e58\",\"url\":\"xiami:\\/\\/ song\\/1773484887\"}],\"type\":\"song\"},{\"items\":[{\"tip\":\"\\u4eb2\\u7231\\u7684\\u8def\\u4eba - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/album\\/55230\"},{\"tip\":\"\\u5728\\u4e00\\u8d77 - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/album\\/377241\"}],\"type\":\"album\"}],\"status\":\"ok\",\"err\":null} ";

        Parser parser = JSON.parseObject(jsonStr, Parser.class);

        System.out.println(JSON.toJSONString(parser));

            

Reported by PMD.

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

Line: 17

                      System.out.println(JSON.toJSONString(parser));
    }

    public static class Parser {

        public int    state;
        public JSON   data;
        public String status;
        public String err;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/JSONObjectFluentTest.java
4 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 JSONObjectFluentTest extends TestCase {

    public void test_fluent() throws Exception {
        JSONObject object = new JSONObject() //
                                             .fluentPut("1", 1001) //
                                             .fluentPut("2", 1002);

        Assert.assertEquals(2, object.size());

            

Reported by PMD.

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

Line: 20

              
        Assert.assertEquals(2, object.size());

        object.fluentPutAll(Collections.singletonMap("3", 1003)) //
              .fluentPutAll(Collections.singletonMap("4", 1004));

        Assert.assertEquals(4, object.size());

        object.fluentRemove("1") //

            

Reported by PMD.

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

Line: 25

              
        Assert.assertEquals(4, object.size());

        object.fluentRemove("1") //
              .fluentRemove("2");
        
        Assert.assertEquals(2, object.size());
        
        object.fluentClear().fluentClear();

            

Reported by PMD.

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

Line: 30

                      
        Assert.assertEquals(2, object.size());
        
        object.fluentClear().fluentClear();
        
        Assert.assertEquals(0, object.size());
    }

}

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/support/spring/FastJsonRedisSerializer.java
4 issues
Private field 'type' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 17

               */
public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
    private FastJsonConfig fastJsonConfig = new FastJsonConfig();
    private Class<T> type;

    public FastJsonRedisSerializer(Class<T> type) {
        this.type = type;
    }


            

Reported by PMD.

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

Line: 17

               */
public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
    private FastJsonConfig fastJsonConfig = new FastJsonConfig();
    private Class<T> type;

    public FastJsonRedisSerializer(Class<T> type) {
        this.type = type;
    }


            

Reported by PMD.

Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 46

                                  JSON.DEFAULT_GENERATE_FEATURE,
                    fastJsonConfig.getSerializerFeatures()
            );
        } catch (Exception ex) {
            throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);
        }
    }

    @Override

            

Reported by PMD.

Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 66

                                  JSON.DEFAULT_PARSER_FEATURE,
                    fastJsonConfig.getFeatures()
            );
        } catch (Exception ex) {
            throw new SerializationException("Could not deserialize: " + ex.getMessage(), ex);
        }
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/MaterializedInterfaceTest2.java
4 issues
System.out.println is used
Design

Line: 22

                      Assert.assertEquals("chris", bean.getName());
        
        String text2 = JSON.toJSONString(bean);
        System.out.println(text2);
    }

    public static interface Bean {
        int getId();


            

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 MaterializedInterfaceTest2 extends TestCase {
    
    public void test_parse() throws Exception {
        String text = "{\"id\":123, \"name\":\"chris\"}";
        JSONObject object = JSON.parseObject(text);
        
        Bean bean = TypeUtils.cast(object, Bean.class, null);
        

            

Reported by PMD.

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

Line: 18

                      
        Bean bean = TypeUtils.cast(object, Bean.class, null);
        
        Assert.assertEquals(123, bean.getId());
        Assert.assertEquals("chris", bean.getName());
        
        String text2 = JSON.toJSONString(bean);
        System.out.println(text2);
    }

            

Reported by PMD.

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

Line: 19

                      Bean bean = TypeUtils.cast(object, Bean.class, null);
        
        Assert.assertEquals(123, bean.getId());
        Assert.assertEquals("chris", bean.getName());
        
        String text2 = JSON.toJSONString(bean);
        System.out.println(text2);
    }


            

Reported by PMD.

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

Line: 18

                      testPOJO.setA("a");
        testPOJO.setB(new BigDecimal("1234512312312312312312"));
        String s = JSON.toJSONString(testPOJO);
        System.out.println(s);
        
        TestPOJO vo2 = JSON.parseObject(s, TestPOJO.class, Feature.UseBigDecimal);
        Assert.assertEquals(testPOJO.getB(), vo2.getB());
    }


            

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

              import junit.framework.TestCase;

public class Bug_for_Issue_535 extends TestCase {
    public void test_for_issue() throws Exception {
        TestPOJO testPOJO = new TestPOJO();
        testPOJO.setA("a");
        testPOJO.setB(new BigDecimal("1234512312312312312312"));
        String s = JSON.toJSONString(testPOJO);
        System.out.println(s);

            

Reported by PMD.

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

Line: 21

                      System.out.println(s);
        
        TestPOJO vo2 = JSON.parseObject(s, TestPOJO.class, Feature.UseBigDecimal);
        Assert.assertEquals(testPOJO.getB(), vo2.getB());
    }

    public static class TestPOJO {

        private String     a;

            

Reported by PMD.

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

Line: 24

                      Assert.assertEquals(testPOJO.getB(), vo2.getB());
    }

    public static class TestPOJO {

        private String     a;
        private BigDecimal b;
        // getter and setter


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue1074.java
4 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: 10

               * Created by wenshao on 16/03/2017.
 */
public class Issue1074 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "//123456";
        Throwable error = null;
        try {
            JSON.parse(json);
        } catch (Exception ex) {

            

Reported by PMD.

Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 15

                      Throwable error = null;
        try {
            JSON.parse(json);
        } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }
}

            

Reported by PMD.

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

Line: 12

              public class Issue1074 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "//123456";
        Throwable error = null;
        try {
            JSON.parse(json);
        } catch (Exception ex) {
            error = ex;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_555_setter2.java
4 issues
JUnit tests should include assert() or fail()
Design

Line: 12

              
public class Bug_for_issue_555_setter2 extends TestCase {

    public void test_for_issue() throws Exception {
        JSON.parseObject("{\"list\":[{\"spec\":{}}]}", A.class);
    }

    public static class A {


            

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

    public void test_for_issue() throws Exception {
        JSON.parseObject("{\"list\":[{\"spec\":{}}]}", A.class);
    }

    public static class A {


            

Reported by PMD.

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

Line: 39

              
    public static class Spec {

        private int id;

        public Spec(int id){
            this.id = id;
        }
    }

            

Reported by PMD.

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

Line: 39

              
    public static class Spec {

        private int id;

        public Spec(int id){
            this.id = id;
        }
    }

            

Reported by PMD.