The following issues were found

src/main/java/com/alibaba/fastjson/PropertyNamingStrategy.java
5 issues
The class 'PropertyNamingStrategy' has a Modified Cyclomatic Complexity of 11(Highest = 10).
Design

Line: 6

              /**
 * @since 1.2.15
 */
public enum PropertyNamingStrategy {
                                    CamelCase, // camelCase
                                    PascalCase, // PascalCase
                                    SnakeCase, // snake_case
                                    KebabCase, // kebab-case
                                    NoChange,  //

            

Reported by PMD.

The class 'PropertyNamingStrategy' has a Standard Cyclomatic Complexity of 14(Highest = 13).
Design

Line: 6

              /**
 * @since 1.2.15
 */
public enum PropertyNamingStrategy {
                                    CamelCase, // camelCase
                                    PascalCase, // PascalCase
                                    SnakeCase, // snake_case
                                    KebabCase, // kebab-case
                                    NoChange,  //

            

Reported by PMD.

The method 'translate' has a Standard Cyclomatic Complexity of 13.
Design

Line: 14

                                                  NoChange,  //
                                    NeverUseThisValueExceptDefaultValue;

    public String translate(String propertyName) {
        switch (this) {
            case SnakeCase: {
                StringBuilder buf = new StringBuilder();
                for (int i = 0; i < propertyName.length(); ++i) {
                    char ch = propertyName.charAt(i);

            

Reported by PMD.

The method 'translate(String)' has a cyclomatic complexity of 19.
Design

Line: 14

                                                  NoChange,  //
                                    NeverUseThisValueExceptDefaultValue;

    public String translate(String propertyName) {
        switch (this) {
            case SnakeCase: {
                StringBuilder buf = new StringBuilder();
                for (int i = 0; i < propertyName.length(); ++i) {
                    char ch = propertyName.charAt(i);

            

Reported by PMD.

The method 'translate' has a Modified Cyclomatic Complexity of 10.
Design

Line: 14

                                                  NoChange,  //
                                    NeverUseThisValueExceptDefaultValue;

    public String translate(String propertyName) {
        switch (this) {
            case SnakeCase: {
                StringBuilder buf = new StringBuilder();
                for (int i = 0; i < propertyName.length(); ++i) {
                    char ch = propertyName.charAt(i);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/SerializeWriterTest.java
5 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

              
public class SerializeWriterTest extends TestCase {

	public void test_0() throws Exception {
		SerializeWriter writer = new SerializeWriter();
		writer.append('A');
		writer.writeInt(156);
		Assert.assertEquals("A156", writer.toString());
		writer.writeLong(345);

            

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

              
	}

	public void test_1() throws Exception {
		SerializeWriter writer = new SerializeWriter();
		writer.writeInt(-1);
		Assert.assertEquals("-1", writer.toString());
	}


            

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("-1", writer.toString());
	}

	public void test_4() throws Exception {
		SerializeWriter writer = new SerializeWriter();
		writer.writeInt(-1);
		writer.write(',');
		Assert.assertEquals("-1,", writer.toString());
	}

            

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

              		Assert.assertEquals("-1,", writer.toString());
	}

	public void test_5() throws Exception {
		SerializeWriter writer = new SerializeWriter();
		writer.writeLong(-1L);
		Assert.assertEquals("-1", writer.toString());
	}


            

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

              		Assert.assertEquals("-1", writer.toString());
	}

	public void test_6() throws Exception {
		SerializeWriter writer = new SerializeWriter();
		writer.writeLong(-1L);
		writer.write(',');
		Assert.assertEquals("-1,", writer.toString());
	}

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/ReferenceCodec.java
5 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 42

                      Object item;
        if (object instanceof AtomicReference) {
            AtomicReference val = (AtomicReference) object;
            item = val.get();
        } else {
            item = ((Reference) object).get();
        }
        serializer.write(item);
    }

            

Reported by PMD.

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

Line: 52

                  @SuppressWarnings({ "unchecked", "rawtypes" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        ParameterizedType paramType = (ParameterizedType) type;
        Type itemType = paramType.getActualTypeArguments()[0];

        Object itemObject = parser.parseObject(itemType);

        Type rawType = paramType.getRawType();
        if (rawType == AtomicReference.class) {

            

Reported by PMD.

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

Line: 56

              
        Object itemObject = parser.parseObject(itemType);

        Type rawType = paramType.getRawType();
        if (rawType == AtomicReference.class) {
            return (T) new AtomicReference(itemObject);
        }

        if (rawType == WeakReference.class) {

            

Reported by PMD.

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

Line: 69

                          return (T) new SoftReference(itemObject);
        }

        throw new UnsupportedOperationException(rawType.toString());
    }

    public int getFastMatchToken() {
        return JSONToken.LBRACE;
    }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'itemObject' (lines '54'-'70').
Error

Line: 54

                      ParameterizedType paramType = (ParameterizedType) type;
        Type itemType = paramType.getActualTypeArguments()[0];

        Object itemObject = parser.parseObject(itemType);

        Type rawType = paramType.getRawType();
        if (rawType == AtomicReference.class) {
            return (T) new AtomicReference(itemObject);
        }

            

Reported by PMD.

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

Line: 18

                      user.setDescrition("大黄牛");

        String text = JSON.toJSONString(user);
        System.out.println(text);

        User user1 = JSON.parseObject(text, User.class);

        Assert.assertEquals(user1.getId(), user.getId());
        Assert.assertEquals(user1.getName(), user.getName());

            

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

              
public class AnnotationTest2 extends TestCase {

    public void test_codec() throws Exception {
        User user = new User();
        user.setId(1001);
        user.setName("bob.panl");
        user.setDescrition("大黄牛");


            

Reported by PMD.

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

Line: 22

              
        User user1 = JSON.parseObject(text, User.class);

        Assert.assertEquals(user1.getId(), user.getId());
        Assert.assertEquals(user1.getName(), user.getName());
    }

    public static class User {


            

Reported by PMD.

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

Line: 23

                      User user1 = JSON.parseObject(text, User.class);

        Assert.assertEquals(user1.getId(), user.getId());
        Assert.assertEquals(user1.getName(), user.getName());
    }

    public static class User {

        @JSONField(name = "ID")

            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals(user1.getName(), user.getName());
    }

    public static class User {

        @JSONField(name = "ID")
        private int    id;
        private String name;
        private String descrition;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue87.java
5 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 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 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 Set<String> set = new HashSet<String>(0);

            

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 Set<String> set = new HashSet<String>(0);

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/SimplePropertyPreFilter.java
5 issues
The class 'SimplePropertyPreFilter' is suspected to be a Data Class (WOC=12.500%, NOPA=0, NOAM=5, WMC=17)
Design

Line: 21

               * See the License for the specific language governing permissions and
 * limitations under the License.
 */
public class SimplePropertyPreFilter implements PropertyPreFilter {

    private final Class<?>    clazz;
    private final Set<String> includes = new HashSet<String>();
    private final Set<String> excludes = new HashSet<String>();
    private int               maxLevel = 0;

            

Reported by PMD.

Avoid using redundant field initializer for 'maxLevel'
Performance

Line: 26

                  private final Class<?>    clazz;
    private final Set<String> includes = new HashSet<String>();
    private final Set<String> excludes = new HashSet<String>();
    private int               maxLevel = 0;

    public SimplePropertyPreFilter(String... properties){
        this(null, properties);
    }


            

Reported by PMD.

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

Line: 93

                          }
        }

        return includes.size() == 0
                || includes.contains(name);
    }

}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'level' (lines '82'-'95').
Error

Line: 82

                      }
        
        if (maxLevel > 0) {
            int level = 0;
            SerialContext context = serializer.context;
            while (context != null) {
                level++;
                if (level > maxLevel) {
                    return false;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'level' (lines '82'-'85').
Error

Line: 82

                      }
        
        if (maxLevel > 0) {
            int level = 0;
            SerialContext context = serializer.context;
            while (context != null) {
                level++;
                if (level > maxLevel) {
                    return false;

            

Reported by PMD.

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

Line: 18

                      user.setDescrition("大黄牛");

        String text = JSON.toJSONString(user);
        System.out.println(text);

        User user1 = JSON.parseObject(text, User.class);

        Assert.assertEquals(user1.getId(), user.getId());
        Assert.assertEquals(user1.getName(), user.getName());

            

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

              
public class AnnotationTest extends TestCase {

    public void test_codec() throws Exception {
        User user = new User();
        user.setId(1001);
        user.setName("bob.panl");
        user.setDescrition("大黄牛");


            

Reported by PMD.

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

Line: 22

              
        User user1 = JSON.parseObject(text, User.class);

        Assert.assertEquals(user1.getId(), user.getId());
        Assert.assertEquals(user1.getName(), user.getName());
    }

    public static class User {


            

Reported by PMD.

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

Line: 23

                      User user1 = JSON.parseObject(text, User.class);

        Assert.assertEquals(user1.getId(), user.getId());
        Assert.assertEquals(user1.getName(), user.getName());
    }

    public static class User {

        private int    id;

            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals(user1.getName(), user.getName());
    }

    public static class User {

        private int    id;
        private String name;
        private String descrition;


            

Reported by PMD.

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

Line: 33

                      String jsonString = jsonObject.toJSONString();
        String text = "{\"scheduleAlarmRules\":[]}";
        Object jsonValue = JSON.parse(text);
        System.out.println(jsonValue);
    }

}

            

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

              
public class JSONParseTest extends TestCase {

    public void test_0() throws Exception {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("scheduleAlarmRules", new ArrayList());
        String jsonString = jsonObject.toJSONString();
        String text = "{\"scheduleAlarmRules\":[]}";
        Object jsonValue = JSON.parse(text);

            

Reported by PMD.

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

Line: 27

              
public class JSONParseTest extends TestCase {

    public void test_0() throws Exception {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("scheduleAlarmRules", new ArrayList());
        String jsonString = jsonObject.toJSONString();
        String text = "{\"scheduleAlarmRules\":[]}";
        Object jsonValue = JSON.parse(text);

            

Reported by PMD.

Avoid unused local variables such as 'jsonString'.
Design

Line: 30

                  public void test_0() throws Exception {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("scheduleAlarmRules", new ArrayList());
        String jsonString = jsonObject.toJSONString();
        String text = "{\"scheduleAlarmRules\":[]}";
        Object jsonValue = JSON.parse(text);
        System.out.println(jsonValue);
    }


            

Reported by PMD.

Found 'DU'-anomaly for variable 'jsonString' (lines '30'-'34').
Error

Line: 30

                  public void test_0() throws Exception {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("scheduleAlarmRules", new ArrayList());
        String jsonString = jsonObject.toJSONString();
        String text = "{\"scheduleAlarmRules\":[]}";
        Object jsonValue = JSON.parse(text);
        System.out.println(jsonValue);
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/StringDeserializerTest.java
5 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

              
public class StringDeserializerTest extends TestCase {

    public void test_0() throws Exception {
        Assert.assertEquals("123", JSON.parseObject("123", String.class));
        Assert.assertEquals("true", JSON.parseObject("true", String.class));
        Assert.assertEquals(null, JSON.parseObject("null", String.class));
    }


            

Reported by PMD.

The String literal '123' appears 6 times in this file; the first occurrence is on line 11
Error

Line: 11

              public class StringDeserializerTest extends TestCase {

    public void test_0() throws Exception {
        Assert.assertEquals("123", JSON.parseObject("123", String.class));
        Assert.assertEquals("true", JSON.parseObject("true", String.class));
        Assert.assertEquals(null, JSON.parseObject("null", String.class));
    }

    public void test_StringBuffer() throws Exception {

            

Reported by PMD.

The String literal 'true' appears 6 times in this file; the first occurrence is on line 12
Error

Line: 12

              
    public void test_0() throws Exception {
        Assert.assertEquals("123", JSON.parseObject("123", String.class));
        Assert.assertEquals("true", JSON.parseObject("true", String.class));
        Assert.assertEquals(null, JSON.parseObject("null", String.class));
    }

    public void test_StringBuffer() throws Exception {
        Assert.assertTrue(equals(new StringBuffer("123"), JSON.parseObject("123", StringBuffer.class)));

            

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

                      Assert.assertEquals(null, JSON.parseObject("null", String.class));
    }

    public void test_StringBuffer() throws Exception {
        Assert.assertTrue(equals(new StringBuffer("123"), JSON.parseObject("123", StringBuffer.class)));
        Assert.assertTrue(equals(new StringBuffer("true"), JSON.parseObject("true", StringBuffer.class)));
        Assert.assertEquals(null, JSON.parseObject("null", StringBuffer.class));
    }


            

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

                      Assert.assertEquals(null, JSON.parseObject("null", StringBuffer.class));
    }

    public void test_StringBuilder() throws Exception {
        Assert.assertTrue(equals(new StringBuilder("123"), JSON.parseObject("123", StringBuilder.class)));
        Assert.assertTrue(equals(new StringBuilder("true"), JSON.parseObject("true", StringBuilder.class)));
        Assert.assertEquals(null, JSON.parseObject("null", StringBuilder.class));
    }


            

Reported by PMD.

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

Line: 14

              
public class ListFieldTest3 extends TestCase {

	public void test_typeRef() throws Exception {
		String text = "{\"images\":[],\"media\":{\"width\":640}}";

		MediaContent object = JSON.parseObject(text, MediaContent.class);
	}


            

Reported by PMD.

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

Line: 14

              
public class ListFieldTest3 extends TestCase {

	public void test_typeRef() throws Exception {
		String text = "{\"images\":[],\"media\":{\"width\":640}}";

		MediaContent object = JSON.parseObject(text, MediaContent.class);
	}


            

Reported by PMD.

Avoid unused local variables such as 'object'.
Design

Line: 17

              	public void test_typeRef() throws Exception {
		String text = "{\"images\":[],\"media\":{\"width\":640}}";

		MediaContent object = JSON.parseObject(text, MediaContent.class);
	}

	public static class Root {
		private List<Image> images = new ArrayList<Image>();
		private Entity media;

            

Reported by PMD.

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

Line: 20

              		MediaContent object = JSON.parseObject(text, MediaContent.class);
	}

	public static class Root {
		private List<Image> images = new ArrayList<Image>();
		private Entity media;

		public List<Image> getImages() {
			return images;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'object' (lines '17'-'18').
Error

Line: 17

              	public void test_typeRef() throws Exception {
		String text = "{\"images\":[],\"media\":{\"width\":640}}";

		MediaContent object = JSON.parseObject(text, MediaContent.class);
	}

	public static class Root {
		private List<Image> images = new ArrayList<Image>();
		private Entity media;

            

Reported by PMD.