The following issues were found

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

    public void test_for_issue() {
        VO vo = new VO();
        vo.id = 123;
        vo.location = new Location(127, 37);

        Object obj = JSON.toJSON(vo);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        Object obj = JSON.toJSON(vo);
        String text = JSON.toJSONString(obj, SerializerFeature.SortField);
        assertEquals("{\"latitude\":37,\"id\":123,\"longitude\":127}", text);
    }

    public void test_for_issue2() {
        VO2 vo = new VO2();
        vo.id = 123;

            

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

                      assertEquals("{\"latitude\":37,\"id\":123,\"longitude\":127}", text);
    }

    public void test_for_issue2() {
        VO2 vo = new VO2();
        vo.id = 123;
        vo.properties.put("latitude", 37);
        vo.properties.put("longitude", 127);


            

Reported by PMD.

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

Line: 26

                  public void test_for_issue2() {
        VO2 vo = new VO2();
        vo.id = 123;
        vo.properties.put("latitude", 37);
        vo.properties.put("longitude", 127);

        Object obj = JSON.toJSON(vo);
        String text = JSON.toJSONString(obj, SerializerFeature.SortField);
        assertEquals("{\"latitude\":37,\"id\":123,\"longitude\":127}", text);

            

Reported by PMD.

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

Line: 27

                      VO2 vo = new VO2();
        vo.id = 123;
        vo.properties.put("latitude", 37);
        vo.properties.put("longitude", 127);

        Object obj = JSON.toJSON(vo);
        String text = JSON.toJSONString(obj, SerializerFeature.SortField);
        assertEquals("{\"latitude\":37,\"id\":123,\"longitude\":127}", text);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 31

              
        Object obj = JSON.toJSON(vo);
        String text = JSON.toJSONString(obj, SerializerFeature.SortField);
        assertEquals("{\"latitude\":37,\"id\":123,\"longitude\":127}", text);
    }

    public static class VO {

        public int id;

            

Reported by PMD.

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

Line: 36

              
    public static class VO {

        public int id;

        @JSONField(unwrapped = true)
        public Location location;
    }


            

Reported by PMD.

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

Line: 39

                      public int id;

        @JSONField(unwrapped = true)
        public Location location;
    }

    public static class VO2 {
        public int id;


            

Reported by PMD.

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

Line: 43

                  }

    public static class VO2 {
        public int id;

        @JSONField(unwrapped = true)
        public Map<String, Object> properties = new LinkedHashMap<String, Object>();
    }


            

Reported by PMD.

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

Line: 46

                      public int id;

        @JSONField(unwrapped = true)
        public Map<String, Object> properties = new LinkedHashMap<String, Object>();
    }


    public static class Location {
        public int longitude;

            

Reported by PMD.

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

Line: 23

                      entry.setUrl("http://www.springframework.org/schema/aop");
        String jsonString = JSONObject.toJSONString(entry);
        String arrayString = JSONObject.toJSONString(list);
        System.out.println(jsonString);
        System.out.println(arrayString);
        list = JSONArray.parseArray(arrayString, OuterEntry.class);
        JSONArray array = JSONArray.parseArray(arrayString);// 这一步出错
    }


            

Reported by PMD.

System.out.println is used
Design

Line: 24

                      String jsonString = JSONObject.toJSONString(entry);
        String arrayString = JSONObject.toJSONString(list);
        System.out.println(jsonString);
        System.out.println(arrayString);
        list = JSONArray.parseArray(arrayString, OuterEntry.class);
        JSONArray array = JSONArray.parseArray(arrayString);// 这一步出错
    }

    @Test

            

Reported by PMD.

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

