The following issues were found

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

Line: 28

              
            text = JSON.toJSONString(list);
            
            System.out.println(text);
        }

        JSONArray array = JSON.parseArray(text);

//        Body body = array.getObject(1, Body.class);

            

Reported by PMD.

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

Line: 14

              
public class CastTest extends TestCase {

    public void test_0() throws Exception {
        String text;
        {
            List<Object> list = new ArrayList<Object>();

            list.add(new Header());

            

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

    public void test_0() throws Exception {
        String text;
        {
            List<Object> list = new ArrayList<Object>();

            list.add(new Header());

            

Reported by PMD.

Avoid unused local variables such as 'array'.
Design

Line: 31

                          System.out.println(text);
        }

        JSONArray array = JSON.parseArray(text);

//        Body body = array.getObject(1, Body.class);
//        Assert.assertEquals(1, body.getItems().size());

//        Assert.assertEquals("张三", body.getName());

            

Reported by PMD.

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

Line: 43

              
    }

    public static class Body {

        private String name;

        public Body(){


            

Reported by PMD.

Avoid unused imports such as 'org.junit.Assert'
Design

Line: 6

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

import org.junit.Assert;
import junit.framework.TestCase;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;


            

Reported by PMD.

Found 'DU'-anomaly for variable 'array' (lines '31'-'37').
Error

Line: 31

                          System.out.println(text);
        }

        JSONArray array = JSON.parseArray(text);

//        Body body = array.getObject(1, Body.class);
//        Assert.assertEquals(1, body.getItems().size());

//        Assert.assertEquals("张三", body.getName());

            

Reported by PMD.

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

Line: 13

              
public class Bug_for_yaoming extends TestCase {

    public void test_bug() throws Exception {
        SimpleHttpReuslt v = new SimpleHttpReuslt();
        v.setErrorMessage(new ArrayList<ErrorMessage>());
        v.getErrorMessage().add(new ErrorMessage());
        String text = JSON.toJSONString(v);
        text = "{\"content\":{\"versionModelList\":[{\"version\":\"260\",\"currentVersion\":true,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375850777000},{\"version\":\"247\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375634817000},{\"version\":\"246\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375613193000},{\"version\":\"245\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375591593000},{\"version\":\"244\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375569999000},{\"version\":\"243\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375548418000}],\"exceptionCode\":0},\"hasError\":false}";

            

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

    public void test_bug() throws Exception {
        SimpleHttpReuslt v = new SimpleHttpReuslt();
        v.setErrorMessage(new ArrayList<ErrorMessage>());
        v.getErrorMessage().add(new ErrorMessage());
        String text = JSON.toJSONString(v);
        text = "{\"content\":{\"versionModelList\":[{\"version\":\"260\",\"currentVersion\":true,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375850777000},{\"version\":\"247\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375634817000},{\"version\":\"246\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375613193000},{\"version\":\"245\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375591593000},{\"version\":\"244\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375569999000},{\"version\":\"243\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375548418000}],\"exceptionCode\":0},\"hasError\":false}";

            

Reported by PMD.

The initializer for variable 'text' is never used (overwritten on line 18)
Design

Line: 17

                      SimpleHttpReuslt v = new SimpleHttpReuslt();
        v.setErrorMessage(new ArrayList<ErrorMessage>());
        v.getErrorMessage().add(new ErrorMessage());
        String text = JSON.toJSONString(v);
        text = "{\"content\":{\"versionModelList\":[{\"version\":\"260\",\"currentVersion\":true,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375850777000},{\"version\":\"247\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375634817000},{\"version\":\"246\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375613193000},{\"version\":\"245\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375591593000},{\"version\":\"244\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375569999000},{\"version\":\"243\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375548418000}],\"exceptionCode\":0},\"hasError\":false}";
        JSON.parseObject(text, SimpleHttpReuslt.class);
    }

    public static class SimpleHttpReuslt {

            

Reported by PMD.

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

Line: 22

                      JSON.parseObject(text, SimpleHttpReuslt.class);
    }

    public static class SimpleHttpReuslt {

        private String             content;
        private Boolean            hasError;
        private List<ErrorMessage> errorMessage;


            

Reported by PMD.

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

Line: 25

                  public static class SimpleHttpReuslt {

        private String             content;
        private Boolean            hasError;
        private List<ErrorMessage> errorMessage;

        public String getContent() {
            return content;
        }

            

Reported by PMD.

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

Line: 52

                          this.errorMessage = errorMessage;
        }

        public static class ErrorMessage {

            private String field;
            private String code;
            private String msg;


            

Reported by PMD.

Found 'DD'-anomaly for variable 'text' (lines '17'-'18').
Error

Line: 17

                      SimpleHttpReuslt v = new SimpleHttpReuslt();
        v.setErrorMessage(new ArrayList<ErrorMessage>());
        v.getErrorMessage().add(new ErrorMessage());
        String text = JSON.toJSONString(v);
        text = "{\"content\":{\"versionModelList\":[{\"version\":\"260\",\"currentVersion\":true,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375850777000},{\"version\":\"247\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375634817000},{\"version\":\"246\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375613193000},{\"version\":\"245\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375591593000},{\"version\":\"244\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130186\",\"appIdentifier\":\"parent\",\"uploadTime\":1375569999000},{\"version\":\"243\",\"currentVersion\":false,\"versionComment\":\"testVersion\",\"warSize\":\"43130185\",\"appIdentifier\":\"parent\",\"uploadTime\":1375548418000}],\"exceptionCode\":0},\"hasError\":false}";
        JSON.parseObject(text, SimpleHttpReuslt.class);
    }

    public static class SimpleHttpReuslt {

            

Reported by PMD.

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

Line: 30

              
            text = JSON.toJSONString(list);
            
            System.out.println(text);
        }

        JSONArray array = JSON.parseArray(text);

        Body body = array.getObject(1, Body.class);

            

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

    public void test_0() throws Exception {
        String text;
        {
            List<Object> list = new ArrayList<Object>();

            list.add(new Header());

            

Reported by PMD.

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

Line: 35

              
        JSONArray array = JSON.parseArray(text);

        Body body = array.getObject(1, Body.class);

        Assert.assertEquals("张三", body.getName());
        Assert.assertEquals(1, body.getItems().size());
    }


            

Reported by PMD.

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

Line: 37

              
        Body body = array.getObject(1, Body.class);

        Assert.assertEquals("张三", body.getName());
        Assert.assertEquals(1, body.getItems().size());
    }

    public static class Header {


            

Reported by PMD.

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

Line: 38

                      Body body = array.getObject(1, Body.class);

        Assert.assertEquals("张三", body.getName());
        Assert.assertEquals(1, body.getItems().size());
    }

    public static class Header {

    }

            

Reported by PMD.

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

Line: 38

                      Body body = array.getObject(1, Body.class);

        Assert.assertEquals("张三", body.getName());
        Assert.assertEquals(1, body.getItems().size());
    }

    public static class Header {

    }

            

Reported by PMD.

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

Line: 45

              
    }

    public static class Body {

        private String name;

        public Body(){


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/builder/BuilderTest1.java
7 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: 12

              
public class BuilderTest1 extends TestCase {
    
    public void test_create() throws Exception {
        VO vo = JSON.parseObject("{\"id\":12304,\"name\":\"ljw\"}", VO.class);
        
        Assert.assertEquals(12304, vo.getId());
        Assert.assertEquals("ljw", vo.getName());
    }

            

Reported by PMD.

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

Line: 15

                  public void test_create() throws Exception {
        VO vo = JSON.parseObject("{\"id\":12304,\"name\":\"ljw\"}", VO.class);
        
        Assert.assertEquals(12304, vo.getId());
        Assert.assertEquals("ljw", vo.getName());
    }

    @JSONType(builder=VOBuilder.class)
    public static class VO {

            

Reported by PMD.

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

Line: 16

                      VO vo = JSON.parseObject("{\"id\":12304,\"name\":\"ljw\"}", VO.class);
        
        Assert.assertEquals(12304, vo.getId());
        Assert.assertEquals("ljw", vo.getName());
    }

    @JSONType(builder=VOBuilder.class)
    public static class VO {
        private int id;

            

Reported by PMD.

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

Line: 21

              
    @JSONType(builder=VOBuilder.class)
    public static class VO {
        private int id;
        private String name;
        
        public int getId() {
            return id;
        }

            

Reported by PMD.

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

Line: 22

                  @JSONType(builder=VOBuilder.class)
    public static class VO {
        private int id;
        private String name;
        
        public int getId() {
            return id;
        }
        

            

Reported by PMD.

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

Line: 35

              
    public static class VOBuilder {

        private VO vo = new VO();

        public VO create() {
            return vo;
        }
        

            

Reported by PMD.

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

Line: 35

              
    public static class VOBuilder {

        private VO vo = new VO();

        public VO create() {
            return vo;
        }
        

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue_for_zuojing.java
7 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 12

               * Created by wenshao on 15/02/2017.
 */
public class Issue_for_zuojing extends TestCase {
    public void test_for_zuojing() throws Exception {
        String rowData = "[{\"@type\":\"java.util.HashMap\",\"end_date\":{\"@type\":\"java.sql.Date\",\"val\":1490803200000},\"gmt_create\":{\"@type\":\"java.sql.Timestamp\",\"val\":1487139144000},\"arr_city\":\"FOC\",\"agent\n" +
                "_id\":4765L,\"auto_book\":0B,\"sale_rebase\":12,\"channel\":1B,\"dep_city\":\"BJS\",\"gmt_modified\":{\"@type\":\"java.sql.Timestamp\",\"val\":1487139144000},\"is_support_share\":1B,\"sale_retenti\n" +
                "on\":430S,\"invoice_type\":5B,\"id\":12675100456,\"start_date\":{\"@type\":\"java.sql.Date\",\"val\":1485878400000},\"pat\":1B,\"agent_sub_nick\":\"辰\",\"travel_start_date\":{\"@type\"\n" +
                ":\"java.sql.Date\",\"val\":1485878400000},\"policy_type\":2B,\"travel_end_date\":{\"@type\":\"java.sql.Date\",\"val\":1490803200000},\"flights_limit_type\":1B,\"officeid\":\"WNZ159\",\"future_tic\n" +
                "ket\":0B,\"fare_id\":80L,\"source_id\":4653492L,\"source_code\":32B,\"agent_sub_id\":2752916259,\"flights_limit\":\"1100-1999,4000-4999,8200-8230,8960\"},{\"$ref\":\"$[0]\"}]";

            

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

               * Created by wenshao on 15/02/2017.
 */
public class Issue_for_zuojing extends TestCase {
    public void test_for_zuojing() throws Exception {
        String rowData = "[{\"@type\":\"java.util.HashMap\",\"end_date\":{\"@type\":\"java.sql.Date\",\"val\":1490803200000},\"gmt_create\":{\"@type\":\"java.sql.Timestamp\",\"val\":1487139144000},\"arr_city\":\"FOC\",\"agent\n" +
                "_id\":4765L,\"auto_book\":0B,\"sale_rebase\":12,\"channel\":1B,\"dep_city\":\"BJS\",\"gmt_modified\":{\"@type\":\"java.sql.Timestamp\",\"val\":1487139144000},\"is_support_share\":1B,\"sale_retenti\n" +
                "on\":430S,\"invoice_type\":5B,\"id\":12675100456,\"start_date\":{\"@type\":\"java.sql.Date\",\"val\":1485878400000},\"pat\":1B,\"agent_sub_nick\":\"辰\",\"travel_start_date\":{\"@type\"\n" +
                ":\"java.sql.Date\",\"val\":1485878400000},\"policy_type\":2B,\"travel_end_date\":{\"@type\":\"java.sql.Date\",\"val\":1490803200000},\"flights_limit_type\":1B,\"officeid\":\"WNZ159\",\"future_tic\n" +
                "ket\":0B,\"fare_id\":80L,\"source_id\":4653492L,\"source_code\":32B,\"agent_sub_id\":2752916259,\"flights_limit\":\"1100-1999,4000-4999,8200-8230,8960\"},{\"$ref\":\"$[0]\"}]";

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                              ":\"java.sql.Date\",\"val\":1485878400000},\"policy_type\":2B,\"travel_end_date\":{\"@type\":\"java.sql.Date\",\"val\":1490803200000},\"flights_limit_type\":1B,\"officeid\":\"WNZ159\",\"future_tic\n" +
                "ket\":0B,\"fare_id\":80L,\"source_id\":4653492L,\"source_code\":32B,\"agent_sub_id\":2752916259,\"flights_limit\":\"1100-1999,4000-4999,8200-8230,8960\"},{\"$ref\":\"$[0]\"}]";
        List row = JSON.parseObject(rowData,List.class);
        assertEquals(2, row.size());
        assertSame(row.get(0), row.get(1));
    }
}

            

Reported by PMD.

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

Line: 19

                              ":\"java.sql.Date\",\"val\":1485878400000},\"policy_type\":2B,\"travel_end_date\":{\"@type\":\"java.sql.Date\",\"val\":1490803200000},\"flights_limit_type\":1B,\"officeid\":\"WNZ159\",\"future_tic\n" +
                "ket\":0B,\"fare_id\":80L,\"source_id\":4653492L,\"source_code\":32B,\"agent_sub_id\":2752916259,\"flights_limit\":\"1100-1999,4000-4999,8200-8230,8960\"},{\"$ref\":\"$[0]\"}]";
        List row = JSON.parseObject(rowData,List.class);
        assertEquals(2, row.size());
        assertSame(row.get(0), row.get(1));
    }
}

            

Reported by PMD.

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

Line: 20

                              "ket\":0B,\"fare_id\":80L,\"source_id\":4653492L,\"source_code\":32B,\"agent_sub_id\":2752916259,\"flights_limit\":\"1100-1999,4000-4999,8200-8230,8960\"},{\"$ref\":\"$[0]\"}]";
        List row = JSON.parseObject(rowData,List.class);
        assertEquals(2, row.size());
        assertSame(row.get(0), row.get(1));
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                              "ket\":0B,\"fare_id\":80L,\"source_id\":4653492L,\"source_code\":32B,\"agent_sub_id\":2752916259,\"flights_limit\":\"1100-1999,4000-4999,8200-8230,8960\"},{\"$ref\":\"$[0]\"}]";
        List row = JSON.parseObject(rowData,List.class);
        assertEquals(2, row.size());
        assertSame(row.get(0), row.get(1));
    }
}

            

Reported by PMD.

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

Line: 20

                              "ket\":0B,\"fare_id\":80L,\"source_id\":4653492L,\"source_code\":32B,\"agent_sub_id\":2752916259,\"flights_limit\":\"1100-1999,4000-4999,8200-8230,8960\"},{\"$ref\":\"$[0]\"}]";
        List row = JSON.parseObject(rowData,List.class);
        assertEquals(2, row.size());
        assertSame(row.get(0), row.get(1));
    }
}

            

Reported by PMD.

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

              
public class IntArrayFieldTest_primitive extends TestCase {

    public void test_array() throws Exception {
        Assert.assertEquals("[1]", JSON.toJSONString(new int[] { 1 }));

    }

    public void test_codec_null() 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: 17

              
    }

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

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

                      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.

Returning 'value' may expose an internal array.
Design

Line: 46

                      private int[] value;

        public int[] getValue() {
            return value;
        }

        public void setValue(int[] value) {
            this.value = value;
        }

            

Reported by PMD.

The user-supplied array 'value' is stored directly.
Design

Line: 49

                          return value;
        }

        public void setValue(int[] value) {
            this.value = value;
        }

    }
}

            

Reported by PMD.

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

Line: 49

                          return value;
        }

        public void setValue(int[] value) {
            this.value = value;
        }

    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue569.java
7 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 15

               * Created by wenshao on 02/07/2017.
 */
public class Issue569 extends TestCase {
    public void test_for_issue() throws Exception {
        String jsonString = "{\"backingMap\":{\"a\":{\"b\":{}}}}";
        Type type = new TypeReference<MyTable<String, String, MyValue>>() {}.getType();
        MyTable<String, String, MyValue> table = JSON.parseObject(jsonString, type);

        Map<String, MyValue> valueMap = table.backingMap.get("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: 15

               * Created by wenshao on 02/07/2017.
 */
public class Issue569 extends TestCase {
    public void test_for_issue() throws Exception {
        String jsonString = "{\"backingMap\":{\"a\":{\"b\":{}}}}";
        Type type = new TypeReference<MyTable<String, String, MyValue>>() {}.getType();
        MyTable<String, String, MyValue> table = JSON.parseObject(jsonString, type);

        Map<String, MyValue> valueMap = table.backingMap.get("a");

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 20

                      Type type = new TypeReference<MyTable<String, String, MyValue>>() {}.getType();
        MyTable<String, String, MyValue> table = JSON.parseObject(jsonString, type);

        Map<String, MyValue> valueMap = table.backingMap.get("a");
        assertNotNull(valueMap);

        MyValue value = valueMap.get("b");
        assertNotNull(value);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      MyTable<String, String, MyValue> table = JSON.parseObject(jsonString, type);

        Map<String, MyValue> valueMap = table.backingMap.get("a");
        assertNotNull(valueMap);

        MyValue value = valueMap.get("b");
        assertNotNull(value);
    }


            

Reported by PMD.

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

Line: 23

                      Map<String, MyValue> valueMap = table.backingMap.get("a");
        assertNotNull(valueMap);

        MyValue value = valueMap.get("b");
        assertNotNull(value);
    }

    public static class MyTable<R, C, V> implements Serializable {
        private Map<R, Map<C, V>> backingMap;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                      assertNotNull(valueMap);

        MyValue value = valueMap.get("b");
        assertNotNull(value);
    }

    public static class MyTable<R, C, V> implements Serializable {
        private Map<R, Map<C, V>> backingMap;


            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 27

                      assertNotNull(value);
    }

    public static class MyTable<R, C, V> implements Serializable {
        private Map<R, Map<C, V>> backingMap;

        public Map<R, Map<C, V>> getBackingMap() {
            return backingMap;
        }

            

Reported by PMD.

src/test/java/com/alibaba/fastjson/deserializer/issues3796/bean/ObjectK1.java
7 issues
The class 'ObjectK1' is suspected to be a Data Class (WOC=0.000%, NOPA=0, NOAM=18, WMC=18)
Design

Line: 9

              import java.util.List;


public class ObjectK1 {

	
	private int a = 0;
	
	private boolean b = false;

            

Reported by PMD.

Avoid using redundant field initializer for 'a'
Performance

Line: 12

              public class ObjectK1 {

	
	private int a = 0;
	
	private boolean b = false;
	
	private int c = 0;
	

            

Reported by PMD.

Avoid using redundant field initializer for 'b'
Performance

Line: 14

              	
	private int a = 0;
	
	private boolean b = false;
	
	private int c = 0;
	
	private int d = 0;
	

            

Reported by PMD.

Avoid using redundant field initializer for 'c'
Performance

Line: 16

              	
	private boolean b = false;
	
	private int c = 0;
	
	private int d = 0;
	
	private int e = 0;
	

            

Reported by PMD.

Avoid using redundant field initializer for 'd'
Performance

Line: 18

              	
	private int c = 0;
	
	private int d = 0;
	
	private int e = 0;
	
	private List<CommonObject> f;
	

            

Reported by PMD.

Avoid using redundant field initializer for 'e'
Performance

Line: 20

              	
	private int d = 0;
	
	private int e = 0;
	
	private List<CommonObject> f;
	
	private List<ObjectK1_A> g;


            

Reported by PMD.

Avoid using redundant field initializer for 'h'
Performance

Line: 31

              

	
	private int h = 0;
	
	private List<ObjectK1_C> i;

	public int getA() {
		return a;

            

Reported by PMD.

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

              
public class Bug_for_issue_318 extends TestCase {

    public void test_for_issue() throws Exception {
        Person o1 = new Person("zhangsan", 20);
        Person o2 = new Person("liuXX", 30);
        Person o3 = new Person("Test", 10);

        List<Person> users = new ArrayList<Person>();

            

Reported by PMD.

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

Line: 59

              //        
//        System.out.println(JSON.toJSONString(target));
        
        Assert.assertNotNull(target.getUsers().get(0));
        Assert.assertNotNull(target.getManagers().get(0));
    }

    private static class Person {
        private String name;

            

Reported by PMD.

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

Line: 59

              //        
//        System.out.println(JSON.toJSONString(target));
        
        Assert.assertNotNull(target.getUsers().get(0));
        Assert.assertNotNull(target.getManagers().get(0));
    }

    private static class Person {
        private String name;

            

Reported by PMD.

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

Line: 60

              //        System.out.println(JSON.toJSONString(target));
        
        Assert.assertNotNull(target.getUsers().get(0));
        Assert.assertNotNull(target.getManagers().get(0));
    }

    private static class Person {
        private String name;
        private Integer age;

            

Reported by PMD.

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

Line: 60

              //        System.out.println(JSON.toJSONString(target));
        
        Assert.assertNotNull(target.getUsers().get(0));
        Assert.assertNotNull(target.getManagers().get(0));
    }

    private static class Person {
        private String name;
        private Integer age;

            

Reported by PMD.

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

Line: 63

                      Assert.assertNotNull(target.getManagers().get(0));
    }

    private static class Person {
        private String name;
        private Integer age;

        public Person(){}


            

Reported by PMD.

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

Line: 88

                      }
    }

    private static class PersonAll {
        private Map<String, List<Person>> userMap = new HashMap<String, List<Person>>();
        private Integer count;
        private List<Person> users;
        private List<Person> managers;


            

Reported by PMD.

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

    public void test_for_issue() throws Exception {
        String jsonContent = "{\"data\":{\"content\":\"xxx\",\"hour\":1}}";
        StatusBean<WorkBean> bean = JSONObject.parseObject(jsonContent,
                                      new TypeReference<StatusBean<WorkBean>>() {
                                    });
        

            

Reported by PMD.

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

Line: 21

                                                  });
        
        Assert.assertNotNull(bean.getData());
        Assert.assertEquals(1, bean.getData().getHour());
        Assert.assertEquals("xxx", bean.getData().getContent());
    }

    public static class StatusBean<T> {


            

Reported by PMD.

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

Line: 22

                      
        Assert.assertNotNull(bean.getData());
        Assert.assertEquals(1, bean.getData().getHour());
        Assert.assertEquals("xxx", bean.getData().getContent());
    }

    public static class StatusBean<T> {

        private int    code;

            

Reported by PMD.

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

Line: 25

                      Assert.assertEquals("xxx", bean.getData().getContent());
    }

    public static class StatusBean<T> {

        private int    code;
        private String msg;
        private T      data;


            

Reported by PMD.

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

Line: 57

              
    }

    public static class WorkBean {

        private int    hour;
        private String content;

        public int getHour() {

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSON'
Design

Line: 5

              
import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;

import junit.framework.TestCase;

            

Reported by PMD.

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

Line: 8

              import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;

import junit.framework.TestCase;

public class Bug_for_issue_330 extends TestCase {


            

Reported by PMD.