The following issues were found

src/test/java/com/alibaba/json/bvt/parser/deser/generic/GenericTest.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: 10

              
public class GenericTest extends TestCase {
    
    public void test_0 () throws Exception {
       B b = JSON.parseObject("{\"data\":[1,2,3]}", B.class);
       b.get(0);
    }

    public static abstract class A<T> {

            

Reported by PMD.

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

Line: 10

              
public class GenericTest extends TestCase {
    
    public void test_0 () throws Exception {
       B b = JSON.parseObject("{\"data\":[1,2,3]}", B.class);
       b.get(0);
    }

    public static abstract class A<T> {

            

Reported by PMD.

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

Line: 12

                  
    public void test_0 () throws Exception {
       B b = JSON.parseObject("{\"data\":[1,2,3]}", B.class);
       b.get(0);
    }

    public static abstract class A<T> {
        T[] data;
        

            

Reported by PMD.

This abstract class does not have any abstract methods
Design

Line: 15

                     b.get(0);
    }

    public static abstract class A<T> {
        T[] data;
        
        public A() {
            
        }

            

Reported by PMD.

Returning 'data' may expose an internal array.
Design

Line: 25

              
        
        public T[] getData() {
            return data;
        }


        
        public void setData(T[] data) {

            

Reported by PMD.

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

Line: 30

              

        
        public void setData(T[] data) {
            this.data = data;
        }
    }
    
    public static class B extends A<Long> {

            

Reported by PMD.

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

Line: 46

                  }
    
    public static class C<T> {
        private T[] data;
        
        public C(T[] data) {
            this.data = data;
        }


            

Reported by PMD.

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

Line: 46

                  }
    
    public static class C<T> {
        private T[] data;
        
        public C(T[] data) {
            this.data = data;
        }


            

Reported by PMD.

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

Line: 48

                  public static class C<T> {
        private T[] data;
        
        public C(T[] data) {
            this.data = data;
        }

        
        public T[] getData() {

            

Reported by PMD.

Returning 'data' may expose an internal array.
Design

Line: 54

              
        
        public T[] getData() {
            return data;
        }
        
    }
}

            

Reported by PMD.

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

Line: 14

                  public void test_for_issue() throws Exception {
        String userStr1 = "{\"id\":\"qfHdV0ez0N10\", \"ext\":{\"model\": \"10000\"} }";
        User user = JSON.parseObject(userStr1, User.class);
        System.out.println(user);
    }

    public void test_for_issue_1() throws Exception {
        String text = "{\"model\":\"10002\" }";
        UserExt ext = JSON.parseObject(text, UserExt.class);

            

Reported by PMD.

System.out.println is used
Design

Line: 26

                      String userStr2 = "{\"id\":\"qfHdV0ez0N10\", \"ext\":{\"model\":\"10000\" } }";

        User user = JSON.parseObject(userStr2, User.class);
        System.out.println(user);
    }

    public static class User {

        private String  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 Bug_for_yuanmomo_Issue_505_1 extends TestCase {

    public void test_for_issue() throws Exception {
        String userStr1 = "{\"id\":\"qfHdV0ez0N10\", \"ext\":{\"model\": \"10000\"} }";
        User user = JSON.parseObject(userStr1, User.class);
        System.out.println(user);
    }


            

Reported by PMD.

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

Line: 11

              
public class Bug_for_yuanmomo_Issue_505_1 extends TestCase {

    public void test_for_issue() throws Exception {
        String userStr1 = "{\"id\":\"qfHdV0ez0N10\", \"ext\":{\"model\": \"10000\"} }";
        User user = JSON.parseObject(userStr1, User.class);
        System.out.println(user);
    }


            

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

                      System.out.println(user);
    }

    public void test_for_issue_1() throws Exception {
        String text = "{\"model\":\"10002\" }";
        UserExt ext = JSON.parseObject(text, UserExt.class);
    }

    public void test_for_issue_2() throws Exception {

            

Reported by PMD.

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

Line: 17

                      System.out.println(user);
    }

    public void test_for_issue_1() throws Exception {
        String text = "{\"model\":\"10002\" }";
        UserExt ext = JSON.parseObject(text, UserExt.class);
    }

    public void test_for_issue_2() throws Exception {

            

Reported by PMD.

Avoid unused local variables such as 'ext'.
Design

Line: 19

              
    public void test_for_issue_1() throws Exception {
        String text = "{\"model\":\"10002\" }";
        UserExt ext = JSON.parseObject(text, UserExt.class);
    }

    public void test_for_issue_2() throws Exception {
        String userStr2 = "{\"id\":\"qfHdV0ez0N10\", \"ext\":{\"model\":\"10000\" } }";


            

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

                      UserExt ext = JSON.parseObject(text, UserExt.class);
    }

    public void test_for_issue_2() throws Exception {
        String userStr2 = "{\"id\":\"qfHdV0ez0N10\", \"ext\":{\"model\":\"10000\" } }";

        User user = JSON.parseObject(userStr2, User.class);
        System.out.println(user);
    }

            

Reported by PMD.

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

Line: 22

                      UserExt ext = JSON.parseObject(text, UserExt.class);
    }

    public void test_for_issue_2() throws Exception {
        String userStr2 = "{\"id\":\"qfHdV0ez0N10\", \"ext\":{\"model\":\"10000\" } }";

        User user = JSON.parseObject(userStr2, User.class);
        System.out.println(user);
    }

            

Reported by PMD.

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

Line: 29

                      System.out.println(user);
    }