Line: 15

              public class JSONTest {

    @Test
    public void testParseArray() throws Exception {
        List list = new ArrayList();
        OuterEntry entry = new OuterEntry();
        list.add(entry);
        entry.setId(1000L);
        entry.setUrl("http://www.springframework.org/schema/aop");

            

Reported by PMD.

The value assigned to variable 'list' is never used
Design

Line: 25

                      String arrayString = JSONObject.toJSONString(list);
        System.out.println(jsonString);
        System.out.println(arrayString);
        list = JSONArray.parseArray(arrayString, OuterEntry.class);
        JSONArray array = JSONArray.parseArray(arrayString);// 这一步出错
    }

    @Test
    public void testInnerEntry() throws Exception {

            

Reported by PMD.

Avoid unused local variables such as 'array'.
Design

Line: 26

                      System.out.println(jsonString);
        System.out.println(arrayString);
        list = JSONArray.parseArray(arrayString, OuterEntry.class);
        JSONArray array = JSONArray.parseArray(arrayString);// 这一步出错
    }

    @Test
    public void testInnerEntry() throws Exception {
        List list = new ArrayList();

            

Reported by PMD.

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

Line: 30

                  }

    @Test
    public void testInnerEntry() throws Exception {
        List list = new ArrayList();
        InnerEntry entry = new InnerEntry();
        list.add(entry);
        entry.setId(1000L);
        entry.setUrl("http://www.springframework.org/schema/aop");

            

Reported by PMD.

Avoid unused local variables such as 'jsonString'.
Design

Line: 36

                      list.add(entry);
        entry.setId(1000L);
        entry.setUrl("http://www.springframework.org/schema/aop");
        String jsonString = JSONObject.toJSONString(entry);// //这一步出错
    }

    class InnerEntry {

        private Long   id;

            

Reported by PMD.

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

Line: 39

                      String jsonString = JSONObject.toJSONString(entry);// //这一步出错
    }

    class InnerEntry {

        private Long   id;
        private String url;

        public Long getId() {

            

Reported by PMD.

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

Line: 61

                      }
    }

    public static class OuterEntry {

        private Long   id;
        private String url;

        public Long getId() {

            

Reported by PMD.

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

Line: 25

                      String arrayString = JSONObject.toJSONString(list);
        System.out.println(jsonString);
        System.out.println(arrayString);
        list = JSONArray.parseArray(arrayString, OuterEntry.class);
        JSONArray array = JSONArray.parseArray(arrayString);// 这一步出错
    }

    @Test
    public void testInnerEntry() throws Exception {

            

Reported by PMD.

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

    public void test_ref() throws Exception {
        Object[] array = new Object[1];
        array[0] = array;
        Assert.assertEquals("[{\"$ref\":\"@\"}]", JSON.toJSONString(array));
    }


            

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("[{\"$ref\":\"@\"}]", JSON.toJSONString(array));
    }

    public void test_ref_1() throws Exception {
        Object[] array = new Object[3];
        array[0] = array;
        array[1] = new Object();
        array[2] = new Object();
        Assert.assertEquals("[{\"$ref\":\"@\"},{},{}]", JSON.toJSONString(array));

            

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

                      Assert.assertEquals("[{\"$ref\":\"@\"},{},{}]", JSON.toJSONString(array));
    }

    public void test_ref_2() throws Exception {
        Object[] array = new Object[3];
        array[0] = new Object();
        array[1] = array;
        array[2] = new Object();
        Assert.assertEquals("[{},{\"$ref\":\"@\"},{}]", JSON.toJSONString(array));

            

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

                      Assert.assertEquals("[{},{\"$ref\":\"@\"},{}]", JSON.toJSONString(array));
    }

    public void test_ref_3() throws Exception {
        Object[] array = new Object[3];
        array[0] = new Object();
        array[1] = new Object();
        array[2] = array;
        Assert.assertEquals("[{},{},{\"$ref\":\"@\"}]", JSON.toJSONString(array));

            

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

                      Assert.assertEquals("[{},{},{\"$ref\":\"@\"}]", JSON.toJSONString(array));
    }

    public void test_parse() throws Exception {
        Object[] array2 = JSON.parseObject("[{\"$ref\":\"$\"}]", Object[].class);
        Assert.assertSame(array2, array2[0]);
    }

    public void test_parse_1() 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: 46

                      Assert.assertSame(array2, array2[0]);
    }

    public void test_parse_1() throws Exception {
        Object[] array2 = JSON.parseObject("[{\"$ref\":\"@\"}]", Object[].class);
        Assert.assertSame(array2, array2[0]);
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '19'-'20').
Error

Line: 19

              
    public void test_ref_1() throws Exception {
        Object[] array = new Object[3];
        array[0] = array;
        array[1] = new Object();
        array[2] = new Object();
        Assert.assertEquals("[{\"$ref\":\"@\"},{},{}]", JSON.toJSONString(array));
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '20'-'21').
Error

Line: 20

                  public void test_ref_1() throws Exception {
        Object[] array = new Object[3];
        array[0] = array;
        array[1] = new Object();
        array[2] = new Object();
        Assert.assertEquals("[{\"$ref\":\"@\"},{},{}]", JSON.toJSONString(array));
    }

    public void test_ref_2() throws Exception {

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '26'-'27').
Error

Line: 26

                  }

    public void test_ref_2() throws Exception {
        Object[] array = new Object[3];
        array[0] = new Object();
        array[1] = array;
        array[2] = new Object();
        Assert.assertEquals("[{},{\"$ref\":\"@\"},{}]", JSON.toJSONString(array));
    }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '28'-'29').
