The following issues were found

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.

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

Line: 13

              
public class JSONFieldTest_unwrapped_2 extends TestCase {

    public void test_jsonField() throws Exception {
        String text = "{\"id\":123,\"latitude\":37,\"longitude\":127}";
        Assert.assertEquals("{\"id\":123,\"latitude\":37,\"longitude\":127}", text);

        VO vo2 = JSON.parseObject(text, VO.class);
        assertNotNull(vo2.properties);

            

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

    public void test_jsonField() throws Exception {
        String text = "{\"id\":123,\"latitude\":37,\"longitude\":127}";
        Assert.assertEquals("{\"id\":123,\"latitude\":37,\"longitude\":127}", text);

        VO vo2 = JSON.parseObject(text, VO.class);
        assertNotNull(vo2.properties);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

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

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

    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

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

    }

    public static class VO {

            

Reported by PMD.

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

Line: 19

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

    }

    public static class VO {

            

Reported by PMD.

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

Line: 20

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

    }

    public static class VO {
        public int id;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

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

    }

    public static class VO {
        public int id;

            

Reported by PMD.

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

Line: 27

                  public static class VO {
        public int id;

        private Map<String, Object> properties = new LinkedHashMap<String, Object>();

        @JSONField(unwrapped = true)
        public void setProperty(String key, Object value) {
            properties.put(key, value);
        }

            

Reported by PMD.

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

Line: 27

                  public static class VO {
        public int id;

        private Map<String, Object> properties = new LinkedHashMap<String, Object>();

        @JSONField(unwrapped = true)
        public void setProperty(String key, Object value) {
            properties.put(key, value);
        }

            

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/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/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/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/issue_1600/Issue1603_getter.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: 11

              import java.util.Collections;

public class Issue1603_getter extends TestCase {
    public void test_emptySet() throws Exception {
        Model_1 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_1.class);
        assertEquals(0, m.values.size());
    }

    public void test_emptyList() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

              public class Issue1603_getter extends TestCase {
    public void test_emptySet() throws Exception {
        Model_1 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_1.class);
        assertEquals(0, m.values.size());
    }

    public void test_emptyList() throws Exception {
        Model_2 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_2.class);
        assertEquals(0, m.values.size());

            

Reported by PMD.

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

Line: 13

              public class Issue1603_getter extends TestCase {
    public void test_emptySet() throws Exception {
        Model_1 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_1.class);
        assertEquals(0, m.values.size());
    }

    public void test_emptyList() throws Exception {
        Model_2 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_2.class);
        assertEquals(0, m.values.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: 16

                      assertEquals(0, m.values.size());
    }

    public void test_emptyList() throws Exception {
        Model_2 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_2.class);
        assertEquals(0, m.values.size());
    }

    public void test_unmodifier() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
    public void test_emptyList() throws Exception {
        Model_2 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_2.class);
        assertEquals(0, m.values.size());
    }

    public void test_unmodifier() throws Exception {
        Model_3 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_3.class);
        assertEquals(0, m.values.size());

            

Reported by PMD.

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

Line: 18

              
    public void test_emptyList() throws Exception {
        Model_2 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_2.class);
        assertEquals(0, m.values.size());
    }

    public void test_unmodifier() throws Exception {
        Model_3 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_3.class);
        assertEquals(0, m.values.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: 21

                      assertEquals(0, m.values.size());
    }

    public void test_unmodifier() throws Exception {
        Model_3 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_3.class);
        assertEquals(0, m.values.size());
    }

    public static class Model_1 {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

              
    public void test_unmodifier() throws Exception {
        Model_3 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_3.class);
        assertEquals(0, m.values.size());
    }

    public static class Model_1 {
        private final Collection<String> values = Collections.emptySet();


            

Reported by PMD.

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

Line: 23

              
    public void test_unmodifier() throws Exception {
        Model_3 m = JSON.parseObject("{\"values\":[\"a\"]}", Model_3.class);
        assertEquals(0, m.values.size());
    }

