The following issues were found

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.

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

Line: 25

              
        String text = JSON.toJSONString(a1);
        Assert.assertEquals("{\"姓名\":\"A\",\"时间\":\"F\",\"满意度\":\"D\",\"状态\":\"C\",\"类型\":\"B\",\"统计\":\"E\"}", text);
        System.out.println(text);
        
        People a2 = JSON.parseObject(text, People.class);
        Assert.assertEquals(a1.get姓名(), a2.get姓名());
        Assert.assertEquals(a1.get类型(), a2.get类型());
        Assert.assertEquals(a1.get状态(), a2.get状态());

            

Reported by PMD.

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

Line: 14

              
public class Bug_for_BlankRain_Issue_502 extends TestCase {

    public void test_for_issue() throws Exception {
        People a1 = new People();
        a1.set姓名("A");
        a1.set类型("B");
        a1.set状态("C");
        a1.set满意度("D");

            

Reported by PMD.

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

Line: 28

                      System.out.println(text);
        
        People a2 = JSON.parseObject(text, People.class);
        Assert.assertEquals(a1.get姓名(), a2.get姓名());
        Assert.assertEquals(a1.get类型(), a2.get类型());
        Assert.assertEquals(a1.get状态(), a2.get状态());
        Assert.assertEquals(a1.get满意度(), a2.get满意度());
        Assert.assertEquals(a1.get统计(), a2.get统计());
        Assert.assertEquals(a1.get时间(), a2.get时间());

            

Reported by PMD.

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

Line: 29

                      
        People a2 = JSON.parseObject(text, People.class);
        Assert.assertEquals(a1.get姓名(), a2.get姓名());
        Assert.assertEquals(a1.get类型(), a2.get类型());
        Assert.assertEquals(a1.get状态(), a2.get状态());
        Assert.assertEquals(a1.get满意度(), a2.get满意度());
        Assert.assertEquals(a1.get统计(), a2.get统计());
        Assert.assertEquals(a1.get时间(), a2.get时间());
    }

            

Reported by PMD.

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

Line: 30

                      People a2 = JSON.parseObject(text, People.class);
        Assert.assertEquals(a1.get姓名(), a2.get姓名());
        Assert.assertEquals(a1.get类型(), a2.get类型());
        Assert.assertEquals(a1.get状态(), a2.get状态());
        Assert.assertEquals(a1.get满意度(), a2.get满意度());
        Assert.assertEquals(a1.get统计(), a2.get统计());
        Assert.assertEquals(a1.get时间(), a2.get时间());
    }


            

Reported by PMD.

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

