The following issues were found

src/test/java/com/alibaba/json/bvt/LongFieldTest_4_stream.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: 19

              
public class LongFieldTest_4_stream extends TestCase {

    public void test_min() throws Exception {
        Random random = new Random();
        Model[] array = new Model[2048];
        for (int i = 0; i < array.length; ++i) {
            array[i] = new Model();
            array[i].value = random.nextLong();

            

Reported by PMD.

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

Line: 42

                  @JSONType(serialzeFeatures = SerializerFeature.BeanToArray, parseFeatures = Feature.SupportArrayToBean)
    public static class Model {

        public long value;

    }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'random' (lines '20'-'37').
Error

Line: 20

              public class LongFieldTest_4_stream extends TestCase {

    public void test_min() throws Exception {
        Random random = new Random();
        Model[] array = new Model[2048];
        for (int i = 0; i < array.length; ++i) {
            array[i] = new Model();
            array[i].value = random.nextLong();
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/BigDecimalFieldTest.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: 14

              
public class BigDecimalFieldTest extends TestCase {

    public void test_codec_null() throws Exception {
        V0 v = new V0();

        SerializeConfig mapping = new SerializeConfig();
        mapping.setAsmEnable(false);


            

Reported by PMD.

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

Line: 25

              
        V0 v1 = JSON.parseObject(text, V0.class);

        Assert.assertEquals(v1.getValue(), v.getValue());
    }

    public void test_codec_null_1() throws Exception {
        V0 v = new V0();


            

Reported by PMD.

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

Line: 28

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }

    public void test_codec_null_1() throws Exception {
        V0 v = new V0();

        SerializeConfig mapping = new SerializeConfig();
        mapping.setAsmEnable(false);


            

Reported by PMD.

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

Line: 29

                          text = JSON.toJSONString(map);
        }
        
        System.out.println(text);
        Map<String, Object> map = JSON.parseObject(text, new TypeReference<Map<String, Object>>() {});
        //Assert.assertEquals(map, map.get("this"));
        Assert.assertEquals(map.get("u1"), map.get("u2"));
    }


            

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

    public void test_0() throws Exception {
        String text;
        {
            Map<String, Object> map = new HashMap<String, Object>();

            User user = new User();

            

Reported by PMD.

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

Line: 35

                      Assert.assertEquals(map.get("u1"), map.get("u2"));
    }

    public static class User {

        private int    id;
        private String name;

        public int getId() {

            

Reported by PMD.

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

Line: 23

                      Rectangle v = new Rectangle(3, 4, 100, 200);
        String text = JSON.toJSONString(v, SerializerFeature.WriteClassName);
        
        System.out.println(text);

        Rectangle v2 = (Rectangle) JSON.parse(text);

        Assert.assertEquals(v, v2);
    }

            

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

    public void test_color() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        Assert.assertEquals(AwtCodec.class, serializer.getObjectWriter(Rectangle.class).getClass());
        
        Rectangle v = new Rectangle(3, 4, 100, 200);
        String text = JSON.toJSONString(v, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 18

              
    public void test_color() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        Assert.assertEquals(AwtCodec.class, serializer.getObjectWriter(Rectangle.class).getClass());
        
        Rectangle v = new Rectangle(3, 4, 100, 200);
        String text = JSON.toJSONString(v, SerializerFeature.WriteClassName);
        
        System.out.println(text);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/SqlDateTest1.java
3 issues
JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 16

              import junit.framework.TestCase;

public class SqlDateTest1 extends TestCase {
    protected void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
        JSON.defaultLocale = new Locale("zh_CN");
    }
    
    public void test_date() throws Exception {

            

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

                      JSON.defaultLocale = new Locale("zh_CN");
    }
    
    public void test_date() throws Exception {
        long millis = 1324138987429L;
        Date date = new Date(millis);

        Assert.assertEquals("1324138987429", JSON.toJSONString(date));
        Assert.assertEquals("{\"@type\":\"java.sql.Date\",\"val\":1324138987429}", JSON.toJSONString(date, SerializerFeature.WriteClassName));

            

Reported by PMD.

Avoid unused imports such as 'java.text.SimpleDateFormat'
Design

Line: 4

              package com.alibaba.json.bvt;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;

import org.junit.Assert;


            

Reported by PMD.

src/test/java/com/alibaba/json/TestGC.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: 7

              

public class TestGC extends TestCase {
    public void test_0 () throws Exception {
        for (int i = 0; i < 1000 * 1000; ++i) {
            StringBuilder buf = new StringBuilder(1000 * 1000 * 10);
            buf.append(i);
            Thread.sleep(10);
        }

            

Reported by PMD.

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

Line: 7

              

public class TestGC extends TestCase {
    public void test_0 () throws Exception {
        for (int i = 0; i < 1000 * 1000; ++i) {
            StringBuilder buf = new StringBuilder(1000 * 1000 * 10);
            buf.append(i);
            Thread.sleep(10);
        }

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 9

              public class TestGC extends TestCase {
    public void test_0 () throws Exception {
        for (int i = 0; i < 1000 * 1000; ++i) {
            StringBuilder buf = new StringBuilder(1000 * 1000 * 10);
            buf.append(i);
            Thread.sleep(10);
        }
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/StringFieldTest.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: 13

              
public class StringFieldTest extends TestCase {

    public void test_codec_null() throws Exception {
        V0 v = new V0();

        SerializeConfig mapping = new SerializeConfig();
        mapping.setAsmEnable(false);


            

Reported by PMD.

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

Line: 27

                      
        V0 v1 = JSON.parseObject(text, V0.class, config, JSON.DEFAULT_PARSER_FEATURE);

        Assert.assertEquals(v1.getValue(), v.getValue());
    }

    public void test_codec_null_1() throws Exception {
        V0 v = new V0();


            

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

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }

    public void test_codec_null_1() throws Exception {
        V0 v = new V0();

        SerializeConfig mapping = new SerializeConfig();
        mapping.setAsmEnable(false);


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/StringFieldTest_special.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: 13

              import junit.framework.TestCase;

public class StringFieldTest_special extends TestCase {
    public void test_special() throws Exception {
        Model model = new Model();
        model.name = "a\\bc";
        String text = JSON.toJSONString(model);
        Assert.assertEquals("{\"name\":\"a\\\\bc\"}", text);


            

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

                      reader.close();
    }
    
    public void test_special_2() throws Exception {
        Model model = new Model();
        model.name = "a\\bc\"";
        String text = JSON.toJSONString(model);
        Assert.assertEquals("{\"name\":\"a\\\\bc\\\"\"}", text);


            

Reported by PMD.

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

Line: 39

              
    public static class Model {

        public String name;

    }
}

            

Reported by PMD.

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

              import junit.framework.TestCase;

public class StringFieldTest_special_reader extends TestCase {
    public void test_special() throws Exception {
        Model model = new Model();
        model.name = "a\\bc";
        String text = JSON.toJSONString(model);
        Assert.assertEquals("{\"name\":\"a\\\\bc\"}", text);


            

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

                      Assert.assertEquals(model.name, model2.name);
    }
    
    public void test_special_2() throws Exception {
        Model model = new Model();
        model.name = "a\\bc\"";
        String text = JSON.toJSONString(model);
        Assert.assertEquals("{\"name\":\"a\\\\bc\\\"\"}", text);


            

Reported by PMD.

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

Line: 32

              
    public static class Model {

        public String name;

    }
}

            

Reported by PMD.

src/test/java/com/alibaba/fastjson/serializer/issue3473/SerializeWriterJavaSqlDateTest.java
3 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 26

               */
public class SerializeWriterJavaSqlDateTest {

    private Map<String, Object> data = new HashMap<String, Object>(1, 1);

    @Before
    public void before() throws ParseException {
        data.put("sqlDate", new Date(DateUtils.parseDate("2020-09-29", "yyyy-MM-dd")
            .getTime()));

            

Reported by PMD.

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

Line: 26

               */
public class SerializeWriterJavaSqlDateTest {

    private Map<String, Object> data = new HashMap<String, Object>(1, 1);

    @Before
    public void before() throws ParseException {
        data.put("sqlDate", new Date(DateUtils.parseDate("2020-09-29", "yyyy-MM-dd")
            .getTime()));

            

Reported by PMD.

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

Line: 30

              
    @Before
    public void before() throws ParseException {
        data.put("sqlDate", new Date(DateUtils.parseDate("2020-09-29", "yyyy-MM-dd")
            .getTime()));
    }

    @Test
    public void yyyy_MM_dd_HH_mm_ss_test() {

            

Reported by PMD.