The following issues were found

src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_ident.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: 11

              
public class JSONScannerTest_ident extends TestCase {

    public void test_true() throws Exception {
        JSONScanner lexer = new JSONScanner("true");
        lexer.scanIdent();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_false() throws Exception {
        JSONScanner lexer = new JSONScanner("false");
        lexer.scanIdent();
        Assert.assertEquals(JSONToken.FALSE, lexer.token());
    }


            

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(JSONToken.FALSE, lexer.token());
    }

    public void test_null() throws Exception {
        JSONScanner lexer = new JSONScanner("null");
        lexer.scanIdent();
        Assert.assertEquals(JSONToken.NULL, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.NULL, lexer.token());
    }

    public void test_new() throws Exception {
        JSONScanner lexer = new JSONScanner("new");
        lexer.scanIdent();
        Assert.assertEquals(JSONToken.NEW, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.NEW, lexer.token());
    }

    public void test_Date() throws Exception {
        String text = "Date";
        JSONScanner lexer = new JSONScanner(text);
        lexer.scanIdent();
        Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
        Assert.assertEquals(text, lexer.stringVal());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2300/Issue2351.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

              import java.util.List;

public class Issue2351 extends TestCase {
    public void test_for_issue() throws Exception {
//        ParserConfig.getGlobalInstance().setAsmEnable(false);
        // 创建空白对象
        Bean1 c = new Bean1();
        c.a = "";


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      // 序列化
        // 输出[null,null]
        String s = JSON.toJSONString(c, SerializerFeature.BeanToArray);
        assertEquals("[\"\",null]", s);

        // 反序列化报错
        // Exception in thread "main" com.alibaba.fastjson.JSONException: syntax error, expect [, actual [
        JSON.parseObject(s, Bean1.class, Feature.SupportArrayToBean);
    }

            

Reported by PMD.

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

Line: 31

              
    public static class Bean1 {

        public String a;

        public List<Bean2> b;
    }

    public static class Bean2  {

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.parser.ParserConfig'
Design

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;

            

Reported by PMD.

Avoid unused imports such as 'java.util.ArrayList'
Design

Line: 9

              import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;

public class Issue2351 extends TestCase {
    public void test_for_issue() throws Exception {
//        ParserConfig.getGlobalInstance().setAsmEnable(false);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1500/Issue1588.java
5 issues
System.out.println is used
Design

Line: 16

                      Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("test", date);
        System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
        System.out.println(JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd'T'HH:mm:ssXXX"));
    }
}

            

Reported by PMD.

System.out.println is used
Design

Line: 17

                      JSONObject jsonObject = new JSONObject();
        jsonObject.put("test", date);
        System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
        System.out.println(JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd'T'HH:mm:ssXXX"));
    }
}

            

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

              import java.util.Date;

public class Issue1588 extends TestCase {
    public void test_for_issue() throws Exception {
        String dateString = "2017-11-17 00:00:00";
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("test", date);
        System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));

            

Reported by PMD.

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

Line: 11

              import java.util.Date;

public class Issue1588 extends TestCase {
    public void test_for_issue() throws Exception {
        String dateString = "2017-11-17 00:00:00";
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("test", date);
        System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));

            

Reported by PMD.

When instantiating a SimpleDateFormat object, specify a Locale
Error

Line: 13

              public class Issue1588 extends TestCase {
    public void test_for_issue() throws Exception {
        String dateString = "2017-11-17 00:00:00";
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("test", date);
        System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
        System.out.println(JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd'T'HH:mm:ssXXX"));
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1500/Issue1583.java
5 issues
System.out.println is used
Design

Line: 26

                      List<Map.Entry<String, List<String>>> mapList = new ArrayList<Map.Entry<String, List<String>>>(totalMap.entrySet());
        String jsonString = JSON.toJSONString(mapList, SerializerFeature.DisableCircularReferenceDetect);

        System.out.println(jsonString);
        List<Map.Entry<String, List<String>>> parse = JSON.parseObject(jsonString, new TypeReference<List<Map.Entry<String, List<String>>>>() {});
        System.out.println(parse);
    }
}

            

Reported by PMD.

System.out.println is used
Design

Line: 28

              
        System.out.println(jsonString);
        List<Map.Entry<String, List<String>>> parse = JSON.parseObject(jsonString, new TypeReference<List<Map.Entry<String, List<String>>>>() {});
        System.out.println(parse);
    }
}

            

Reported by PMD.

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

Line: 14

              import java.util.Map;

public class Issue1583 extends TestCase {
    public void test_issue() throws Exception {
        Map<String, List<String>> totalMap = new HashMap<String, List<String>>();
        for (int i = 0; i < 10; i++) {
            List<String> list = new ArrayList<String>();
            for (int j = 0; j < 2; j++) {
                list.add("list" + j);

            

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

              import java.util.Map;

public class Issue1583 extends TestCase {
    public void test_issue() throws Exception {
        Map<String, List<String>> totalMap = new HashMap<String, List<String>>();
        for (int i = 0; i < 10; i++) {
            List<String> list = new ArrayList<String>();
            for (int j = 0; j < 2; j++) {
                list.add("list" + j);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 17

                  public void test_issue() throws Exception {
        Map<String, List<String>> totalMap = new HashMap<String, List<String>>();
        for (int i = 0; i < 10; i++) {
            List<String> list = new ArrayList<String>();
            for (int j = 0; j < 2; j++) {
                list.add("list" + j);
            }
            totalMap.put("map" + i, list);
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/lombok/LomBokTest.java
5 issues
System.out.println is used
Design

Line: 30

                      ParserConfig.getGlobalInstance().addAccept("com.alibaba.json.bvt.lombok.LomBokTest.DaysCycleExeDecision");
        JSONObject obj = JSON.parseObject(str);
        IndicatorCycleRule cycleRule = obj.getObject("cycleRule", IndicatorCycleRule.class);
        System.out.println(((DaysCycleExeDecision) cycleRule.decision).days);
    }

    @lombok.Data
    public static class DaysCycleExeDecision implements ExeDecision {
        private int days;

            

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

              import junit.framework.TestCase;

public class LomBokTest extends TestCase {
    public void test_for_issue() throws Exception {
        String str = "{\n" +
                "\t\"target\": 1,\n" +
                "\t\"current\": 0,\n" +
                "\t\"step\": 1,\n" +
                "\t\"uqcRule\": {\n" +

            

Reported by PMD.

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

Line: 9

              import junit.framework.TestCase;

public class LomBokTest extends TestCase {
    public void test_for_issue() throws Exception {
        String str = "{\n" +
                "\t\"target\": 1,\n" +
                "\t\"current\": 0,\n" +
                "\t\"step\": 1,\n" +
                "\t\"uqcRule\": {\n" +

            

Reported by PMD.

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

Line: 27

                              "\t\t}\n" +
                "\t}\n" +
                "}";
        ParserConfig.getGlobalInstance().addAccept("com.alibaba.json.bvt.lombok.LomBokTest.DaysCycleExeDecision");
        JSONObject obj = JSON.parseObject(str);
        IndicatorCycleRule cycleRule = obj.getObject("cycleRule", IndicatorCycleRule.class);
        System.out.println(((DaysCycleExeDecision) cycleRule.decision).days);
    }


            

Reported by PMD.

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

Line: 29

                              "}";
        ParserConfig.getGlobalInstance().addAccept("com.alibaba.json.bvt.lombok.LomBokTest.DaysCycleExeDecision");
        JSONObject obj = JSON.parseObject(str);
        IndicatorCycleRule cycleRule = obj.getObject("cycleRule", IndicatorCycleRule.class);
        System.out.println(((DaysCycleExeDecision) cycleRule.decision).days);
    }

    @lombok.Data
    public static class DaysCycleExeDecision implements ExeDecision {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_3300/Issue3347.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: 15

               * @Date :Created in 22:29 2020/7/15
 */
public class Issue3347 extends TestCase {
    public void test_for_issue() throws Exception {
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "hello");
        String mapJSONString = JSON.toJSONString(map);
        Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
        Object mapKey = mapValues.keySet().iterator().next();

            

Reported by PMD.

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

Line: 20

                      map.put(1, "hello");
        String mapJSONString = JSON.toJSONString(map);
        Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
        Object mapKey = mapValues.keySet().iterator().next();
        assertTrue(mapKey instanceof Integer);
    }
}

            

Reported by PMD.

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

Line: 20

                      map.put(1, "hello");
        String mapJSONString = JSON.toJSONString(map);
        Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
        Object mapKey = mapValues.keySet().iterator().next();
        assertTrue(mapKey instanceof Integer);
    }
}

            

Reported by PMD.

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

Line: 20

                      map.put(1, "hello");
        String mapJSONString = JSON.toJSONString(map);
        Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
        Object mapKey = mapValues.keySet().iterator().next();
        assertTrue(mapKey instanceof Integer);
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      String mapJSONString = JSON.toJSONString(map);
        Map mapValues = JSONObject.parseObject(mapJSONString, Map.class);
        Object mapKey = mapValues.keySet().iterator().next();
        assertTrue(mapKey instanceof Integer);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONLexerTest_11.java
5 issues
Avoid throwing raw exception types.
Design

Line: 43

                  
    public static class MyList<T> extends ArrayList<T> {
        public MyList() {
            throw new RuntimeException();
        }
    }
}

            

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

              
public class JSONLexerTest_11 extends TestCase {

    public void test_a() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("{\"type\":[\"AAA\"]}", VO.class);
        } catch (Exception ex) {
            error = ex;

            

Reported by PMD.

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

Line: 17

                      Exception error = null;
        try {
            JSON.parseObject("{\"type\":[\"AAA\"]}", VO.class);
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }


            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 41

              
    }
    
    public static class MyList<T> extends ArrayList<T> {
        public MyList() {
            throw new RuntimeException();
        }
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '14'-'18').
Error

Line: 14

              public class JSONLexerTest_11 extends TestCase {

    public void test_a() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("{\"type\":[\"AAA\"]}", VO.class);
        } catch (Exception ex) {
            error = ex;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/date/DateTest.java
5 issues
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 DateTest extends TestCase {
    protected void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
        JSON.defaultLocale = Locale.CHINA;
    }

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

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_date() throws Exception {
        long millis = 1324138987429L;
        Date date = new Date(millis);

        Assert.assertEquals("1324138987429", JSON.toJSONString(date));
        Assert.assertEquals("new Date(1324138987429)", JSON.toJSONString(date, SerializerFeature.WriteClassName));

            

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

                                                                          SerializerFeature.UseSingleQuotes));
    }

    public void test_parse() throws Exception {
        Date date = JSON.parseObject("\"2018-10-12 09:48:22 +0800\"", Date.class);
        assertEquals(1539308902000L, date.getTime());
    }
}

            

Reported by PMD.

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

Line: 38

              
    public void test_parse() throws Exception {
        Date date = JSON.parseObject("\"2018-10-12 09:48:22 +0800\"", Date.class);
        assertEquals(1539308902000L, date.getTime());
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 38

              
    public void test_parse() throws Exception {
        Date date = JSON.parseObject("\"2018-10-12 09:48:22 +0800\"", Date.class);
        assertEquals(1539308902000L, date.getTime());
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/joda/JodaTest_7_DateTimeZone.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: 8

              import org.joda.time.DateTimeZone;

public class JodaTest_7_DateTimeZone extends TestCase {
    public void test_for_joda_0() throws Exception {

       Model m = new Model();
       m.zone = DateTimeZone.forID("Asia/Shanghai");

       String json = JSON.toJSONString(m);

            

Reported by PMD.

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

Line: 8

              import org.joda.time.DateTimeZone;

public class JodaTest_7_DateTimeZone extends TestCase {
    public void test_for_joda_0() throws Exception {

       Model m = new Model();
       m.zone = DateTimeZone.forID("Asia/Shanghai");

       String json = JSON.toJSONString(m);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

              
       String json = JSON.toJSONString(m);

       assertEquals("{\"zone\":\"Asia/Shanghai\"}", json);

       Model m1 = JSON.parseObject(json, Model.class);
       assertEquals(m.zone, m1.zone);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                     assertEquals("{\"zone\":\"Asia/Shanghai\"}", json);

       Model m1 = JSON.parseObject(json, Model.class);
       assertEquals(m.zone, m1.zone);
    }

    public static class Model {
        public DateTimeZone zone;
    }

            

Reported by PMD.

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

Line: 22

                  }

    public static class Model {
        public DateTimeZone zone;
    }
}

            

Reported by PMD.

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

               * Created by wenshao on 11/06/2017.
 */
public class Issue1205 extends TestCase {
    public void test_for_issue() throws Exception {
        JSONArray array = new JSONArray();
        array.add(new JSONObject());

        List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
        assertEquals(1, list.size());

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 11/06/2017.
 */
public class Issue1205 extends TestCase {
    public void test_for_issue() throws Exception {
        JSONArray array = new JSONArray();
        array.add(new JSONObject());

        List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
        assertEquals(1, list.size());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      array.add(new JSONObject());

        List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());
    }

    public static class Model {


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());
    }

    public static class Model {

    }

            

Reported by PMD.

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

Line: 20

              
        List<Model> list = array.toJavaObject(new TypeReference<List<Model>>(){});
        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());
    }

    public static class Model {

    }

            

Reported by PMD.