Line: 31

                      Assert.assertEquals(a1.get姓名(), a2.get姓名());
        Assert.assertEquals(a1.get类型(), a2.get类型());
        Assert.assertEquals(a1.get状态(), a2.get状态());
        Assert.assertEquals(a1.get满意度(), a2.get满意度());
        Assert.assertEquals(a1.get统计(), a2.get统计());
        Assert.assertEquals(a1.get时间(), a2.get时间());
    }

    public static class People {

            

Reported by PMD.

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

Line: 32

                      Assert.assertEquals(a1.get类型(), a2.get类型());
        Assert.assertEquals(a1.get状态(), a2.get状态());
        Assert.assertEquals(a1.get满意度(), a2.get满意度());
        Assert.assertEquals(a1.get统计(), a2.get统计());
        Assert.assertEquals(a1.get时间(), a2.get时间());
    }

    public static class People {


            

Reported by PMD.

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

Line: 33

                      Assert.assertEquals(a1.get状态(), a2.get状态());
        Assert.assertEquals(a1.get满意度(), a2.get满意度());
        Assert.assertEquals(a1.get统计(), a2.get统计());
        Assert.assertEquals(a1.get时间(), a2.get时间());
    }

    public static class People {

        private String 姓名;

            

Reported by PMD.

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

Line: 36

                      Assert.assertEquals(a1.get时间(), a2.get时间());
    }

    public static class People {

        private String 姓名;
        private String 类型;
        private String 状态;
        private String 满意度;

            

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/fastjson/serializer/TestParse.java
9 issues
The Logger variable declaration does not contain the static and final modifiers
Error

Line: 15

               * Created by yixian on 2016-02-25.
 */
public class TestParse {
    private final Logger logger = Logger.getLogger(TestParse.class.getSimpleName());

    private String jsonString;

    @Before
    public void prepareJsonString() {

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 31

              
    @Test
    public void testParse() {
        logger.info("parsing json string:" + jsonString);
        TestBean testBean = (TestBean) JSON.parse(jsonString);
        assert testBean.getData() != null;
        assert "tester".equals(testBean.getName());
        assert "value".equals(testBean.getData().getString("key"));
    }

            

Reported by PMD.

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

Line: 15

               * Created by yixian on 2016-02-25.
 */
public class TestParse {
    private final Logger logger = Logger.getLogger(TestParse.class.getSimpleName());

    private String jsonString;

    @Before
    public void prepareJsonString() {

            

Reported by PMD.

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

Line: 17

              public class TestParse {
    private final Logger logger = Logger.getLogger(TestParse.class.getSimpleName());

    private String jsonString;

    @Before
    public void prepareJsonString() {
        TestBean bean = new TestBean();
        bean.setName("tester");

            

Reported by PMD.

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

Line: 30

                  }

    @Test
    public void testParse() {
        logger.info("parsing json string:" + jsonString);
        TestBean testBean = (TestBean) JSON.parse(jsonString);
        assert testBean.getData() != null;
        assert "tester".equals(testBean.getName());
        assert "value".equals(testBean.getData().getString("key"));

            

Reported by PMD.

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

Line: 33

                  public void testParse() {
        logger.info("parsing json string:" + jsonString);
        TestBean testBean = (TestBean) JSON.parse(jsonString);
        assert testBean.getData() != null;
        assert "tester".equals(testBean.getName());
        assert "value".equals(testBean.getData().getString("key"));
    }
}

            

Reported by PMD.

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

Line: 34

                      logger.info("parsing json string:" + jsonString);
        TestBean testBean = (TestBean) JSON.parse(jsonString);
        assert testBean.getData() != null;
        assert "tester".equals(testBean.getName());
        assert "value".equals(testBean.getData().getString("key"));
    }
}

            

Reported by PMD.

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

Line: 35

                      TestBean testBean = (TestBean) JSON.parse(jsonString);
        assert testBean.getData() != null;
        assert "tester".equals(testBean.getName());
        assert "value".equals(testBean.getData().getString("key"));
    }
}

            

Reported by PMD.

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

Line: 35

                      TestBean testBean = (TestBean) JSON.parse(jsonString);
        assert testBean.getData() != null;
        assert "tester".equals(testBean.getName());
        assert "value".equals(testBean.getData().getString("key"));
    }
}

            

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.

src/test/java/com/alibaba/fastjson/serializer/SerializeWriterToBytesTest.java
9 issues
All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 11

              /**
 * @author gongdewei 2020/5/15
 */
public class SerializeWriterToBytesTest {

    /**
     * Execute toBytes periodically, use tools to analyze JVM memory allocation.
     * For example, Memory Allocation Record of YourKit java profiler
     */

            

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