    public static class Model_1 {
        private final Collection<String> values = Collections.emptySet();


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/typeRef/TypeReferenceTest6.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: 15

              
public class TypeReferenceTest6 extends TestCase {

	public void test_typeRef() throws Exception {
		TypeReference<Map<String, Entity>> typeRef = new TypeReference<Map<String, Entity>>() {
		};

		Map<String, Entity> map = JSON.parseObject(
				"{\"value\":{\"id\":\"abc\",\"list\":[{\"id\":123}]}}", typeRef);

            

Reported by PMD.

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

Line: 22

              		Map<String, Entity> map = JSON.parseObject(
				"{\"value\":{\"id\":\"abc\",\"list\":[{\"id\":123}]}}", typeRef);

		Entity entity = map.get("value");
		Assert.assertNotNull(entity);
		Assert.assertEquals("abc", entity.getId());
		Assert.assertEquals(1, entity.getList().size());
		Assert.assertEquals(123, entity.getList().get(0).getId());
	}

            

Reported by PMD.

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

Line: 24

              
		Entity entity = map.get("value");
		Assert.assertNotNull(entity);
		Assert.assertEquals("abc", entity.getId());
		Assert.assertEquals(1, entity.getList().size());
		Assert.assertEquals(123, entity.getList().get(0).getId());
	}

	public static class Entity {

            

Reported by PMD.

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

Line: 25

              		Entity entity = map.get("value");
		Assert.assertNotNull(entity);
		Assert.assertEquals("abc", entity.getId());
		Assert.assertEquals(1, entity.getList().size());
		Assert.assertEquals(123, entity.getList().get(0).getId());
	}

	public static class Entity {
		private String id;

            

Reported by PMD.

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

Line: 25

              		Entity entity = map.get("value");
		Assert.assertNotNull(entity);
		Assert.assertEquals("abc", entity.getId());
		Assert.assertEquals(1, entity.getList().size());
		Assert.assertEquals(123, entity.getList().get(0).getId());
	}

	public static class Entity {
		private String id;

            

Reported by PMD.

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

Line: 26

              		Assert.assertNotNull(entity);
		Assert.assertEquals("abc", entity.getId());
		Assert.assertEquals(1, entity.getList().size());
		Assert.assertEquals(123, entity.getList().get(0).getId());
	}

	public static class Entity {
		private String id;


            

Reported by PMD.

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

Line: 26

              		Assert.assertNotNull(entity);
		Assert.assertEquals("abc", entity.getId());
		Assert.assertEquals(1, entity.getList().size());
		Assert.assertEquals(123, entity.getList().get(0).getId());
	}

	public static class Entity {
		private String id;


            

Reported by PMD.

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

Line: 26

              		Assert.assertNotNull(entity);
		Assert.assertEquals("abc", entity.getId());
		Assert.assertEquals(1, entity.getList().size());
		Assert.assertEquals(123, entity.getList().get(0).getId());
	}

	public static class Entity {
		private String id;


            

Reported by PMD.

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

Line: 29

              		Assert.assertEquals(123, entity.getList().get(0).getId());
	}

	public static class Entity {
		private String id;

		private List<A> list = new ArrayList<A>();

