The following issues were found

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

Line: 29

                      GroovyObject aa = (GroovyObject) JSON.parseObject(textA, AClass);
        Assert.assertEquals(a.getProperty("id"), aa.getProperty("id"));
        
        System.out.println(a);

        // B类,继承于A
        Class BClass = loader.parseClass("class B extends A {\n" + //
        		"    String name\n" + //
        		"}");

            

Reported by PMD.

System.out.println is used
Design

Line: 46

                      

        // 序列化失败
        System.out.println(JSON.toJSONString(b, true));
    }
}

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 12

              
public class GroovyTest extends TestCase {

    public void test_groovy() throws Exception {
        ClassLoader parent = Thread.currentThread().getContextClassLoader();
        GroovyClassLoader loader = new GroovyClassLoader(parent);

        // A类
        Class AClass = loader.parseClass("class A {\n" + //

            

Reported by PMD.

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

Line: 13

              public class GroovyTest extends TestCase {

    public void test_groovy() throws Exception {
        ClassLoader parent = Thread.currentThread().getContextClassLoader();
        GroovyClassLoader loader = new GroovyClassLoader(parent);

        // A类
        Class AClass = loader.parseClass("class A {\n" + //
                                         "    int id\n" + //

            

Reported by PMD.

Ensure that resources like this GroovyClassLoader object are closed after use
Error

Line: 14

              
    public void test_groovy() throws Exception {
        ClassLoader parent = Thread.currentThread().getContextClassLoader();
        GroovyClassLoader loader = new GroovyClassLoader(parent);

        // A类
        Class AClass = loader.parseClass("class A {\n" + //
                                         "    int id\n" + //
                                         "}");

            

Reported by PMD.

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

Line: 22

                                                       "}");

        // A实例
        GroovyObject a = (GroovyObject) AClass.newInstance();
        a.setProperty("id", 33);
        String textA = JSON.toJSONString(a);
        
        GroovyObject aa = (GroovyObject) JSON.parseObject(textA, AClass);
        Assert.assertEquals(a.getProperty("id"), aa.getProperty("id"));

            

Reported by PMD.

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

Line: 23

              
        // A实例
        GroovyObject a = (GroovyObject) AClass.newInstance();
        a.setProperty("id", 33);
        String textA = JSON.toJSONString(a);
        
        GroovyObject aa = (GroovyObject) JSON.parseObject(textA, AClass);
        Assert.assertEquals(a.getProperty("id"), aa.getProperty("id"));
        

            

Reported by PMD.

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

Line: 27

                      String textA = JSON.toJSONString(a);
        
        GroovyObject aa = (GroovyObject) JSON.parseObject(textA, AClass);
        Assert.assertEquals(a.getProperty("id"), aa.getProperty("id"));
        
        System.out.println(a);

        // B类,继承于A
        Class BClass = loader.parseClass("class B extends A {\n" + //

            

Reported by PMD.

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

Line: 27

                      String textA = JSON.toJSONString(a);
        
        GroovyObject aa = (GroovyObject) JSON.parseObject(textA, AClass);
        Assert.assertEquals(a.getProperty("id"), aa.getProperty("id"));
        
        System.out.println(a);

        // B类,继承于A
        Class BClass = loader.parseClass("class B extends A {\n" + //

            

Reported by PMD.

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

Line: 37

                      		"}");

        // B实例
        GroovyObject b = (GroovyObject) BClass.newInstance();
        b.setProperty("name", "jobs");
        String textB = JSON.toJSONString(b);
        GroovyObject bb = (GroovyObject) JSON.parseObject(textB, BClass);
        Assert.assertEquals(b.getProperty("id"), bb.getProperty("id"));
        Assert.assertEquals(b.getProperty("name"), bb.getProperty("name"));

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/DefaultObjectDeserializerTest5.java
15 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 DefaultObjectDeserializerTest5 extends TestCase {

    public void test_error() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[]", new TypeReference<Map<Object, Object>>() {
            });
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 20

                      try {
            JSON.parseObject("[]", new TypeReference<Map<Object, Object>>() {
            });
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }


            

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

                      Assert.assertNotNull(error);
    }

    public void test_error_2() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject(",]", new TypeReference<Map<Object, Object>>() {
            });
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 31

                      try {
            JSON.parseObject(",]", new TypeReference<Map<Object, Object>>() {
            });
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    

            

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

                      Assert.assertNotNull(error);
    }
    
    public void test_error_3() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[{},{\"$ref\":0}]",
                             new TypeReference<List<Map<Object, Object>>>() {
                             });

            

Reported by PMD.

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

Line: 43

                          JSON.parseObject("[{},{\"$ref\":0}]",
                             new TypeReference<List<Map<Object, Object>>>() {
                             });
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    

            

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.assertNotNull(error);
    }
    
    public void test_error_4() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[{},{\"$ref\":\"$[0]\",}]",
                             new TypeReference<List<Map<Object, Object>>>() {
                             });

            

Reported by PMD.

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

Line: 55

                          JSON.parseObject("[{},{\"$ref\":\"$[0]\",}]",
                             new TypeReference<List<Map<Object, Object>>>() {
                             });
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }


            

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

                      Assert.assertNotNull(error);
    }

    public void test_0() throws Exception {
        List<Map<Object, Object>> list = JSON.parseObject("[{},{\"$ref\":\"$[0]\"}]",
                                                          new TypeReference<List<Map<Object, Object>>>() {
                                                          });
        Assert.assertSame(list.get(0), list.get(1));
    }

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 68

                      Assert.assertSame(list.get(0), list.get(1));
    }

    public void test_1() throws Exception {
        Map<Object, Map<Object, Object>> map = JSON.parseObject("{\"1\":{},\"2\":{\"$ref\":\"$\"}}",
                                                                new TypeReference<Map<Object, Map<Object, Object>>>() {
                                                                });
        Assert.assertSame(map, map.get("2"));
    }

            

Reported by PMD.

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

Line: 47

                      }

        public void setSecond(Child second) {
            System.out.println("setSecond");
            this.second = second;
        }

        public Child getFirst() {
            return first;

            

Reported by PMD.

System.out.println is used
Design

Line: 56

                      }

        public void setFirst(Child first) {
            System.out.println("setFirst");
            this.first = first;
        }

        public List<Child> getChildren() {
            return children;

            

Reported by PMD.

System.out.println is used
Design

Line: 65

                      }

        public void setChildren(List<Child> children) {
            System.out.println("setChildren");
            this.children = children;
        }

        public int getId() {
            return id;

            

Reported by PMD.

System.out.println is used
Design

Line: 102

                      }

        public void setRoot(Root root) {
            System.out.println("setRoot");
            this.root = root;
        }

        public int getId() {
            return id;

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 13

              
public class Bug_for_wangran2 extends TestCase {

    public void test_for_wangran() throws Exception {
        String text = "{" + //
                      "\"first\":{\"id\":1001}," + //
                      "\"second\":{\"id\":1002,\"root\":{\"$ref\":\"$\"}}," + //
                      "\"id\":23," + //
                      "\"name\":\"xxx\"," + //

            

Reported by PMD.

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

Line: 22

                                    "\"children\":[{\"root\":{\"$ref\":\"$\"}},{\"$ref\":\"$.second\"}]" + //
                      "}";
        Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }


            

Reported by PMD.

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

Line: 23

                                    "}";
        Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }

    public static class Root {

            

Reported by PMD.

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

Line: 24

                      Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }

    public static class Root {


            

Reported by PMD.

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

Line: 24

                      Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }

    public static class Root {


            

Reported by PMD.

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

Line: 24

                      Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }

    public static class Root {


            

Reported by PMD.

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

    public void test_special() throws Exception {
        JSONReader read = new JSONReader(new StringReader("{\"value\":1}"));
        Model model = read.readObject(Model.class);
        Assert.assertEquals(Type.B, model.value);
        read.close();
    }

            

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

                      read.close();
    }
    
    public void test_1() throws Exception {
        JSONReader read = new JSONReader(new StringReader("{\"value\":\"A\",\"value1\":\"B\"}"));
        Model model = read.readObject(Model.class);
        Assert.assertEquals(Type.A, model.value);
        Assert.assertEquals(Type.B, model.value1);
        read.close();

            

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

                      read.close();
    }
    
    public void test_map() throws Exception {
        JSONReader read = new JSONReader(new StringReader("{\"model\":{\"value\":\"A\",\"value1\":\"B\"}}"));
        Map<String, Model> map = read.readObject(new TypeReference<Map<String, Model>>(){});
        Model model = (Model) map.get("model");
        Assert.assertEquals(Type.A, model.value);
        Assert.assertEquals(Type.B, model.value1);

            

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

                      read.close();
    }

    public void test_error() throws Exception {
        JSONReader read = new JSONReader(new StringReader("{\"value\":\"a\\b\"}"));
        Model model = read.readObject(Model.class);
        assertNull(model.value);
    }
    

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 43

                  public void test_error() throws Exception {
        JSONReader read = new JSONReader(new StringReader("{\"value\":\"a\\b\"}"));
        Model model = read.readObject(Model.class);
        assertNull(model.value);
    }
    
    public void test_error_1() throws Exception {
        Exception error = null;
        try {

            

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

                      assertNull(model.value);
    }
    
    public void test_error_1() throws Exception {
        Exception error = null;
        try {
            JSONReader read = new JSONReader(new StringReader("{\"value\":\"A\",\"value1\":\"B\"["));
            Model model = read.readObject(Model.class);
            read.readObject(Model.class);

            

Reported by PMD.

Avoid unused local variables such as 'model'.
Design

Line: 50

                      Exception error = null;
        try {
            JSONReader read = new JSONReader(new StringReader("{\"value\":\"A\",\"value1\":\"B\"["));
            Model model = read.readObject(Model.class);
            read.readObject(Model.class);
        } catch (JSONException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);

            

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

                      Assert.assertNotNull(error);
    }
    
    public void test_error_2() throws Exception {
        Exception error = null;
        try {
            JSONReader read = new JSONReader(new StringReader("{\"model\":{\"value\":\"A\",\"value1\":\"B\"}["));
            Map<String, Model> map = read.readObject(new TypeReference<Map<String, Model>>(){});
            read.readObject(Model.class);

            

Reported by PMD.

Avoid unused local variables such as 'map'.
Design

Line: 62

                      Exception error = null;
        try {
            JSONReader read = new JSONReader(new StringReader("{\"model\":{\"value\":\"A\",\"value1\":\"B\"}["));
            Map<String, Model> map = read.readObject(new TypeReference<Map<String, Model>>(){});
            read.readObject(Model.class);
        } catch (JSONException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);

            

Reported by PMD.

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

Line: 72

              
    private static class Model {

        public Type value;
        public Type value1;

    }

    public static enum Type {

            

Reported by PMD.

src/test/java/com/alibaba/json/demo/hibernate/LazyLoadingTest.java
15 issues
System.out.println is used
Design

Line: 41

                          Customer customer = em.find(Customer.class, 103);
            // assertFalse(Hibernate.isInitialized(customer.getPayments()));
            String json = JSON.toJSONString(customer);
        System.out.println(json);
            // should not force loading...
            Set<Payment> payments = customer.getPayments();
            /*
            System.out.println("--- JSON ---");
            System.out.println(json);

            

Reported by PMD.

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

Line: 19

              import org.junit.Test;

public class LazyLoadingTest extends TestCase {
    EntityManagerFactory emf;

    protected void setUp() throws Exception {
        emf = Persistence.createEntityManagerFactory("persistenceUnit");
    }


            

Reported by PMD.

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

Line: 21

              public class LazyLoadingTest extends TestCase {
    EntityManagerFactory emf;

    protected void setUp() throws Exception {
        emf = Persistence.createEntityManagerFactory("persistenceUnit");
    }

    protected void tearDown() throws Exception {
        if (emf != null) {

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 25

                      emf = Persistence.createEntityManagerFactory("persistenceUnit");
    }

    protected void tearDown() throws Exception {
        if (emf != null) {
            emf.close();
        }
    }


            

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 testGetCustomerJson() throws Exception {

            EntityManager em = emf.createEntityManager();
            
            // false -> no forcing of lazy loading
            //ObjectMapper mapper = mapperWithModule(false);

            

Reported by PMD.

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

Line: 38

                          // false -> no forcing of lazy loading
            //ObjectMapper mapper = mapperWithModule(false);
            
            Customer customer = em.find(Customer.class, 103);
            // assertFalse(Hibernate.isInitialized(customer.getPayments()));
            String json = JSON.toJSONString(customer);
        System.out.println(json);
            // should not force loading...
            Set<Payment> payments = customer.getPayments();

            

Reported by PMD.

Avoid unused local variables such as 'payments'.
Design

Line: 43

                          String json = JSON.toJSONString(customer);
        System.out.println(json);
            // should not force loading...
            Set<Payment> payments = customer.getPayments();
            /*
            System.out.println("--- JSON ---");
            System.out.println(json);
            System.out.println("--- /JSON ---");
            */

            

Reported by PMD.

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

Line: 43

                          String json = JSON.toJSONString(customer);
        System.out.println(json);
            // should not force loading...
            Set<Payment> payments = customer.getPayments();
            /*
            System.out.println("--- JSON ---");
            System.out.println(json);
            System.out.println("--- /JSON ---");
            */

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 52

              
            //assertFalse(Hibernate.isInitialized(payments));
            // TODO: verify
            assertNotNull(json);
            
//            Map<?,?> stuff = mapper.readValue(json, Map.class);
//
//            // "payments" is marked as lazily loaded AND "Include.NON_EMPTY"; should not be serialized
//            if (stuff.containsKey("payments")) {

            

Reported by PMD.

Avoid unused imports such as 'com.fasterxml.jackson.core.JsonProcessingException'
Design

Line: 10

              import javax.persistence.Persistence;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.alibaba.json.demo.hibernate.data.*;

import junit.framework.TestCase;
import org.hibernate.Hibernate;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/JSONFieldTest_unwrapped_4.java
15 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 13

              
public class JSONFieldTest_unwrapped_4 extends TestCase {

    public void test_jsonField() throws Exception {
        Health vo = new Health();
        vo.id = 123;
        vo.border = 234;
        vo.details.put("latitude", 37);
        vo.details.put("longitude", 127);

            

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

    public void test_jsonField() throws Exception {
        Health vo = new Health();
        vo.id = 123;
        vo.border = 234;
        vo.details.put("latitude", 37);
        vo.details.put("longitude", 127);

            

Reported by PMD.

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

Line: 17

                      Health vo = new Health();
        vo.id = 123;
        vo.border = 234;
        vo.details.put("latitude", 37);
        vo.details.put("longitude", 127);

        String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"border\":234,\"latitude\":37,\"longitude\":127,\"id\":123}", text);


            

Reported by PMD.

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

Line: 18

                      vo.id = 123;
        vo.border = 234;
        vo.details.put("latitude", 37);
        vo.details.put("longitude", 127);

        String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"border\":234,\"latitude\":37,\"longitude\":127,\"id\":123}", text);

        Health vo2 = JSON.parseObject(text, Health.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

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

        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

              
        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }

    public void test_null() throws Exception {

            

Reported by PMD.

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

Line: 25

              
        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }

    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.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }

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

            

Reported by PMD.

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

Line: 26

                      Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }

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

              
    }

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


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/ConcurrentHashMapTest6.java
15 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: 19

              
public class ConcurrentHashMapTest6 extends TestCase {

    public void test_concurrentHashmap() throws Exception {
        OffsetSerializeWrapper wrapper = new OffsetSerializeWrapper();
        wrapper.offsetTable.put(new MessageQueue(), new WeakReference<A>(new A(true)));
        String text = JSON.toJSONString(wrapper);
        Assert.assertEquals("{\"offsetTable\":{{\"items\":[]}:{\"value\":true}}}", text);


            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals("{\"offsetTable\":{{\"items\":[]}:{\"value\":true}}}", text);

        OffsetSerializeWrapper wrapper2 = JSON.parseObject(text, OffsetSerializeWrapper.class);
        Assert.assertEquals(1, wrapper2.getOffsetTable().size());

        Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());

            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals("{\"offsetTable\":{{\"items\":[]}:{\"value\":true}}}", text);

        OffsetSerializeWrapper wrapper2 = JSON.parseObject(text, OffsetSerializeWrapper.class);
        Assert.assertEquals(1, wrapper2.getOffsetTable().size());

        Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());

            

Reported by PMD.

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

Line: 28

                      OffsetSerializeWrapper wrapper2 = JSON.parseObject(text, OffsetSerializeWrapper.class);
        Assert.assertEquals(1, wrapper2.getOffsetTable().size());

        Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());
    }


            

Reported by PMD.

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

Line: 28

                      OffsetSerializeWrapper wrapper2 = JSON.parseObject(text, OffsetSerializeWrapper.class);
        Assert.assertEquals(1, wrapper2.getOffsetTable().size());

        Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());
    }


            

Reported by PMD.

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

Line: 28

                      OffsetSerializeWrapper wrapper2 = JSON.parseObject(text, OffsetSerializeWrapper.class);
        Assert.assertEquals(1, wrapper2.getOffsetTable().size());

        Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());
    }


            