Error

Line: 28

                  public void test_ref_2() throws Exception {
        Object[] array = new Object[3];
        array[0] = new Object();
        array[1] = array;
        array[2] = new Object();
        Assert.assertEquals("[{},{\"$ref\":\"@\"},{}]", JSON.toJSONString(array));
    }

    public void test_ref_3() throws Exception {

            

Reported by PMD.

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

    public void test_jsonField() throws Exception {
        Health vo = new Health();
        List<String> cities = new ArrayList<String>();
        cities.add("Beijing");
        cities.add("Shanghai");
        vo.id = 123;

            

Reported by PMD.

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

Line: 13

              
public class JSONFieldTest_unwrapped_6 extends TestCase {

    public void test_jsonField() throws Exception {
        Health vo = new Health();
        List<String> cities = new ArrayList<String>();
        cities.add("Beijing");
        cities.add("Shanghai");
        vo.id = 123;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                      Assert.assertEquals("{\"cities\":[\"Beijing\",\"Shanghai\"],\"id\":123}", text);

        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.cities);
        assertEquals("Beijing", vo2.cities.get(0));
        assertEquals("Shanghai", vo2.cities.get(1));

    }


            

Reported by PMD.

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

Line: 26

              
        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.cities);
        assertEquals("Beijing", vo2.cities.get(0));
        assertEquals("Shanghai", vo2.cities.get(1));

    }

    public void test_null() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

              
        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.cities);
        assertEquals("Beijing", vo2.cities.get(0));
        assertEquals("Shanghai", vo2.cities.get(1));

    }

    public void test_null() throws Exception {

            

Reported by PMD.

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

Line: 27

                      Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.cities);
        assertEquals("Beijing", vo2.cities.get(0));
        assertEquals("Shanghai", vo2.cities.get(1));

    }

    public void test_null() throws Exception {
        Health vo = new Health();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

                      Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.cities);
        assertEquals("Beijing", vo2.cities.get(0));
        assertEquals("Shanghai", vo2.cities.get(1));

    }

    public void test_null() throws Exception {
        Health vo = new Health();

            

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

              
    }

    public void test_null() throws Exception {
        Health vo = new Health();
        vo.id = 123;
        vo.cities = null;

        String text = JSON.toJSONString(vo);

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 34

                  public void test_null() throws Exception {
        Health vo = new Health();
        vo.id = 123;
        vo.cities = null;

        String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"id\":123}", 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: 40

                      Assert.assertEquals("{\"id\":123}", text);
    }

    public void test_empty() throws Exception {
        Health vo = new Health();
        vo.id = 123;

        String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"id\":123}", text);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/deny/InitJavaBeanDeserializerTest.java
12 issues
System.out.println is used
Design

Line: 36

                      Exception error = null;
        try {
            Object obj = JSON.parseObject(text, Object.class, config);
            System.out.println(obj.getClass());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNotNull(error);


            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 28/01/2017.
 */
public class InitJavaBeanDeserializerTest extends TestCase {
    ParserConfig config = new ParserConfig();

    protected void setUp() throws Exception {
        assertFalse(config.isAutoTypeSupport());

        Properties properties = new Properties();

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 16

              public class InitJavaBeanDeserializerTest extends TestCase {
    ParserConfig config = new ParserConfig();

    protected void setUp() throws Exception {
        assertFalse(config.isAutoTypeSupport());

        Properties properties = new Properties();
        properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
        // config.addAccept("com.alibaba.json.bvt.parser.deser.deny.DenyTest11.Model");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                  ParserConfig config = new ParserConfig();

    protected void setUp() throws Exception {
        assertFalse(config.isAutoTypeSupport());

        Properties properties = new Properties();
        properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
        // config.addAccept("com.alibaba.json.bvt.parser.deser.deny.DenyTest11.Model");
        // -ea -Dfastjson.parser.autoTypeAccept=com.alibaba.json.bvt.parser.deser.deny.DenyTest9

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                      // -ea -Dfastjson.parser.autoTypeAccept=com.alibaba.json.bvt.parser.deser.deny.DenyTest9
        config.configFromPropety(properties);

        assertFalse(config.isAutoTypeSupport());
    }

    public void test_desktop() throws Exception {
        DenyTest11.Model model = new DenyTest11.Model();
        model.a = new DenyTest11.B();

            

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

                      assertFalse(config.isAutoTypeSupport());
    }

    public void test_desktop() throws Exception {
        DenyTest11.Model model = new DenyTest11.Model();
        model.a = new DenyTest11.B();
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.InitJavaBeanDeserializerTest$Model\"}";

        Exception error = null;

            

Reported by PMD.

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

Line: 28

                      assertFalse(config.isAutoTypeSupport());
    }

    public void test_desktop() throws Exception {
        DenyTest11.Model model = new DenyTest11.Model();
        model.a = new DenyTest11.B();
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.InitJavaBeanDeserializerTest$Model\"}";

        Exception error = null;

            

Reported by PMD.

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

Line: 36

                      Exception error = null;
        try {
            Object obj = JSON.parseObject(text, Object.class, config);
            System.out.println(obj.getClass());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNotNull(error);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

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

        config.initJavaBeanDeserializers(Model.class);

        Object obj = JSON.parseObject(text, Object.class, config);
        assertEquals(Model.class, obj.getClass());

            

Reported by PMD.

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

Line: 45

                      config.initJavaBeanDeserializers(Model.class);

        Object obj = JSON.parseObject(text, Object.class, config);
        assertEquals(Model.class, obj.getClass());
    }

    public static class Model {

    }

            

Reported by PMD.

src/test/java/com/alibaba/json/demo/FilterDemo.java
12 issues
System.out.println is used
Design

Line: 46

                      serializer.write(object);

        String outText = out.toString();
        System.out.println(outText);
    }
}

            

Reported by PMD.

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

Line: 13

              
public class FilterDemo extends TestCase {

    public void test_secure() throws Exception {

        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {

            

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

    public void test_secure() throws Exception {

        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 18

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "WSJ";
                }
                return value;
            }
        };

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 18

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "WSJ";
                }
                return value;
            }
        };

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 27

              
        NameFilter nameFilter = new NameFilter() {
            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "ID";
                }
                return name;
            }
        };

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 27

              
        NameFilter nameFilter = new NameFilter() {
            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "ID";
                }
                return name;
            }
        };

            

