The following issues were found

src/test/java/com/alibaba/json/bvt/issue_1600/Issue1683.java
9 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 9

              import junit.framework.TestCase;

public class Issue1683 extends TestCase {
    public void test_for_issue() throws Exception {
        String line = "[2, \"浪漫奇侠\", \"雨天不打伞\", 4536]";
        BookDO book = JSON.parseObject(line, BookDO.class, Feature.SupportArrayToBean);
        assertEquals(2L, book.bookId.longValue());
        assertEquals("浪漫奇侠", book.bookName);
        assertEquals("雨天不打伞", book.authorName);

            

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

              import junit.framework.TestCase;

public class Issue1683 extends TestCase {
    public void test_for_issue() throws Exception {
        String line = "[2, \"浪漫奇侠\", \"雨天不打伞\", 4536]";
        BookDO book = JSON.parseObject(line, BookDO.class, Feature.SupportArrayToBean);
        assertEquals(2L, book.bookId.longValue());
        assertEquals("浪漫奇侠", book.bookName);
        assertEquals("雨天不打伞", book.authorName);

            

Reported by PMD.

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

Line: 12

                  public void test_for_issue() throws Exception {
        String line = "[2, \"浪漫奇侠\", \"雨天不打伞\", 4536]";
        BookDO book = JSON.parseObject(line, BookDO.class, Feature.SupportArrayToBean);
        assertEquals(2L, book.bookId.longValue());
        assertEquals("浪漫奇侠", book.bookName);
        assertEquals("雨天不打伞", book.authorName);
        assertEquals(4536, book.wordCount.intValue());
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

                  public void test_for_issue() throws Exception {
        String line = "[2, \"浪漫奇侠\", \"雨天不打伞\", 4536]";
        BookDO book = JSON.parseObject(line, BookDO.class, Feature.SupportArrayToBean);
        assertEquals(2L, book.bookId.longValue());
        assertEquals("浪漫奇侠", book.bookName);
        assertEquals("雨天不打伞", book.authorName);
        assertEquals(4536, book.wordCount.intValue());
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

                      String line = "[2, \"浪漫奇侠\", \"雨天不打伞\", 4536]";
        BookDO book = JSON.parseObject(line, BookDO.class, Feature.SupportArrayToBean);
        assertEquals(2L, book.bookId.longValue());
        assertEquals("浪漫奇侠", book.bookName);
        assertEquals("雨天不打伞", book.authorName);
        assertEquals(4536, book.wordCount.intValue());
    }

    @JSONType(orders = {"bookId", "bookName", "authorName", "wordCount"})

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

                      BookDO book = JSON.parseObject(line, BookDO.class, Feature.SupportArrayToBean);
        assertEquals(2L, book.bookId.longValue());
        assertEquals("浪漫奇侠", book.bookName);
        assertEquals("雨天不打伞", book.authorName);
        assertEquals(4536, book.wordCount.intValue());
    }

    @JSONType(orders = {"bookId", "bookName", "authorName", "wordCount"})
    public static class BookDO {

            

Reported by PMD.

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

Line: 15

                      assertEquals(2L, book.bookId.longValue());
        assertEquals("浪漫奇侠", book.bookName);
        assertEquals("雨天不打伞", book.authorName);
        assertEquals(4536, book.wordCount.intValue());
    }

    @JSONType(orders = {"bookId", "bookName", "authorName", "wordCount"})
    public static class BookDO {


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                      assertEquals(2L, book.bookId.longValue());
        assertEquals("浪漫奇侠", book.bookName);
        assertEquals("雨天不打伞", book.authorName);
        assertEquals(4536, book.wordCount.intValue());
    }

    @JSONType(orders = {"bookId", "bookName", "authorName", "wordCount"})
    public static class BookDO {


            

Reported by PMD.

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

Line: 19

                  }

    @JSONType(orders = {"bookId", "bookName", "authorName", "wordCount"})
    public static class BookDO {

        private Long bookId;

        private String bookName;


            

Reported by PMD.

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

Line: 13

              
public class JSONFieldTest6 extends TestCase {

    public void test_for_issue1()
    {
        NonStringMap nonStringMap = new NonStringMap();
        Map<Integer, Integer> map1 = new HashMap();
        map1.put( 111,666 );
        nonStringMap.setMap1( map1 );

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      map1.put( 111,666 );
        nonStringMap.setMap1( map1 );
        String json = JSON.toJSONString( nonStringMap );
        assertEquals( "{\"map1\":{\"111\":666}}", json );
    }

    public void test_for_issue2()
    {
        NonStringMap nonStringMap = new NonStringMap();

            

Reported by PMD.

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

Line: 23

                      assertEquals( "{\"map1\":{\"111\":666}}", json );
    }

    public void test_for_issue2()
    {
        NonStringMap nonStringMap = new NonStringMap();
        Map<Integer, Integer> map2 = new HashMap();
        map2.put( 222,888 );
        nonStringMap.setMap2( map2 );

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 30

                      map2.put( 222,888 );
        nonStringMap.setMap2( map2 );
        String json = JSON.toJSONString( nonStringMap );
        assertEquals( "{\"map2\":{222:\"888\"}}", json );
    }

    public void test_for_issue3()
    {
        NonStringMap nonStringMap = new NonStringMap();

            

Reported by PMD.

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

Line: 33

                      assertEquals( "{\"map2\":{222:\"888\"}}", json );
    }

    public void test_for_issue3()
    {
        NonStringMap nonStringMap = new NonStringMap();
        Map<Integer, Integer> map3 = new HashMap();
        map3.put( 333,999 );
        nonStringMap.setMap3( map3 );

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

                      map3.put( 333,999 );
        nonStringMap.setMap3( map3 );
        String json = JSON.toJSONString( nonStringMap );
        assertEquals( "{\"map3\":{\"333\":\"999\"}}", json );
    }

    public void test_for_issue4()
    {
        NonStringMap nonStringMap = new NonStringMap();

            

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

                      assertEquals( "{\"map3\":{\"333\":\"999\"}}", json );
    }

    public void test_for_issue4()
    {
        NonStringMap nonStringMap = new NonStringMap();
        Bean person = new Bean();
        person.setAge( 23 );
        nonStringMap.setPerson( person );

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 50

                      person.setAge( 23 );
        nonStringMap.setPerson( person );
        String json = JSON.toJSONString( nonStringMap );
        assertEquals( "{\"person\":{\"age\":\"23\"}}", json );
    }

    class NonStringMap
    {
        @JSONField( serialzeFeatures = {SerializerFeature.WriteNonStringKeyAsString} )

            

Reported by PMD.

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

Line: 53

                      assertEquals( "{\"person\":{\"age\":\"23\"}}", json );
    }

    class NonStringMap
    {
        @JSONField( serialzeFeatures = {SerializerFeature.WriteNonStringKeyAsString} )
        private Map map1;

        public Map getMap1()

            

Reported by PMD.

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

Line: 17

              
public class IntFieldTest2 extends TestCase {

    public void test_model() throws Exception {
        Model model = new Model();
        model.id = -1001;
        model.id2 = -1002;

        String text = JSON.toJSONString(model);

            

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.assertEquals("{\"id\":-1001,\"id2\":-1002}", text);
    }

    public void test_model_max() throws Exception {
        Model model = new Model();
        model.id = Integer.MIN_VALUE;
        model.id2 = Integer.MAX_VALUE;

        String text = JSON.toJSONString(model);

            

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

                      }
    }

    public void test_model_map() throws Exception {
        String text = "{\"model\":{\"id\":-1001,\"id2\":-1002}}";

        JSONReader reader = new JSONReader(new StringReader(text));
        Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {
        });

            

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

                      reader.close();
    }

    public void test_model_map_error() throws Exception {
        String text = "{\"model\":{\"id\":-1001,\"id2\":-1002[";

        Exception error = null;
        JSONReader reader = new JSONReader(new StringReader(text));
        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: 68

                      Assert.assertNotNull(error);
    }
    
    public void test_model_map_error_2() throws Exception {
        String text = "{\"model\":{\"id\":-1001,\"id2\":-1002}[";

        Exception error = null;
        JSONReader reader = new JSONReader(new StringReader(text));
        try {

            

Reported by PMD.

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

Line: 84

              
    public static class Model {

        public int id;
        public int id2;
    }
}

            

Reported by PMD.

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

Line: 85

                  public static class Model {

        public int id;
        public int id2;
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '57'-'63').
Error

Line: 57

                  public void test_model_map_error() throws Exception {
        String text = "{\"model\":{\"id\":-1001,\"id2\":-1002[";

        Exception error = null;
        JSONReader reader = new JSONReader(new StringReader(text));
        try {
            reader.readObject(new TypeReference<Map<String, Model>>() {
            });
        } catch (JSONException ex) {

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '71'-'77').
Error

Line: 71

                  public void test_model_map_error_2() throws Exception {
        String text = "{\"model\":{\"id\":-1001,\"id2\":-1002}[";

        Exception error = null;
        JSONReader reader = new JSONReader(new StringReader(text));
        try {
            reader.readObject(new TypeReference<Map<String, Model>>() {
            });
        } catch (JSONException ex) {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1600/Issue_for_gaorui.java
9 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: 8

              import junit.framework.TestCase;

public class Issue_for_gaorui extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"@type\":\"java.util.HashMap\",\"COUPON\":[{\"@type\":\"com.alibaba.json.bvt.issue_1600.Issue_for_gaorui.PromotionTermDetail\",\"activityId\":\"1584034\",\"choose\":true,\"couponId\":1251068987,\"couponType\":\"limitp\",\"match\":true,\"realPrice\":{\"amount\":0.6,\"currency\":\"USD\"}}],\"grayTrade\":\"true\"}";

        JSON.parseObject(json, Object.class, Feature.SupportAutoType);
    }


            

Reported by PMD.

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

Line: 8

              import junit.framework.TestCase;

public class Issue_for_gaorui extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"@type\":\"java.util.HashMap\",\"COUPON\":[{\"@type\":\"com.alibaba.json.bvt.issue_1600.Issue_for_gaorui.PromotionTermDetail\",\"activityId\":\"1584034\",\"choose\":true,\"couponId\":1251068987,\"couponType\":\"limitp\",\"match\":true,\"realPrice\":{\"amount\":0.6,\"currency\":\"USD\"}}],\"grayTrade\":\"true\"}";

        JSON.parseObject(json, Object.class, Feature.SupportAutoType);
    }


            

Reported by PMD.

The class 'PromotionTermDetail' is suspected to be a Data Class (WOC=22.222%, NOPA=0, NOAM=14, WMC=18)
Design

Line: 14

                      JSON.parseObject(json, Object.class, Feature.SupportAutoType);
    }

    public static class PromotionTermDetail {
        /**
         * 卡券Id
         */
        private Long couponId;
        /**

            

Reported by PMD.

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

Line: 40

                      /**
         * 是否能够获取到该优惠
         */
        private boolean isMatch = false;
        /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**

            

Reported by PMD.

Avoid using redundant field initializer for 'isMatch'
Performance

Line: 40

                      /**
         * 是否能够获取到该优惠
         */
        private boolean isMatch = false;
        /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**

            

Reported by PMD.

Field isMatch has the same name as a method
Error

Line: 40

                      /**
         * 是否能够获取到该优惠
         */
        private boolean isMatch = false;
        /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**

            

Reported by PMD.

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

Line: 44

                      /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**
         * 未获取到优惠的原因
         */
        private String reasonForLose;
        /**

            

Reported by PMD.

Avoid using redundant field initializer for 'isChoose'
Performance

Line: 44

                      /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**
         * 未获取到优惠的原因
         */
        private String reasonForLose;
        /**

            

Reported by PMD.

Field isChoose has the same name as a method
Error

Line: 44

                      /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**
         * 未获取到优惠的原因
         */
        private String reasonForLose;
        /**

            

Reported by PMD.

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

Line: 10

              
public class JSONFieldTest_unwrapped_0 extends TestCase {

    public void test_jsonField() throws Exception {
        VO vo = new VO();
        vo.id = 123;
        vo.localtion = new Localtion(127, 37);

        String text = JSON.toJSONString(vo);

            

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

              
public class JSONFieldTest_unwrapped_0 extends TestCase {

    public void test_jsonField() throws Exception {
        VO vo = new VO();
        vo.id = 123;
        vo.localtion = new Localtion(127, 37);

        String text = JSON.toJSONString(vo);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

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

        VO vo2 = JSON.parseObject(text, VO.class);
        assertNotNull(vo2.localtion);
        assertEquals(vo.localtion.latitude, vo2.localtion.latitude);
        assertEquals(vo.localtion.longitude, vo2.localtion.longitude);
    }

    public static class VO {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        VO vo2 = JSON.parseObject(text, VO.class);
        assertNotNull(vo2.localtion);
        assertEquals(vo.localtion.latitude, vo2.localtion.latitude);
        assertEquals(vo.localtion.longitude, vo2.localtion.longitude);
    }

    public static class VO {
        public int id;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      VO vo2 = JSON.parseObject(text, VO.class);
        assertNotNull(vo2.localtion);
        assertEquals(vo.localtion.latitude, vo2.localtion.latitude);
        assertEquals(vo.localtion.longitude, vo2.localtion.longitude);
    }

    public static class VO {
        public int id;


            

Reported by PMD.

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

Line: 25

                  }

    public static class VO {
        public int id;

        @JSONField(unwrapped = true)
        public Localtion localtion;
    }


            

Reported by PMD.

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

Line: 28

                      public int id;

        @JSONField(unwrapped = true)
        public Localtion localtion;
    }

    public static class Localtion {
        public int longitude;
        public int latitude;

            

Reported by PMD.

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

Line: 32

                  }

    public static class Localtion {
        public int longitude;
        public int latitude;

        public Localtion() {

        }

            

Reported by PMD.

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

Line: 33

              
    public static class Localtion {
        public int longitude;
        public int latitude;

        public Localtion() {

        }


            

Reported by PMD.

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

Line: 18

                      to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

            

Reported by PMD.

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

Line: 13

              

public class Issue87_hashset extends TestCase {
    public void test_for_issue() throws Exception {
        TestObject to = new TestObject();
        to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(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: 13

              

public class Issue87_hashset extends TestCase {
    public void test_for_issue() throws Exception {
        TestObject to = new TestObject();
        to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(text);

            

Reported by PMD.

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

Line: 20

                      String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

        private HashSet<String> set = new HashSet<String>(0);

            

Reported by PMD.

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

Line: 25

                  
    public static class TestObject {

        private HashSet<String> set = new HashSet<String>(0);

        public HashSet<String> getSet() {
            return set;
        }


            

Reported by PMD.

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

Line: 27

              
        private HashSet<String> set = new HashSet<String>(0);

        public HashSet<String> getSet() {
            return set;
        }

        public void setSet(HashSet<String> set) {
            this.set = set;

            

Reported by PMD.

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

Line: 31

                          return set;
        }

        public void setSet(HashSet<String> set) {
            this.set = set;
        }

        public void add(String str) {
            set.add(str);

            

Reported by PMD.

Avoid unused imports such as 'java.util.Set'
Design

Line: 4

              package com.alibaba.json.bvt.bug;

import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'to' (lines '20'-'21').
Error

Line: 20

                      String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

        private HashSet<String> set = new HashSet<String>(0);

            

Reported by PMD.

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

Line: 13

              
public class WriteAsArray_Object_2_public extends TestCase {

    public void test_0() throws Exception {
        A a = new A();
        a.setId(123);
        a.setName("wenshao");

        VO vo = new VO();

            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals("[1001,[123,\"wenshao\"]]", text);

        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getValue().getId(), vo2.getValue().getId());
        Assert.assertEquals(vo.getValue().getName(), vo2.getValue().getName());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals("[1001,[123,\"wenshao\"]]", text);

        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getValue().getId(), vo2.getValue().getId());
        Assert.assertEquals(vo.getValue().getName(), vo2.getValue().getName());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals("[1001,[123,\"wenshao\"]]", text);

        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getValue().getId(), vo2.getValue().getId());
        Assert.assertEquals(vo.getValue().getName(), vo2.getValue().getName());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 27

              
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getValue().getId(), vo2.getValue().getId());
        Assert.assertEquals(vo.getValue().getName(), vo2.getValue().getName());
    }

    public static class VO {

        private int id;

            

Reported by PMD.

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

Line: 27

              
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getValue().getId(), vo2.getValue().getId());
        Assert.assertEquals(vo.getValue().getName(), vo2.getValue().getName());
    }

    public static class VO {

        private int id;

            

Reported by PMD.

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

Line: 27

              
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getValue().getId(), vo2.getValue().getId());
        Assert.assertEquals(vo.getValue().getName(), vo2.getValue().getName());
    }

    public static class VO {

        private int id;

            

Reported by PMD.

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

Line: 30

                      Assert.assertEquals(vo.getValue().getName(), vo2.getValue().getName());
    }

    public static class VO {

        private int id;
        private A   value;

        public int getId() {

            

Reported by PMD.

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

Line: 53

              
    }

    public static class A {

        private int    id;
        private String name;

        public int getId() {

            

Reported by PMD.

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

Line: 22

                      SerializeConfig.getGlobalInstance().setAsmEnable(false);
        String json = JSON.toJSONString(user, SerializerFeature.WriteClassName);
        // 输出{"@type":"xx.TUser","id":0L}
        System.out.println(json);
        // 下面反系列化错误:com.alibaba.fastjson.JSONException: unclosed.str
        // 原因:id带L后缀
        user = (TUser) JSON.parse(json);
    }


            

Reported by PMD.

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

Line: 11

              import junit.framework.TestCase;

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

    public void test_for_issue() throws Exception {
        TUser user = new TUser();

            

Reported by PMD.

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

Line: 12

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

    public void test_for_issue() throws Exception {
        TUser user = new TUser();
        user.id = 1001;

            

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

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

    public void test_for_issue() throws Exception {
        TUser user = new TUser();
        user.id = 1001;
        // 禁用asm(在android下使用),启用asm则没问题。
        SerializeConfig.getGlobalInstance().setAsmEnable(false);
        String json = JSON.toJSONString(user, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 15

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

    public void test_for_issue() throws Exception {
        TUser user = new TUser();
        user.id = 1001;
        // 禁用asm(在android下使用),启用asm则没问题。
        SerializeConfig.getGlobalInstance().setAsmEnable(false);
        String json = JSON.toJSONString(user, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 19

                      TUser user = new TUser();
        user.id = 1001;
        // 禁用asm(在android下使用),启用asm则没问题。
        SerializeConfig.getGlobalInstance().setAsmEnable(false);
        String json = JSON.toJSONString(user, SerializerFeature.WriteClassName);
        // 输出{"@type":"xx.TUser","id":0L}
        System.out.println(json);
        // 下面反系列化错误:com.alibaba.fastjson.JSONException: unclosed.str
        // 原因:id带L后缀

            

Reported by PMD.

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

Line: 25

                      System.out.println(json);
        // 下面反系列化错误:com.alibaba.fastjson.JSONException: unclosed.str
        // 原因:id带L后缀
        user = (TUser) JSON.parse(json);
    }

    public static class TUser {

        public long id;

            

Reported by PMD.

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

Line: 30

              
    public static class TUser {

        public long id;
    }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'user' (lines '25'-'26').
Error

Line: 25

                      System.out.println(json);
        // 下面反系列化错误:com.alibaba.fastjson.JSONException: unclosed.str
        // 原因:id带L后缀
        user = (TUser) JSON.parse(json);
    }

    public static class TUser {

        public long id;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/array/FieldFloatArray2Test_private.java
9 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 11/01/2017.
 */
public class FieldFloatArray2Test_private extends TestCase {
    public void test_intArray() throws Exception {
        Model model = JSON.parseObject("{\"value\":[[1,2.1,-0.3]]}", Model.class);
        assertNotNull(model.value);
        assertEquals(1, model.value.length);
        assertEquals(3, model.value[0].length);
        assertEquals(1f, model.value[0][0]);

            

Reported by PMD.

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

Line: 10

               * Created by wenshao on 11/01/2017.
 */
public class FieldFloatArray2Test_private extends TestCase {
    public void test_intArray() throws Exception {
        Model model = JSON.parseObject("{\"value\":[[1,2.1,-0.3]]}", Model.class);
        assertNotNull(model.value);
        assertEquals(1, model.value.length);
        assertEquals(3, model.value[0].length);
        assertEquals(1f, model.value[0][0]);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

              public class FieldFloatArray2Test_private extends TestCase {
    public void test_intArray() throws Exception {
        Model model = JSON.parseObject("{\"value\":[[1,2.1,-0.3]]}", Model.class);
        assertNotNull(model.value);
        assertEquals(1, model.value.length);
        assertEquals(3, model.value[0].length);
        assertEquals(1f, model.value[0][0]);
        assertEquals(2.1f, model.value[0][1]);
        assertEquals(-0.3f, model.value[0][2]);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

                  public void test_intArray() throws Exception {
        Model model = JSON.parseObject("{\"value\":[[1,2.1,-0.3]]}", Model.class);
        assertNotNull(model.value);
        assertEquals(1, model.value.length);
        assertEquals(3, model.value[0].length);
        assertEquals(1f, model.value[0][0]);
        assertEquals(2.1f, model.value[0][1]);
        assertEquals(-0.3f, model.value[0][2]);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

                      Model model = JSON.parseObject("{\"value\":[[1,2.1,-0.3]]}", Model.class);
        assertNotNull(model.value);
        assertEquals(1, model.value.length);
        assertEquals(3, model.value[0].length);
        assertEquals(1f, model.value[0][0]);
        assertEquals(2.1f, model.value[0][1]);
        assertEquals(-0.3f, model.value[0][2]);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                      assertNotNull(model.value);
        assertEquals(1, model.value.length);
        assertEquals(3, model.value[0].length);
        assertEquals(1f, model.value[0][0]);
        assertEquals(2.1f, model.value[0][1]);
        assertEquals(-0.3f, model.value[0][2]);
    }

    private static class Model {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      assertEquals(1, model.value.length);
        assertEquals(3, model.value[0].length);
        assertEquals(1f, model.value[0][0]);
        assertEquals(2.1f, model.value[0][1]);
        assertEquals(-0.3f, model.value[0][2]);
    }

    private static class Model {
        public float[][] value;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      assertEquals(3, model.value[0].length);
        assertEquals(1f, model.value[0][0]);
        assertEquals(2.1f, model.value[0][1]);
        assertEquals(-0.3f, model.value[0][2]);
    }

    private static class Model {
        public float[][] value;
    }

            

Reported by PMD.

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

Line: 21

                  }

    private static class Model {
        public float[][] value;
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1600/Issue1653.java
9 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

              import java.util.Map;

public class Issue1653 extends TestCase {
    public void test_for_issue() throws Exception {
ParserConfig config = new ParserConfig();
MapDeserializer deserializer = new MapDeserializer() {
    public Map<Object, Object> createMap(Type type) {
        return new CaseInsensitiveMap();
    }

            

Reported by PMD.

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

Line: 24

              config.putDeserializer(Map.class, deserializer);

CaseInsensitiveMap<String, Object> root = (CaseInsensitiveMap) JSON.parseObject("{\"val\":{}}", Map.class, config, Feature.CustomMapDeserializer);
CaseInsensitiveMap subMap = (CaseInsensitiveMap) root.get("val");
assertEquals(0, subMap.size());
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

              
CaseInsensitiveMap<String, Object> root = (CaseInsensitiveMap) JSON.parseObject("{\"val\":{}}", Map.class, config, Feature.CustomMapDeserializer);
CaseInsensitiveMap subMap = (CaseInsensitiveMap) root.get("val");
assertEquals(0, subMap.size());
    }
}

            

Reported by PMD.

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

Line: 25

              
CaseInsensitiveMap<String, Object> root = (CaseInsensitiveMap) JSON.parseObject("{\"val\":{}}", Map.class, config, Feature.CustomMapDeserializer);
CaseInsensitiveMap subMap = (CaseInsensitiveMap) root.get("val");
assertEquals(0, subMap.size());
    }
}

            

Reported by PMD.

Avoid unused imports such as 'org.apache.commons.collections4.map'
Design

Line: 8

              import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.MapDeserializer;
import junit.framework.TestCase;
import org.apache.commons.collections4.map.*;

import java.lang.reflect.Type;
import java.util.Map;

public class Issue1653 extends TestCase {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'config' (lines '15'-'26').
Error

Line: 15

              
public class Issue1653 extends TestCase {
    public void test_for_issue() throws Exception {
ParserConfig config = new ParserConfig();
MapDeserializer deserializer = new MapDeserializer() {
    public Map<Object, Object> createMap(Type type) {
        return new CaseInsensitiveMap();
    }
};

            

Reported by PMD.

Found 'DU'-anomaly for variable 'config' (lines '15'-'26').
Error

Line: 15

              
public class Issue1653 extends TestCase {
    public void test_for_issue() throws Exception {
ParserConfig config = new ParserConfig();
MapDeserializer deserializer = new MapDeserializer() {
    public Map<Object, Object> createMap(Type type) {
        return new CaseInsensitiveMap();
    }
};

            

Reported by PMD.

Found 'DU'-anomaly for variable 'deserializer' (lines '16'-'26').
Error

Line: 16

              public class Issue1653 extends TestCase {
    public void test_for_issue() throws Exception {
ParserConfig config = new ParserConfig();
MapDeserializer deserializer = new MapDeserializer() {
    public Map<Object, Object> createMap(Type type) {
        return new CaseInsensitiveMap();
    }
};
config.putDeserializer(Map.class, deserializer);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'deserializer' (lines '16'-'26').
Error

Line: 16

              public class Issue1653 extends TestCase {
    public void test_for_issue() throws Exception {
ParserConfig config = new ParserConfig();
MapDeserializer deserializer = new MapDeserializer() {
    public Map<Object, Object> createMap(Type type) {
        return new CaseInsensitiveMap();
    }
};
config.putDeserializer(Map.class, deserializer);

            

Reported by PMD.