Reported by PMD.

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

Line: 30

              
        Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());
    }

    public static class OffsetSerializeWrapper {


            

Reported by PMD.

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

Line: 30

              
        Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());
    }

    public static class OffsetSerializeWrapper {


            

Reported by PMD.

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

Line: 30

              
        Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());
    }

    public static class OffsetSerializeWrapper {


            

Reported by PMD.

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

Line: 31

                      Iterator<Map.Entry<MessageQueue, WeakReference<A>>> iter = wrapper2.getOffsetTable().entrySet().iterator();
        Map.Entry<MessageQueue, WeakReference<A>> entry = iter.next();
        Assert.assertEquals(0, entry.getKey().getItems().size());
        Assert.assertEquals(true, entry.getValue().get().isValue());
    }

    public static class OffsetSerializeWrapper {

        private ConcurrentHashMap<MessageQueue, WeakReference<A>> offsetTable = new ConcurrentHashMap<MessageQueue, WeakReference<A>>();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_string.java
15 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 14

              
public class WriteAsArray_string extends TestCase {

    public void test_0() throws Exception {
        Model model = new Model();

        String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
        Assert.assertEquals("[null]", 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: 24

                      Assert.assertNull(model2.name);
    }

    public void test_1() throws Exception {
        Model model = new Model();
        model.name = "abc";
        String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
        Assert.assertEquals("[\"abc\"]", 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: 34

                      Assert.assertEquals(model.name, model2.name);
    }
    
    public void test_error_0() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[n", Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {
            error = ex;

            

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

                      Assert.assertNotNull(error);
    }

    public void test_error_1() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[nu", Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {
            error = ex;

            

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

                      Assert.assertNotNull(error);
    }

    public void test_error_2() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[nul", Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {
            error = ex;

            

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

                      Assert.assertNotNull(error);
    }

    public void test_error_3() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[null", Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {
            error = ex;

            

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

                      Assert.assertNotNull(error);
    }

    public void test_error_4() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[\"ab", Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {
            error = ex;

            

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

                      Assert.assertNotNull(error);
    }

    public void test_error_5() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[\"ab\"", Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {
            error = ex;

            

Reported by PMD.

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

Line: 96

              
    public static class Model {

        public String name;

    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '35'-'39').
Error

Line: 35

                  }
    
    public void test_error_0() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("[n", Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {
            error = ex;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/AbstractSerializeTest.java
15 issues
JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 12

              import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

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

        ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
        ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }

            

Reported by PMD.

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

Line: 13

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

        ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
        ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }


            

Reported by PMD.

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

Line: 15

                  protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.AbstractSerializeTest");

        ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
        ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }

    protected void tearDown() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(A.class, null);

            

Reported by PMD.

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

Line: 16

                      ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.AbstractSerializeTest");

        ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
        ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }

    protected void tearDown() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(A.class, null);
    }

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 19

                      ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }

    protected void tearDown() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(A.class, null);
    }

    public void test_mapping_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\"}";

            

Reported by PMD.

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

Line: 20

                  }

    protected void tearDown() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(A.class, null);
    }

    public void test_mapping_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\"}";


            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 23

                      ParserConfig.getGlobalInstance().putDeserializer(A.class, null);
    }

    public void test_mapping_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\"}";

        B b = (B) JSON.parse(text);
        Assert.assertNotNull(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: 30

                      Assert.assertNotNull(b);
    }

    public void test_mapping_1() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\",\"id\":123}";

        B b = (B) JSON.parse(text);
        Assert.assertNotNull(b);
        Assert.assertEquals(123, b.getId());

            