    public static class User {

        private String  id;
        private UserExt ext;

        public String getId() {

            

Reported by PMD.

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

              import junit.framework.TestCase;

public class Issue2164 extends TestCase {
    public void test_for_issue() throws Exception {
        java.sql.Timestamp ts = new java.sql.Timestamp(-65001600000L);
        String json = JSON.toJSONString(ts);
        assertEquals("-65001600000", json);
        java.sql.Timestamp ts2 = JSON.parseObject(json, java.sql.Timestamp.class);
        assertEquals(ts.getTime(), ts2.getTime());

            

Reported by PMD.

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

Line: 7

              import junit.framework.TestCase;

public class Issue2164 extends TestCase {
    public void test_for_issue() throws Exception {
        java.sql.Timestamp ts = new java.sql.Timestamp(-65001600000L);
        String json = JSON.toJSONString(ts);
        assertEquals("-65001600000", json);
        java.sql.Timestamp ts2 = JSON.parseObject(json, java.sql.Timestamp.class);
        assertEquals(ts.getTime(), ts2.getTime());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 10

                  public void test_for_issue() throws Exception {
        java.sql.Timestamp ts = new java.sql.Timestamp(-65001600000L);
        String json = JSON.toJSONString(ts);
        assertEquals("-65001600000", json);
        java.sql.Timestamp ts2 = JSON.parseObject(json, java.sql.Timestamp.class);
        assertEquals(ts.getTime(), ts2.getTime());
    }

    public void test_for_issue_1() throws Exception {

            

Reported by PMD.

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

Line: 12

                      String json = JSON.toJSONString(ts);
        assertEquals("-65001600000", json);
        java.sql.Timestamp ts2 = JSON.parseObject(json, java.sql.Timestamp.class);
        assertEquals(ts.getTime(), ts2.getTime());
    }

    public void test_for_issue_1() throws Exception {
        Model m = new Model(-65001600000L);
        String json = JSON.toJSONString(m);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

                      String json = JSON.toJSONString(ts);
        assertEquals("-65001600000", json);
        java.sql.Timestamp ts2 = JSON.parseObject(json, java.sql.Timestamp.class);
        assertEquals(ts.getTime(), ts2.getTime());
    }

    public void test_for_issue_1() throws Exception {
        Model m = new Model(-65001600000L);
        String json = JSON.toJSONString(m);

            

Reported by PMD.

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

Line: 15

                      assertEquals(ts.getTime(), ts2.getTime());
    }

    public void test_for_issue_1() throws Exception {
        Model m = new Model(-65001600000L);
        String json = JSON.toJSONString(m);
        assertEquals("{\"time\":-65001600000}", json);
        Model m2 = JSON.parseObject(json, Model.class);
        assertEquals(m.time.getTime(), m2.time.getTime());

            

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

                      assertEquals(ts.getTime(), ts2.getTime());
    }

    public void test_for_issue_1() throws Exception {
        Model m = new Model(-65001600000L);
        String json = JSON.toJSONString(m);
        assertEquals("{\"time\":-65001600000}", json);
        Model m2 = JSON.parseObject(json, Model.class);
        assertEquals(m.time.getTime(), m2.time.getTime());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                  public void test_for_issue_1() throws Exception {
        Model m = new Model(-65001600000L);
        String json = JSON.toJSONString(m);
        assertEquals("{\"time\":-65001600000}", json);
        Model m2 = JSON.parseObject(json, Model.class);
        assertEquals(m.time.getTime(), m2.time.getTime());
    }

    public static class Model {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      String json = JSON.toJSONString(m);
        assertEquals("{\"time\":-65001600000}", json);
        Model m2 = JSON.parseObject(json, Model.class);
        assertEquals(m.time.getTime(), m2.time.getTime());
    }

    public static class Model {
        public java.sql.Timestamp time;


            

Reported by PMD.

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

Line: 20

                      String json = JSON.toJSONString(m);
        assertEquals("{\"time\":-65001600000}", json);
        Model m2 = JSON.parseObject(json, Model.class);
        assertEquals(m.time.getTime(), m2.time.getTime());
    }

    public static class Model {
        public java.sql.Timestamp time;


            

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/bvt/LongFieldTest_2.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: 16

              
public class LongFieldTest_2 extends TestCase {

    public void test_min() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v);


            

Reported by PMD.

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

Line: 24

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

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

    public void test_min_reader() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

            

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

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

    public void test_min_reader() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v);


            

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

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_max() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MAX_VALUE);

        String text = JSON.toJSONString(v);


            

Reported by PMD.

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

Line: 46

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

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

    public void test_max_reader() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MAX_VALUE);

            

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

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

    public void test_max_reader() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MAX_VALUE);

        String text = JSON.toJSONString(v);


            

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

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_min_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);


            

Reported by PMD.

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

Line: 68

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

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

    public void test_min_array_reader() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

            

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

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

    public void test_min_array_reader() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);


            

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

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_max_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MAX_VALUE);

