The following issues were found

src/test/java/com/alibaba/json/bvt/parser/creator/JSONCreatorTest10.java
10 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

              import junit.framework.TestCase;

public class JSONCreatorTest10 extends TestCase {
    public void test_for_yk() throws Exception {
        String jsonString = "{\"link\":\"http://lqgzs.org/fsqhwlnf\",\"text\":\"乐动力专享\"}";
        JSONObject headerJSON = JSONObject.parseObject(jsonString);
        HeaderDTO headerDTO = headerJSON.toJavaObject(HeaderDTO.class);

        assertEquals("http://lqgzs.org/fsqhwlnf", headerDTO.link);

            

Reported by PMD.

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

Line: 10

              import junit.framework.TestCase;

public class JSONCreatorTest10 extends TestCase {
    public void test_for_yk() throws Exception {
        String jsonString = "{\"link\":\"http://lqgzs.org/fsqhwlnf\",\"text\":\"乐动力专享\"}";
        JSONObject headerJSON = JSONObject.parseObject(jsonString);
        HeaderDTO headerDTO = headerJSON.toJavaObject(HeaderDTO.class);

        assertEquals("http://lqgzs.org/fsqhwlnf", headerDTO.link);

            

Reported by PMD.

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

Line: 13

                  public void test_for_yk() throws Exception {
        String jsonString = "{\"link\":\"http://lqgzs.org/fsqhwlnf\",\"text\":\"乐动力专享\"}";
        JSONObject headerJSON = JSONObject.parseObject(jsonString);
        HeaderDTO headerDTO = headerJSON.toJavaObject(HeaderDTO.class);

        assertEquals("http://lqgzs.org/fsqhwlnf", headerDTO.link);
        assertEquals("乐动力专享", headerDTO.title);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                      JSONObject headerJSON = JSONObject.parseObject(jsonString);
        HeaderDTO headerDTO = headerJSON.toJavaObject(HeaderDTO.class);

        assertEquals("http://lqgzs.org/fsqhwlnf", headerDTO.link);
        assertEquals("乐动力专享", headerDTO.title);
    }

    public static class HeaderDTO {
        private String title;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      HeaderDTO headerDTO = headerJSON.toJavaObject(HeaderDTO.class);

        assertEquals("http://lqgzs.org/fsqhwlnf", headerDTO.link);
        assertEquals("乐动力专享", headerDTO.title);
    }

    public static class HeaderDTO {
        private String title;
        private String link;

            

Reported by PMD.

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

Line: 20

                  }

    public static class HeaderDTO {
        private String title;
        private String link;

        @JSONCreator
        public HeaderDTO(@JSONField(name = "text") String title,@JSONField(name = "link") String link) {
            this.title = title;

            

Reported by PMD.

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

Line: 20

                  }

    public static class HeaderDTO {
        private String title;
        private String link;

        @JSONCreator
        public HeaderDTO(@JSONField(name = "text") String title,@JSONField(name = "link") String link) {
            this.title = title;

            

Reported by PMD.

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

Line: 21

              
    public static class HeaderDTO {
        private String title;
        private String link;

        @JSONCreator
        public HeaderDTO(@JSONField(name = "text") String title,@JSONField(name = "link") String link) {
            this.title = title;
            this.link = link;

            

Reported by PMD.

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

Line: 21

              
    public static class HeaderDTO {
        private String title;
        private String link;

        @JSONCreator
        public HeaderDTO(@JSONField(name = "text") String title,@JSONField(name = "link") String link) {
            this.title = title;
            this.link = link;

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSON'
Design

Line: 3

              package com.alibaba.json.bvt.parser.creator;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;
import junit.framework.TestCase;

public class JSONCreatorTest10 extends TestCase {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/SpecialTest.java
10 issues
System.out.println is used
Design

Line: 16

                              count++;
            }
        }
        System.out.println(count);
    }
    
    final static long flags;
    static {
        long val = 0L;

            

Reported by PMD.

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

              
import com.alibaba.fastjson.serializer.SerializerFeature;

public class SpecialTest {
    
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 7

              
public class SpecialTest {
    
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 28

                  }
    
    static boolean isSpecial(char ch) {
        if (ch <= 31) {
            return true;
        }
        
        if (ch > '\\') { // 92
            return false;

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 32

                          return true;
        }
        
        if (ch > '\\') { // 92
            return false;
        }
        
        return ((1L << (ch - 31)) & flags) != 0;
    }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 44

                      // return false;
        // }
        
        if (ch == ' ') { // 32
            return false;
        }

        if (ch == '/') { // 47
            return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 48

                          return false;
        }

        if (ch == '/') { // 47
            return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);
        }

        if (ch > '#' // 35
            && ch != '\\' // 92

            

Reported by PMD.

Avoid unnecessary if..then..else statements when returning booleans
Design

Line: 58

                          return false;
        }

        if (ch <= 0x1F // 31
                || ch == '\\' // 92
                || ch == '"' // 34
                ) {
            return true;
        }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'count' (lines '9'-'13').
Error

Line: 9

                  
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {
                count++;
            }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'count' (lines '13'-'13').
Error

Line: 13

                      for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {
                count++;
            }
        }
        System.out.println(count);
    }
    

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/JSONLibDataFormatSerializer.java
10 issues
Potential violation of Law of Demeter (static property access)
Design

Line: 17

                  @SuppressWarnings("deprecation")
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    	if (object == null) {
    		serializer.out.writeNull();
    		return;
    	}
    	
        Date date = (Date) object;
       

            

Reported by PMD.

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

Line: 24

                      Date date = (Date) object;
       
        JSONObject json = new JSONObject();
        json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());

            

Reported by PMD.

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

Line: 25

                     
        JSONObject json = new JSONObject();
        json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());

            

Reported by PMD.

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

Line: 26

                      JSONObject json = new JSONObject();
        json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());

            

Reported by PMD.

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

Line: 27

                      json.put("date", date.getDate());
        json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

            

Reported by PMD.

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

Line: 28

                      json.put("day", date.getDay());
        json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());


            

Reported by PMD.

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

Line: 29

                      json.put("hours", date.getHours());
        json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

        serializer.write(json);

            

Reported by PMD.

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

Line: 30

                      json.put("minutes", date.getMinutes());
        json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

        serializer.write(json);
    }

            

Reported by PMD.

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

Line: 31

                      json.put("month", date.getMonth());
        json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

        serializer.write(json);
    }
}

            

Reported by PMD.

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

Line: 32