Reported by PMD.

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

Line: 35

              
        B b = (B) JSON.parse(text);
        Assert.assertNotNull(b);
        Assert.assertEquals(123, b.getId());
    }

    public void test_mapping_2() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\",\"id\":234,\"name\":\"abc\"}";


            

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(123, b.getId());
    }

    public void test_mapping_2() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\",\"id\":234,\"name\":\"abc\"}";

        B b = (B) JSON.parse(text);
        Assert.assertNotNull(b);
        Assert.assertEquals(234, b.getId());

            

Reported by PMD.

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

               * Created by wenshao on 16/02/2017.
 */
public class Issue_for_huangfeng extends TestCase {
    public void test_for_huangfeng() throws Exception {
        String json = "{\"success\":\"Y\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

                      String json = "{\"success\":\"Y\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_t() throws Exception {
        String json = "{\"success\":\"T\"}";


            

Reported by PMD.

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

Line: 14

                      String json = "{\"success\":\"Y\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_t() throws Exception {
        String json = "{\"success\":\"T\"}";


            

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

                      assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_t() throws Exception {
        String json = "{\"success\":\"T\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

            

Reported by PMD.

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

Line: 21

                      String json = "{\"success\":\"T\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_is_t() throws Exception {
        String json = "{\"isSuccess\":\"T\"}";


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      String json = "{\"success\":\"T\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_is_t() throws Exception {
        String json = "{\"isSuccess\":\"T\"}";


            

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

                      assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_is_t() throws Exception {
        String json = "{\"isSuccess\":\"T\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

            

Reported by PMD.

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

Line: 28

                      String json = "{\"isSuccess\":\"T\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_false() throws Exception {
        String json = "{\"success\":\"N\"}";


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 28

                      String json = "{\"isSuccess\":\"T\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_false() throws Exception {
        String json = "{\"success\":\"N\"}";


            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 31

                      assertTrue(model.isSuccess());
    }

    public void test_for_huangfeng_false() throws Exception {
        String json = "{\"success\":\"N\"}";

        Model model = JSON.parseObject(json, Model.class);
        assertFalse(model.isSuccess());
    }

            

Reported by PMD.