        String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);


            

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/bug/Bug_for_wangran1.java
12 issues
System.out.println is used
Design

Line: 26

                      
        String text = JSON.toJSONString(entity);
        
        System.out.println(text);
        
        Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());

            

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

    public void test_0() throws Exception {
        Entity entity = new Entity();
        
        entity.setId(11);
        entity.setName("xx");
        

            

Reported by PMD.

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

Line: 22

                      Queue q = new Queue();
        q.setId(55);
        
        entity.getQueue().put(q.getId(), q);
        
        String text = JSON.toJSONString(entity);
        
        System.out.println(text);
        

            

Reported by PMD.

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

Line: 30

                      
        Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

            

Reported by PMD.

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

Line: 31

                      Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 31

                      Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 32

                      
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

        private int                 id;

            

Reported by PMD.

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

Line: 32

                      
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

        private int                 id;

            

Reported by PMD.

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

Line: 32

                      
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

        private int                 id;

            

Reported by PMD.

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

Line: 32

                      
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

        private int                 id;

            

Reported by PMD.

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

Line: 26

                      set.add(new B1());
        a.setList(set);
        String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
        System.out.println(text);
//        Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set3$A\",\"list\":[{},{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set3$B1\"}]}",
//                            text);

        A a1 = (A) JSON.parse(text);


            

Reported by PMD.

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

Line: 15

              import com.alibaba.fastjson.serializer.SerializerFeature;

public class WriteClassNameTest_Set3 extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set3");
    }

    public void test_list() throws Exception {
        A a = new A();

            

Reported by PMD.

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

Line: 16

              
public class WriteClassNameTest_Set3 extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set3");
    }

    public void test_list() throws Exception {
        A a = new A();
        LinkedHashSet<B> set = new LinkedHashSet<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: 19

                      ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set3");
    }