Reported by PMD.

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

Line: 40

              
        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getValueFilters().add(filter);
        serializer.getNameFilters().add(nameFilter);

        serializer.write(object);

        String outText = out.toString();

            

Reported by PMD.

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

Line: 41

                      SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getValueFilters().add(filter);
        serializer.getNameFilters().add(nameFilter);

        serializer.write(object);

        String outText = out.toString();
        System.out.println(outText);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '15'-'47').
Error

Line: 15

              
    public void test_secure() throws Exception {

        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "WSJ";
                }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/filters/NameFilterTest_int_field.java
12 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

              
public class NameFilterTest_int_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 19

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);
                    return "ID";
                }

                return name;

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 19

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);
                    return "ID";
                }

                return name;

            

Reported by PMD.

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

Line: 31

              
        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getNameFilters().add(filter);

        Bean a = new Bean();
        serializer.write(a);

        String text = out.toString();

            

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

                      Assert.assertEquals("{\"ID\":0}", text);
    }

    public void test_namefilter_1() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "ID";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 44

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "ID";
                }

                return name;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 44

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "ID";
                }

                return name;
            }

            

Reported by PMD.

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

Line: 55

              
        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getNameFilters().add(filter);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", 0);
        serializer.write(map);


            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '16'-'38').
Error