		public String getId() {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Bug_for_Johnny.java
9 issues
Do not use the short type
Performance

Line: 60

              
		private String stringType;
		private byte byteType;
		private short shortType;
		private int intType;
		private long longType;
		private char charType;
		private float floatType;
		private double doubleType;

            

Reported by PMD.

Do not use the short type
Performance

Line: 137

              		/**
		 * @return the shortType
		 */
		public short getShortType() {
			return shortType;
		}

		/**
		 * @param shortType

            

Reported by PMD.

Do not use the short type
Performance

Line: 145

              		 * @param shortType
		 *            the shortType to set
		 */
		public void setShortType(short shortType) {
			this.shortType = shortType;
		}

		/**
		 * @return the intType

            

Reported by PMD.

System.out.println is used
Design

Line: 47

                      myObject.setListType(listObj);
        
        String text = JSON.toJSONString(myObject, SerializerFeature.WriteClassName);
        System.out.println(text);
        MyObject myObject2 = (MyObject) JSON.parse(text);
        Assert.assertEquals(myObject2.getMapType(), myObject.getMapType());
	}
	
	public static enum EnumType {

            

Reported by PMD.

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

Line: 18

              import com.alibaba.fastjson.serializer.SerializerFeature;

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

	public void test_bug()throws Exception {
		MyObject myObject = new MyObject();

            

Reported by PMD.

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

Line: 19

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

	public void test_bug()throws Exception {
		MyObject myObject = new MyObject();
        List<String> listObj = new LinkedList<String>();

            

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

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

	public void test_bug()throws Exception {
		MyObject myObject = new MyObject();
        List<String> listObj = new LinkedList<String>();
        Set<String> setObj = new HashSet<String>();
        Map<String, String> mapObj = new HashMap<String, String>();
        listObj.add("aaa");

            

Reported by PMD.

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

Line: 49

                      String text = JSON.toJSONString(myObject, SerializerFeature.WriteClassName);
        System.out.println(text);
        MyObject myObject2 = (MyObject) JSON.parse(text);
        Assert.assertEquals(myObject2.getMapType(), myObject.getMapType());
	}
	
	public static enum EnumType {
		MD5, SHA1
	}

            

Reported by PMD.

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

Line: 56

              		MD5, SHA1
	}

	public static class MyObject {

		private String stringType;
		private byte byteType;
		private short shortType;
		private int intType;

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/EnumSerializer.java
9 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 28

               */
public class EnumSerializer implements ObjectSerializer {

    private final Member member;

    public EnumSerializer() {
        this.member = null;
    }


            

Reported by PMD.

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

Line: 31

                  private final Member member;

    public EnumSerializer() {
        this.member = null;
    }

    public EnumSerializer(Member member) {
        this.member = member;
    }

            

Reported by PMD.

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

Line: 43

                  public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        if (member == null) {
            SerializeWriter out = serializer.out;
            out.writeEnum((Enum<?>) object);
            return;
        }

        Object fieldValue = null;
        try {

            

Reported by PMD.

The initializer for variable 'fieldValue' is never used (overwritten on lines 50 and 52)
Design

Line: 47

                          return;
        }

        Object fieldValue = null;
        try {
            if (member instanceof Field) {
                fieldValue = ((Field) member).get(object);
            } else {
                fieldValue = ((Method) member).invoke(object);

            

Reported by PMD.

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

Line: 54

                          } else {
                fieldValue = ((Method) member).invoke(object);
            }
        } catch (Exception e) {
            throw new JSONException("getEnumValue error", e);
        }

        serializer.write(fieldValue);
    }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'fieldValue' (lines '47'-'52').
Error

Line: 47

                          return;
        }

        Object fieldValue = null;
        try {
            if (member instanceof Field) {
                fieldValue = ((Field) member).get(object);
            } else {
                fieldValue = ((Method) member).invoke(object);

            

Reported by PMD.

Found 'DD'-anomaly for variable 'fieldValue' (lines '47'-'50').
Error

Line: 47

                          return;
        }

        Object fieldValue = null;
        try {
            if (member instanceof Field) {
                fieldValue = ((Field) member).get(object);
            } else {
                fieldValue = ((Method) member).invoke(object);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'fieldValue' (lines '50'-'59').
Error

Line: 50

                      Object fieldValue = null;
        try {
            if (member instanceof Field) {
                fieldValue = ((Field) member).get(object);
            } else {
                fieldValue = ((Method) member).invoke(object);
            }
        } catch (Exception e) {
            throw new JSONException("getEnumValue error", e);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'fieldValue' (lines '52'-'59').
Error

Line: 52

                          if (member instanceof Field) {
                fieldValue = ((Field) member).get(object);
            } else {
                fieldValue = ((Method) member).invoke(object);
            }
        } catch (Exception e) {
            throw new JSONException("getEnumValue error", e);
        }


            

Reported by PMD.