    public void test_list() throws Exception {
        A a = new A();
        LinkedHashSet<B> set = new LinkedHashSet<B>();
        set.add(new B());
        set.add(new B1());
        a.setList(set);

            

Reported by PMD.

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

Line: 32

              
        A a1 = (A) JSON.parse(text);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue(new ArrayList<B>(a1.getList()).get(0) instanceof B);
        Assert.assertTrue(new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

            

Reported by PMD.

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

Line: 32

              
        A a1 = (A) JSON.parse(text);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue(new ArrayList<B>(a1.getList()).get(0) instanceof B);
        Assert.assertTrue(new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

            

Reported by PMD.

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

Line: 33

                      A a1 = (A) JSON.parse(text);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue(new ArrayList<B>(a1.getList()).get(0) instanceof B);
        Assert.assertTrue(new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {


            

Reported by PMD.

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

Line: 34

              
        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue(new ArrayList<B>(a1.getList()).get(0) instanceof B);
        Assert.assertTrue(new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

        private LinkedHashSet<B> list;

            

Reported by PMD.

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

Line: 39

              
    private static class A {

        private LinkedHashSet<B> list;

        public LinkedHashSet<B> getList() {
            return list;
        }


            

Reported by PMD.

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

Line: 41

              
        private LinkedHashSet<B> list;

        public LinkedHashSet<B> getList() {
            return list;
        }

        public void setList(LinkedHashSet<B> list) {
            this.list = list;

            

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.

src/main/java/com/alibaba/fastjson/serializer/StringCodec.java
12 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 46

                          return;
        }

        out.writeString(value);
    }

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
        if (clazz == StringBuffer.class) {

            

Reported by PMD.

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

Line: 53

                  public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
        if (clazz == StringBuffer.class) {
            final JSONLexer lexer = parser.lexer;
            if (lexer.token() == JSONToken.LITERAL_STRING) {
                String val = lexer.stringVal();
                lexer.nextToken(JSONToken.COMMA);

                return (T) new StringBuffer(val);
            }

            

Reported by PMD.

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

Line: 54

                      if (clazz == StringBuffer.class) {
            final JSONLexer lexer = parser.lexer;
            if (lexer.token() == JSONToken.LITERAL_STRING) {
                String val = lexer.stringVal();
                lexer.nextToken(JSONToken.COMMA);

                return (T) new StringBuffer(val);
            }


            

Reported by PMD.

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

Line: 55

                          final JSONLexer lexer = parser.lexer;
            if (lexer.token() == JSONToken.LITERAL_STRING) {
                String val = lexer.stringVal();
                lexer.nextToken(JSONToken.COMMA);

                return (T) new StringBuffer(val);
            }

            Object value = parser.parse();

            

Reported by PMD.

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

Line: 66

                              return null;
            }

            return (T) new StringBuffer(value.toString());
        }

        if (clazz == StringBuilder.class) {
            final JSONLexer lexer = parser.lexer;
            if (lexer.token() == JSONToken.LITERAL_STRING) {

            

Reported by PMD.

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

Line: 71

              
        if (clazz == StringBuilder.class) {
            final JSONLexer lexer = parser.lexer;
            if (lexer.token() == JSONToken.LITERAL_STRING) {
                String val = lexer.stringVal();
                lexer.nextToken(JSONToken.COMMA);

                return (T) new StringBuilder(val);
            }

            

Reported by PMD.

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

Line: 72

                      if (clazz == StringBuilder.class) {
            final JSONLexer lexer = parser.lexer;
            if (lexer.token() == JSONToken.LITERAL_STRING) {
                String val = lexer.stringVal();
                lexer.nextToken(JSONToken.COMMA);

                return (T) new StringBuilder(val);
            }


            

Reported by PMD.

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

Line: 73

                          final JSONLexer lexer = parser.lexer;
            if (lexer.token() == JSONToken.LITERAL_STRING) {
                String val = lexer.stringVal();
                lexer.nextToken(JSONToken.COMMA);

                return (T) new StringBuilder(val);
            }

            Object value = parser.parse();

            

Reported by PMD.

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

Line: 84

                              return null;
            }

            return (T) new StringBuilder(value.toString());
        }

        return (T) deserialze(parser);
    }


            

Reported by PMD.

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

Line: 93

                  @SuppressWarnings("unchecked")
    public static <T> T deserialze(DefaultJSONParser parser) {
        final JSONLexer lexer = parser.getLexer();
        if (lexer.token() == JSONToken.LITERAL_STRING) {
            String val = lexer.stringVal();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val;
        }


            

Reported by PMD.