Line: 16

              public class NameFilterTest_int_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);
                    return "ID";

            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '16'-'38').
Error

Line: 16

              public class NameFilterTest_int_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);
                    return "ID";

            

Reported by PMD.

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

               * Created by wenshao on 30/05/2017.
 */
public class Issue1235 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 30/05/2017.
 */
public class Issue1235 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              
        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }

    @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 27

              
    @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 28

                  @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")
    public static class FloorV2 implements Area {

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 29

                  public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")
    public static class FloorV2 implements Area {
        public String type;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/filters/NameFilterTest_long_field.java
12 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

              
public class NameFilterTest_long_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 19

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);
                    return "ID";
                }

                return name;

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 19

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);
                    return "ID";
                }

                return name;

            

Reported by PMD.

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

Line: 31

              
        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getNameFilters().add(filter);

        Bean a = new Bean();
        serializer.write(a);

        String text = out.toString();

            

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

                      Assert.assertEquals("{\"ID\":0}", text);
    }

    public void test_namefilter_1() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "ID";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 44

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "ID";
                }

                return name;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 44

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "ID";
                }

                return name;
            }

            

Reported by PMD.

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

Line: 55

              
        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getNameFilters().add(filter);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", 0);
        serializer.write(map);


            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '16'-'38').
Error

Line: 16

              public class NameFilterTest_long_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);
                    return "ID";

            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '16'-'38').
Error

Line: 16

              public class NameFilterTest_long_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);
                    return "ID";

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 06/12/2016.
 */
public class Issue912 extends TestCase {
    public void test_for_issue() throws Exception {
        String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(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: 14

               * Created by wenshao on 06/12/2016.
 */
public class Issue912 extends TestCase {
    public void test_for_issue() throws Exception {
        String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {

            

Reported by PMD.

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

Line: 18

                      String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {

            

Reported by PMD.

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

Line: 18

                      String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {

            

Reported by PMD.

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

Line: 19

                      JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {
        T jd = (T) JSON.parseObject(json, clazz,

            

Reported by PMD.

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

Line: 19

                      JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {
        T jd = (T) JSON.parseObject(json, clazz,

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {
        T jd = (T) JSON.parseObject(json, clazz,
                Feature.IgnoreNotMatch,

            

Reported by PMD.

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

Line: 32

                  }

    public static class JsonBean {
        private List<SCFMethod> mList;

        public List<SCFMethod> getmList() {
            return mList;
        }


            

Reported by PMD.

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

Line: 43

                      }
    }

    public static class SCFMethod {
        public String className;
        public String url;
        public String methodName;
        public int parameterSize;
        public List<SCFMethodParameter> parameters = new LinkedList<SCFMethodParameter>();

            

Reported by PMD.