                   * Execute toBytes periodically, use tools to analyze JVM memory allocation.
     * For example, Memory Allocation Record of YourKit java profiler
     */
    public static void testLargeStrToBytes() {
        String str = createTestStr();
        for (int i = 0; i < 600; i++) {
            SerializeWriter writer = new SerializeWriter();
            try {
                writer.writeString(str);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 20

                  public static void testLargeStrToBytes() {
        String str = createTestStr();
        for (int i = 0; i < 600; i++) {
            SerializeWriter writer = new SerializeWriter();
            try {
                writer.writeString(str);
                writer.toBytes("UTF-8");
            } finally {
                writer.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: 34

                      }
    }

    public static void testLargeStrWriteToEx() throws IOException {
        String str = createTestStr();
        ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length()+2);
        for (int i = 0; i < 600; i++) {
            SerializeWriter writer = new SerializeWriter();
            try {

            

Reported by PMD.

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

Line: 36

              
    public static void testLargeStrWriteToEx() throws IOException {
        String str = createTestStr();
        ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length()+2);
        for (int i = 0; i < 600; i++) {
            SerializeWriter writer = new SerializeWriter();
            try {
                writer.writeString(str);
                writer.writeToEx(baos, IOUtils.UTF8);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 38

                      String str = createTestStr();
        ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length()+2);
        for (int i = 0; i < 600; i++) {
            SerializeWriter writer = new SerializeWriter();
            try {
                writer.writeString(str);
                writer.writeToEx(baos, IOUtils.UTF8);
            } finally {
                writer.close();

            

Reported by PMD.

Found 'DU'-anomaly for variable 'str' (lines '18'-'32').
Error

Line: 18

                   * For example, Memory Allocation Record of YourKit java profiler
     */
    public static void testLargeStrToBytes() {
        String str = createTestStr();
        for (int i = 0; i < 600; i++) {
            SerializeWriter writer = new SerializeWriter();
            try {
                writer.writeString(str);
                writer.toBytes("UTF-8");

            

Reported by PMD.

Found 'DU'-anomaly for variable 'baos' (lines '36'-'51').
Error

Line: 36

              
    public static void testLargeStrWriteToEx() throws IOException {
        String str = createTestStr();
        ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length()+2);
        for (int i = 0; i < 600; i++) {
            SerializeWriter writer = new SerializeWriter();
            try {
                writer.writeString(str);
                writer.writeToEx(baos, IOUtils.UTF8);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'tmp' (lines '54'-'60').
Error

Line: 54

                  }

    private static String createTestStr() {
        String tmp = new String(IOUtils.DIGITS);
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < 400; i++) {
            builder.append(tmp);
        }
        return builder.toString();

            

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/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/issue_3400/Issue3453.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 Issue3453 extends TestCase {

    public void test_for_issue() throws Exception {
        String str = "[\n" +
                " {\n" +
                " \"altitude\": 109.0,\n" +
                " \"angle\": 5.0,\n" +
                " \"index\": 1,\n" +

            

Reported by PMD.

The String literal ' {\n' appears 7 times in this file; the first occurrence is on line 17
Error

Line: 17

              
    public void test_for_issue() throws Exception {
        String str = "[\n" +
                " {\n" +
                " \"altitude\": 109.0,\n" +
                " \"angle\": 5.0,\n" +
                " \"index\": 1,\n" +
                " \"type\": 1\n" +
                " },\n" +

            

Reported by PMD.

The String literal ' },\n' appears 6 times in this file; the first occurrence is on line 22
Error

Line: 22

                              " \"angle\": 5.0,\n" +
                " \"index\": 1,\n" +
                " \"type\": 1\n" +
                " },\n" +
                " {\n" +
                " \"altitude\": 1307.0,\n" +
                " \"angle\": 5.0,\n" +
                " \"index\": 2,\n" +
                " \"type\": 1\n" +

            

Reported by PMD.

The String literal ' \'altitude\': 22.0,\n' appears 5 times in this file; the first occurrence is on line 30
Error

Line: 30

                              " \"type\": 1\n" +
                " },\n" +
                " {\n" +
                " \"altitude\": 22.0,\n" +
                " \"angle\": 7.0,\n" +
                " \"index\": 3,\n" +
                " \"type\": 1\n" +
                " },\n" +
                " {\n" +

            

Reported by PMD.

The String literal ' \'angle\': 7.0,\n' appears 5 times in this file; the first occurrence is on line 31
Error

Line: 31

                              " },\n" +
                " {\n" +
                " \"altitude\": 22.0,\n" +
                " \"angle\": 7.0,\n" +
                " \"index\": 3,\n" +
                " \"type\": 1\n" +
                " },\n" +
                " {\n" +
                " \"altitude\": 22.0,\n" +

            

Reported by PMD.

The String literal ' \'type\': 2\n' appears 4 times in this file; the first occurrence is on line 39
Error

Line: 39

                              " \"altitude\": 22.0,\n" +
                " \"angle\": 7.0,\n" +
                " \"index\": 4,\n" +
                " \"type\": 2\n" +
                " },\n" +
                " {\n" +
                " \"altitude\": 22.0,\n" +
                " \"angle\": 7.0,\n" +
                " \"index\": 5,\n" +

            

Reported by PMD.

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

Line: 61

                              " }\n" +
                "]";
        JSONValidator validator = JSONValidator.from(str);
        Assert.assertTrue(validator.validate());
        JSONValidator.Type type = validator.getType();
        Assert.assertEquals("Array",type.name());
    }

}

            

Reported by PMD.

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

Line: 62

                              "]";
        JSONValidator validator = JSONValidator.from(str);
        Assert.assertTrue(validator.validate());
        JSONValidator.Type type = validator.getType();
        Assert.assertEquals("Array",type.name());
    }

}

            

Reported by PMD.

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

Line: 63

                      JSONValidator validator = JSONValidator.from(str);
        Assert.assertTrue(validator.validate());
        JSONValidator.Type type = validator.getType();
        Assert.assertEquals("Array",type.name());
    }

}

            

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.