                      json.put("seconds", date.getSeconds());
        json.put("time", date.getTime());
        json.put("timezoneOffset", date.getTimezoneOffset());
        json.put("year", date.getYear());

        serializer.write(json);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/path/JSONPath_12.java
10 issues
System.out.println is used
Design

Line: 44

              
        assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

System.out.println is used
Design

Line: 45

                      assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

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

Line: 12

              public class JSONPath_12
        extends TestCase {

    public void test(){
        JSONObject schemaResult = JSON.parseObject("{\n" +
                "  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n" +
                "  \"title\": \"AE product schema\",\n" +
                "  \"description\": \"AE product schema\",\n" +
                "  \"type\": \"object\",\n" +

            

Reported by PMD.

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

Line: 12

              public class JSONPath_12
        extends TestCase {

    public void test(){
        JSONObject schemaResult = JSON.parseObject("{\n" +
                "  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n" +
                "  \"title\": \"AE product schema\",\n" +
                "  \"description\": \"AE product schema\",\n" +
                "  \"type\": \"object\",\n" +

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 38

                              "  \"title\": \"Brand Name\",\n" +
                "  \"type\": \"String\"\n" +
                "}");
        assertTrue(
                JSONPath.set(schemaResult, jsonPath + "['" + attributeName + "']" , attributeValue)
        );

        assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 42

                              JSONPath.set(schemaResult, jsonPath + "['" + attributeName + "']" , attributeValue)
        );

        assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

            

Reported by PMD.

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

Line: 45

                      assertTrue(JSONPath.contains(schemaResult, jsonPath + "['" + attributeName + "']"));
        JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

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

Line: 46

                      JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

                      JSONObject newAttribute = (JSONObject)JSONPath.eval(schemaResult, jsonPath);
        System.out.println(schemaResult);
        System.out.println(JSONPath.read(schemaResult.toJSONString(), jsonPath + "['" + attributeName + "']"));
        assertTrue(newAttribute.containsKey("Brand. Name"));
    }

}

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONArray'
Design

Line: 4

              package com.alibaba.json.bvt.path;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import junit.framework.TestCase;

public class JSONPath_12

            

Reported by PMD.

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

Line: 42

              
        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }
    
    public static class AisleDeployInfo {

            

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

              
public class Bug_for_issue_256 extends TestCase {

    public void test_for_issue() throws Exception {
        List<AisleDeployInfo> list3 = new ArrayList<AisleDeployInfo>();
        AisleDeployInfo aisleDeployInfo = new AisleDeployInfo();
        aisleDeployInfo.setId(1L);
        aisleDeployInfo.setProvinceArea("3,4,5");
        list3.add(aisleDeployInfo);

            

Reported by PMD.

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

Line: 17

              
public class Bug_for_issue_256 extends TestCase {

    public void test_for_issue() throws Exception {
        List<AisleDeployInfo> list3 = new ArrayList<AisleDeployInfo>();
        AisleDeployInfo aisleDeployInfo = new AisleDeployInfo();
        aisleDeployInfo.setId(1L);
        aisleDeployInfo.setProvinceArea("3,4,5");
        list3.add(aisleDeployInfo);

            

Reported by PMD.

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

Line: 40

                      Map<String, List<AisleDeployInfo>> map1 = JSON.parseObject(str, new TypeReference<Map<String, List<AisleDeployInfo>>>(){});
        List<AisleDeployInfo> aList = map1.get("1");

        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 40

                      Map<String, List<AisleDeployInfo>> map1 = JSON.parseObject(str, new TypeReference<Map<String, List<AisleDeployInfo>>>(){});
        List<AisleDeployInfo> aList = map1.get("1");

        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }

            

Reported by PMD.

This for loop can be replaced by a foreach loop
Design

Line: 41

                      List<AisleDeployInfo> aList = map1.get("1");

        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }
    

            

Reported by PMD.

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

Line: 42

              
        if (aList != null && aList.size() > 0) {
            for (int i = 0; i < aList.size(); i++) {
                System.out.println(aList.get(i).getId());
            }
        }
    }
    
    public static class AisleDeployInfo {

            

Reported by PMD.

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

Line: 47

                      }
    }
    
    public static class AisleDeployInfo {
        private long id;
        private String provinceArea;
        
        public long getId() {
            return id;

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 75

                      
    }

    public static class Model extends HashMap {

    }
}

            

Reported by PMD.

Avoid unused imports such as 'org.junit.Assert'
Design

Line: 8

              import java.util.List;
import java.util.Map;

import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import junit.framework.TestCase;

            

Reported by PMD.

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

Line: 22

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

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


            

Reported by PMD.

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

Line: 14

              import com.alibaba.fastjson.serializer.SerializerFeature;

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

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

            

Reported by PMD.

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

Line: 15

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

    public void test_list() throws Exception {
        A a = new A();
        a.setList(Collections.singletonList(new B()));

            

Reported by PMD.

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

Line: 18

                      com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection");
    }

    public void test_list() throws Exception {
        A a = new A();
        a.setList(Collections.singletonList(new B()));
        String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
        System.out.println(text);
        Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection$A\",\"list\":[{}]}",

            

Reported by PMD.

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

Line: 28

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

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    private static class A {


            

Reported by PMD.

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

Line: 28

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

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    private static class A {


            

Reported by PMD.

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

Line: 29

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

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    private static class A {

        private Collection<B> list;

            

Reported by PMD.

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

Line: 29

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

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    private static class A {

        private Collection<B> list;

            

Reported by PMD.

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

Line: 29

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

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    private static class A {

        private Collection<B> list;

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.parser.ParserConfig'
Design

Line: 6

              import java.util.Collection;
import java.util.Collections;

import com.alibaba.fastjson.parser.ParserConfig;
import org.junit.Assert;
import junit.framework.TestCase;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

            

Reported by PMD.

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

Line: 26

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

        ParserConfig parserConfig = new ParserConfig();
        parserConfig.addAccept("com.alibaba.json.bvt");

            

Reported by PMD.

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

Line: 15

              import com.alibaba.fastjson.serializer.SerializerFeature;

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

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

            

Reported by PMD.

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

Line: 16

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

    public void test_list() throws Exception {
        A a = new A();
        Set<B> set = new LinkedHashSet<B>();

            

Reported by PMD.

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

Line: 19

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

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

            

Reported by PMD.

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

Line: 34

                      parserConfig.addAccept("com.alibaba.json.bvt");
        A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

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

    private static class A {

            

Reported by PMD.

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

Line: 34

                      parserConfig.addAccept("com.alibaba.json.bvt");
        A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

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

    private static class A {

            

Reported by PMD.

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

Line: 35

                      A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

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

    private static class A {


            

Reported by PMD.

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

Line: 35

                      A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

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

    private static class A {


            

Reported by PMD.

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

Line: 36

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

    private static class A {

        private Set<B> list;

            

Reported by PMD.

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

Line: 36

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

    private static class A {

        private Set<B> list;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/ProxyTest2.java
10 issues
System.out.println is used
Design

Line: 15

                  public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());

        assertEquals("{\"id\":1001}", 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: 12

               * Created by wenshao on 07/08/2017.
 */
public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 07/08/2017.
 */
public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());

            

Reported by PMD.

The String literal '{\'id\':1001}' appears 4 times in this file; the first occurrence is on line 13
Error

Line: 13

               */
public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());

            

Reported by PMD.

Avoid unused local variables such as 'model2'.
Design

Line: 14

              public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());


            

Reported by PMD.

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

Line: 15

                  public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());

        assertEquals("{\"id\":1001}", JSON.toJSONString(model));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              //        System.out.println(model.getClass());
//        System.out.println(model2.getClass());

        assertEquals("{\"id\":1001}", JSON.toJSONString(model));
        assertEquals("{\"id\":1001}", JSON.toJSONString(model));

    }

    public static interface Model {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

              //        System.out.println(model2.getClass());

        assertEquals("{\"id\":1001}", JSON.toJSONString(model));
        assertEquals("{\"id\":1001}", JSON.toJSONString(model));

    }

    public static interface Model {
        int getId();

            

Reported by PMD.

Avoid unused imports such as 'java.lang.reflect.Proxy'
Design

Line: 6

              import com.alibaba.fastjson.JSON;
import junit.framework.TestCase;

import java.lang.reflect.Proxy;

/**
 * Created by wenshao on 07/08/2017.
 */
public class ProxyTest2 extends TestCase {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'model2' (lines '14'-'23').
Error

Line: 14

              public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());


            

Reported by PMD.

src/test/java/com/alibaba/fastjson/codegen/ClassGen.java
10 issues
This class has too many methods, consider refactoring it.
Design

Line: 6

              import java.io.IOException;
import java.lang.reflect.Type;

public abstract class ClassGen {

    protected Class<?>   clazz;
    protected Type       type;
    protected Appendable out;


            

Reported by PMD.

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

Line: 8

              
public abstract class ClassGen {

    protected Class<?>   clazz;
    protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

            

Reported by PMD.

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

Line: 9

              public abstract class ClassGen {

    protected Class<?>   clazz;
    protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;


            

Reported by PMD.

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

Line: 10

              
    protected Class<?>   clazz;
    protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){

            

Reported by PMD.

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

Line: 12

                  protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){
        this(clazz, null, out);
    }

            

Reported by PMD.

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

Line: 12

                  protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){
        this(clazz, null, out);
    }

            

Reported by PMD.

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

Line: 13

                  protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){
        this(clazz, null, out);
    }


            

Reported by PMD.

Avoid using redundant field initializer for 'indentCount'
Performance

Line: 13

                  protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){
        this(clazz, null, out);
    }


            

Reported by PMD.

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

Line: 44

              
    protected void printPackage() throws IOException {
        print("package ");
        print(clazz.getPackage().getName());
        println(";");
    }

    protected void beginClass(String className) throws IOException {
        print("public class ");

            

Reported by PMD.

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

Line: 102

                  
    protected void printClassName(Class<?> clazz) throws IOException {
        String name = clazz.getName();
        name = name.replace('$', '.');
        print(name);
    }
}

            

Reported by PMD.

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

Line: 22

                      vo.getMap().put(1L, new VAL());
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        System.out.println(text);
        
        JSON.parse(text);
    }
    
    public void test_1() throws Exception {

            

Reported by PMD.

System.out.println is used
Design

Line: 33

                      submap.put("subkey", "subvalue");
        map.put(submap, "value");
        String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        System.out.println(jsonString);
        Object object = JSON.parse(jsonString);
        System.out.println(object.toString());
    }

    public static class VO {

            

Reported by PMD.

System.out.println is used
Design

Line: 35

                      String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        System.out.println(jsonString);
        Object object = JSON.parse(jsonString);
        System.out.println(object.toString());
    }

    public static class VO {

        private Map<Long, VAL> map = new HashMap<Long, VAL>();

            

Reported by PMD.

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

Line: 13

              import junit.framework.TestCase;

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

    public void test_bug() throws Exception {
        VO vo = new VO();

            

Reported by PMD.

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

Line: 14

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

    public void test_bug() throws Exception {
        VO vo = new VO();
        vo.getMap().put(1L, new VAL());

            

Reported by PMD.

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

Line: 17

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

    public void test_bug() throws Exception {
        VO vo = new VO();
        vo.getMap().put(1L, new VAL());
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        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: 17

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

    public void test_bug() throws Exception {
        VO vo = new VO();
        vo.getMap().put(1L, new VAL());
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        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: 27

                      JSON.parse(text);
    }
    
    public void test_1() throws Exception {
        Map<Map<String, String>, String> map = new HashMap<Map<String, String>, String>();
        Map<String, String> submap = new HashMap<String, String>();
        submap.put("subkey", "subvalue");
        map.put(submap, "value");
        String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 27

                      JSON.parse(text);
    }
    
    public void test_1() throws Exception {
        Map<Map<String, String>, String> map = new HashMap<Map<String, String>, String>();
        Map<String, String> submap = new HashMap<String, String>();
        submap.put("subkey", "subvalue");
        map.put(submap, "value");
        String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 35

                      String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        System.out.println(jsonString);
        Object object = JSON.parse(jsonString);
        System.out.println(object.toString());
    }

    public static class VO {

        private Map<Long, VAL> map = new HashMap<Long, VAL>();

            

Reported by PMD.