The following issues were found

src/test/java/com/alibaba/json/bvt/parser/creator/JSONCreatorTest_default_short.java
4 issues
Do not use the short type
Performance

Line: 20

              
    public static class Model {

        private final short id;
        private final String name;

        @JSONCreator
        public Model(@JSONField(name="id") short id, @JSONField(name="name") String name) {
            this.id = id;

            

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

              
public class JSONCreatorTest_default_short extends TestCase {

    public void test_create() throws Exception {
        Model model = JSON.parseObject("{\"name\":\"wenshao\"}", Model.class);
        Assert.assertEquals(0, model.id);
        Assert.assertEquals("wenshao", model.name);
    }


            

Reported by PMD.

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

Line: 20

              
    public static class Model {

        private final short id;
        private final String name;

        @JSONCreator
        public Model(@JSONField(name="id") short id, @JSONField(name="name") String name) {
            this.id = id;

            

Reported by PMD.

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

Line: 21

                  public static class Model {

        private final short id;
        private final String name;

        @JSONCreator
        public Model(@JSONField(name="id") short id, @JSONField(name="name") String name) {
            this.id = id;
            this.name = name;

            

Reported by PMD.

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

Line: 17

                      ParserConfig config = new ParserConfig();
        config.setAutoTypeSupport(true);

        System.out.println(Model.class.isAnnotationPresent(JSONField.class));
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest1$Model\",\"id\":123}";

        Model model2 = (Model) JSON.parseObject(text, Object.class, config);
        assertEquals(123, model2.id);
    }

            

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 10/02/2017.
 */
public class AutoTypeTest1 extends TestCase {
    public void test_0() throws Exception {
        ParserConfig config = new ParserConfig();
        config.setAutoTypeSupport(true);

        System.out.println(Model.class.isAnnotationPresent(JSONField.class));
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest1$Model\",\"id\":123}";

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest1$Model\",\"id\":123}";

        Model model2 = (Model) JSON.parseObject(text, Object.class, config);
        assertEquals(123, model2.id);
    }

    @JSONType
    public static class Model {
        public int id;

            

Reported by PMD.

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

Line: 26

              
    @JSONType
    public static class Model {
        public int id;
    }
}

            

Reported by PMD.

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

               * Created by wenshao on 16/8/23.
 */
public class DateTest1 extends TestCase {
    public void test_date() throws Exception {
        Model model = new Model();
        model.date = new Date(1471939192128L);

        String text = JSON.toJSONString(model);
        Assert.assertEquals("{\"date\":1471939192128}", text);

            

Reported by PMD.

Avoid unused local variables such as 'text2'.
Design

Line: 25

                      Map<String, Object> map = new HashMap<String, Object>();
        map.put("date", new Date(1471939192128L));

        String text2 = JSON.toJSONString(map);
        Assert.assertEquals("{\"date\":1471939192128}", text);
    }

    public static class Model {
        public Date date;

            

Reported by PMD.

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

Line: 30

                  }

    public static class Model {
        public Date date;
    }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'text2' (lines '25'-'27').
Error

Line: 25

                      Map<String, Object> map = new HashMap<String, Object>();
        map.put("date", new Date(1471939192128L));

        String text2 = JSON.toJSONString(map);
        Assert.assertEquals("{\"date\":1471939192128}", text);
    }

    public static class Model {
        public Date date;

            

Reported by PMD.

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

Line: 7

              import junit.framework.TestCase;

public class Bug_for_kongmu extends TestCase {
    public void test_for_bug() throws Exception {
        String JSON_STRING = "{\n"
                + "\t\"body\":\"parentBody\",\n"
                + "\t\"name\":\"child-1\",\n"
                + "\t\"result\":{\n"
                + "\t\t\"code\":11\n"

            

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

              import junit.framework.TestCase;

public class Bug_for_kongmu extends TestCase {
    public void test_for_bug() throws Exception {
        String JSON_STRING = "{\n"
                + "\t\"body\":\"parentBody\",\n"
                + "\t\"name\":\"child-1\",\n"
                + "\t\"result\":{\n"
                + "\t\t\"code\":11\n"

            

Reported by PMD.

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

Line: 24

                  }


    public static class BaseDO {
        private String body;
        private Result result;

        public String getBody() {
            return body;

            

Reported by PMD.

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

Line: 67

                      }
    }

    public static class Child extends BaseDO {
        public String name;
        public Toy toy;

        public String getName() {
            return name;

            

Reported by PMD.

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

              import java.util.Map;

public class Issue_for_luohaoyu extends TestCase {
    public void test_for_issue() throws Exception {
        Map map = new HashMap();
        map.put(null, 123);

        String str = JSON.toJSONString(map);
        assertEquals("{null:123}", str);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      map.put(null, 123);

        String str = JSON.toJSONString(map);
        assertEquals("{null:123}", str);

        JSONObject object = JSON.parseObject(str);
    }
}

            

Reported by PMD.

Avoid unused local variables such as 'object'.
Design

Line: 18

                      String str = JSON.toJSONString(map);
        assertEquals("{null:123}", str);

        JSONObject object = JSON.parseObject(str);
    }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'object' (lines '18'-'19').
Error

Line: 18

                      String str = JSON.toJSONString(map);
        assertEquals("{null:123}", str);

        JSONObject object = JSON.parseObject(str);
    }
}

            

Reported by PMD.

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

Line: 10

              public class Issue2311 extends TestCase {
    public void test_for_issue() throws Exception {
        String t = "{\"groups\":[{\"timers\":[{\"date\":\"00000001\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:06\",\"status\":1},{\"date\":\"00000010\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:07\",\"status\":1}],\"id\":\"1:\"},{\"timers\":[{\"date\":\"00000100\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:06\",\"status\":1},{\"date\":\"00001000\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:07\",\"status\":1}],\"id\":\"2:\"}],\"category\":{\"category\":\"xxxxxx\",\"status\":1}}";
        System.out.println((Object) JsonPath.read(t, "$.groups[*].timers[*].dps.1"));
        System.out.println(JSONPath.extract(t, "$.groups[*].timers[*].dps['1']"));
    }
}

            

Reported by PMD.

System.out.println is used
Design

Line: 11

                  public void test_for_issue() throws Exception {
        String t = "{\"groups\":[{\"timers\":[{\"date\":\"00000001\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:06\",\"status\":1},{\"date\":\"00000010\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:07\",\"status\":1}],\"id\":\"1:\"},{\"timers\":[{\"date\":\"00000100\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:06\",\"status\":1},{\"date\":\"00001000\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:07\",\"status\":1}],\"id\":\"2:\"}],\"category\":{\"category\":\"xxxxxx\",\"status\":1}}";
        System.out.println((Object) JsonPath.read(t, "$.groups[*].timers[*].dps.1"));
        System.out.println(JSONPath.extract(t, "$.groups[*].timers[*].dps['1']"));
    }
}

            

Reported by PMD.

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

Line: 8

              import junit.framework.TestCase;

public class Issue2311 extends TestCase {
    public void test_for_issue() throws Exception {
        String t = "{\"groups\":[{\"timers\":[{\"date\":\"00000001\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:06\",\"status\":1},{\"date\":\"00000010\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:07\",\"status\":1}],\"id\":\"1:\"},{\"timers\":[{\"date\":\"00000100\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:06\",\"status\":1},{\"date\":\"00001000\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:07\",\"status\":1}],\"id\":\"2:\"}],\"category\":{\"category\":\"xxxxxx\",\"status\":1}}";
        System.out.println((Object) JsonPath.read(t, "$.groups[*].timers[*].dps.1"));
        System.out.println(JSONPath.extract(t, "$.groups[*].timers[*].dps['1']"));
    }
}

            

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 Issue2311 extends TestCase {
    public void test_for_issue() throws Exception {
        String t = "{\"groups\":[{\"timers\":[{\"date\":\"00000001\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:06\",\"status\":1},{\"date\":\"00000010\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:07\",\"status\":1}],\"id\":\"1:\"},{\"timers\":[{\"date\":\"00000100\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:06\",\"status\":1},{\"date\":\"00001000\",\"dps\":{\"1\":true},\"loops\":\"1111111\",\"timezoneId\":\"Asia/Shanghai\",\"time\":\"13:07\",\"status\":1}],\"id\":\"2:\"}],\"category\":{\"category\":\"xxxxxx\",\"status\":1}}";
        System.out.println((Object) JsonPath.read(t, "$.groups[*].timers[*].dps.1"));
        System.out.println(JSONPath.extract(t, "$.groups[*].timers[*].dps['1']"));
    }
}

            

Reported by PMD.

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

              import junit.framework.TestCase;

public class Issue2254 extends TestCase {
    public void test_for_issue() throws Exception {
        String jsonString = "{\"a\":[1.0,2.0]}"; //{"a":[1.0,2.0]}
        Exception error = null;
        try {
            JSON.parseObject(jsonString, TestClass.class);
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 12

                      Exception error = null;
        try {
            JSON.parseObject(jsonString, TestClass.class);
        } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

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

    public static class TestClass {
        public float[][] a;
    }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '9'-'13').
Error

Line: 9

              public class Issue2254 extends TestCase {
    public void test_for_issue() throws Exception {
        String jsonString = "{\"a\":[1.0,2.0]}"; //{"a":[1.0,2.0]}
        Exception error = null;
        try {
            JSON.parseObject(jsonString, TestClass.class);
        } catch (Exception ex) {
            error = ex;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/test/benchmark/basic/LongBenchmark_obj.java
4 issues
System.out.println is used
Design

Line: 34

                          JSON.parseObject(json, Model.class);
        }
        long millis = System.currentTimeMillis() - start;
        System.out.println("millis : " + millis);
    }

    public static void perf2() {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 1000 * 1000 * 10; ++i) {

            

Reported by PMD.

System.out.println is used
Design

Line: 43

                          JSON.parseObject(json2, Model.class);
        }
        long millis = System.currentTimeMillis() - start;
        System.out.println("millis : " + millis);
    }

    public static class Model {
        public Long v1;
        public Long v2;

            

Reported by PMD.

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

              /**
 * Created by wenshao on 04/08/2017.
 */
public class LongBenchmark_obj {
    static String json = "{\"v1\":-1883391953414482124,\"v2\":-3019416596934963650,\"v3\":6497525620823745793,\"v4\":2136224289077142499,\"v5\":-2090575024006307745}";
    static String json2 = "{\"v1\":\"-1883391953414482124\",\"v2\":\"-3019416596934963650\",\"v3\":\"6497525620823745793\",\"v4\":\"2136224289077142499\",\"v5\":\"-2090575024006307745\"}";

    public static void main(String[] args) throws Exception {
//        Model model = new Model();

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 12

                  static String json = "{\"v1\":-1883391953414482124,\"v2\":-3019416596934963650,\"v3\":6497525620823745793,\"v4\":2136224289077142499,\"v5\":-2090575024006307745}";
    static String json2 = "{\"v1\":\"-1883391953414482124\",\"v2\":\"-3019416596934963650\",\"v3\":\"6497525620823745793\",\"v4\":\"2136224289077142499\",\"v5\":\"-2090575024006307745\"}";

    public static void main(String[] args) throws Exception {
//        Model model = new Model();
//        model.v1 = new Random().nextLong();
//        model.v2 = new Random().nextLong();
//        model.v3 = new Random().nextLong();
//        model.v4 = new Random().nextLong();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvtVO/IEventDto.java
4 issues
The class 'IEventDto' is suspected to be a Data Class (WOC=20.000%, NOPA=0, NOAM=4, WMC=5)
Design

Line: 24

              /**
 * @author wb_jianhui.shijh
 */
public class IEventDto implements Serializable {

    private static final long serialVersionUID = -3903138261314727539L;

    private String            source;


            

Reported by PMD.

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

Line: 30

              
    private String            source;

    private ArrayList<IEvent> eventList = new ArrayList<IEvent>();

    public String getSource() {
        return source;
    }


            

Reported by PMD.

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

Line: 40

                      this.source = source;
    }
    
    public ArrayList<IEvent> getEventList() {
        return eventList;
    }

    public void setEventList(ArrayList<IEvent> eventList) {
        this.eventList = eventList;

            

Reported by PMD.

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

Line: 44

                      return eventList;
    }

    public void setEventList(ArrayList<IEvent> eventList) {
        this.eventList = eventList;
    }

    @Override
    public String toString() {

            

Reported by PMD.

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

              import junit.framework.TestCase;

public class WriteAsArray_long_stream_public extends TestCase {
    public void test_0 () throws Exception {
        VO vo = new VO();
        vo.setId(123);
        vo.setName("wenshao");
        
        String text = JSON.toJSONString(vo, SerializerFeature.BeanToArray);

            

Reported by PMD.

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

Line: 24

                      Assert.assertEquals("[123,\"wenshao\"]", text);
        JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
        VO vo2 = reader.readObject(VO.class);
        Assert.assertEquals(vo.getId(), vo2.getId());
        Assert.assertEquals(vo.getName(), vo2.getName());
        reader.close();
    }
    
    public static class VO {

            

Reported by PMD.

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

Line: 25

                      JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
        VO vo2 = reader.readObject(VO.class);
        Assert.assertEquals(vo.getId(), vo2.getId());
        Assert.assertEquals(vo.getName(), vo2.getName());
        reader.close();
    }
    
    public static class VO {
        private long id;

            

Reported by PMD.

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

Line: 29

                      reader.close();
    }
    
    public static class VO {
        private long id;
        private String name;

        public long getId() {
            return id;

            

Reported by PMD.