The following issues were found

src/test/java/com/alibaba/fastjson/deserializer/issue3050/TestIssue3050.java
4 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 21

                  public void testIssue3050() {
        String jsonStr = "{\"name\":5, \"address\":\"beijing\", \"id\":\"100\", \"age\":10}";
        Person person = JSON.parseObject(jsonStr, Person.class, Feature.InitStringFieldAsEmpty);
        Assert.assertEquals("5", person.getName());
        Assert.assertEquals("beijing", person.getAddress());
        Assert.assertEquals("100", person.getId());
        Assert.assertEquals(10, person.getAge());
    }


            

Reported by PMD.

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

Line: 22

                      String jsonStr = "{\"name\":5, \"address\":\"beijing\", \"id\":\"100\", \"age\":10}";
        Person person = JSON.parseObject(jsonStr, Person.class, Feature.InitStringFieldAsEmpty);
        Assert.assertEquals("5", person.getName());
        Assert.assertEquals("beijing", person.getAddress());
        Assert.assertEquals("100", person.getId());
        Assert.assertEquals(10, person.getAge());
    }

}

            

Reported by PMD.

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

Line: 23

                      Person person = JSON.parseObject(jsonStr, Person.class, Feature.InitStringFieldAsEmpty);
        Assert.assertEquals("5", person.getName());
        Assert.assertEquals("beijing", person.getAddress());
        Assert.assertEquals("100", person.getId());
        Assert.assertEquals(10, person.getAge());
    }

}

            

Reported by PMD.

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

Line: 24

                      Assert.assertEquals("5", person.getName());
        Assert.assertEquals("beijing", person.getAddress());
        Assert.assertEquals("100", person.getId());
        Assert.assertEquals(10, person.getAge());
    }

}

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/parser/deserializer/PropertyProcessableDeserializer.java
4 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 13

               * Created by wenshao on 15/07/2017.
 */
public class PropertyProcessableDeserializer implements ObjectDeserializer {
    public final Class<PropertyProcessable> type;

    public PropertyProcessableDeserializer(Class<PropertyProcessable> type) {
        this.type = type;
    }


            

Reported by PMD.

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

Line: 23

                      PropertyProcessable processable;
        try {
            processable = this.type.newInstance();
        } catch (Exception e) {
            throw new JSONException("craete instance error");
        }

        Object object =parser.parse(processable, fieldName);


            

Reported by PMD.

New exception is thrown in catch block, original stack trace may be lost
Design

Line: 24

                      try {
            processable = this.type.newInstance();
        } catch (Exception e) {
            throw new JSONException("craete instance error");
        }

        Object object =parser.parse(processable, fieldName);

        return (T) object;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'processable' (lines '22'-'30').
Error

Line: 22

                  public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        PropertyProcessable processable;
        try {
            processable = this.type.newInstance();
        } catch (Exception e) {
            throw new JSONException("craete instance error");
        }

        Object object =parser.parse(processable, fieldName);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/TestDeprecate.java
4 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: 9

              
public class TestDeprecate extends TestCase {

    public void test_0() throws Exception {
        VO vo = new VO();
        vo.setId(123);

        String text = JSON.toJSONString(vo);
    }

            

Reported by PMD.

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

Line: 9

              
public class TestDeprecate extends TestCase {

    public void test_0() throws Exception {
        VO vo = new VO();
        vo.setId(123);

        String text = JSON.toJSONString(vo);
    }

            

Reported by PMD.

Avoid unused local variables such as 'text'.
Design

Line: 13

                      VO vo = new VO();
        vo.setId(123);

        String text = JSON.toJSONString(vo);
    }

    public static class VO {

        private int id;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'text' (lines '13'-'14').
Error

Line: 13

                      VO vo = new VO();
        vo.setId(123);

        String text = JSON.toJSONString(vo);
    }

    public static class VO {

        private int id;

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/parser/JSONToken.java
4 issues
The class 'JSONToken' has a Standard Cyclomatic Complexity of 28 (Highest = 27).
Design

Line: 21

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONToken {

    //
    public final static int ERROR                = 1;
    //
    public final static int LITERAL_INT          = 2;

            

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

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONToken {

    //
    public final static int ERROR                = 1;
    //
    public final static int LITERAL_INT          = 2;

            

Reported by PMD.

The method 'name' has a Standard Cyclomatic Complexity of 27.
Design

Line: 73

                  public final static int DOT                  = 25;
    public final static int HEX                  = 26;

    public static String name(int value) {
        switch (value) {
            case ERROR:
                return "error";
            case LITERAL_INT:
                return "int";

            

Reported by PMD.

The method 'name(int)' has a cyclomatic complexity of 27.
Design

Line: 73

                  public final static int DOT                  = 25;
    public final static int HEX                  = 26;

    public static String name(int value) {
        switch (value) {
            case ERROR:
                return "error";
            case LITERAL_INT:
                return "int";

            

Reported by PMD.

src/test/java/com/alibaba/fastjson/serializer/issue3479/TestIssue3479.java
4 issues
System.out.println is used
Design

Line: 69

                      dog.dogName = "dog1001";

        String text = JSON.toJSONString(dog, SerializerFeature.WriteClassName);
        System.out.println(text);

        Dog dog2 = (Dog) JSON.parseObject(text, Animal.class);

        System.out.println(dog2);
    }

            

Reported by PMD.

System.out.println is used
Design

Line: 73

              
        Dog dog2 = (Dog) JSON.parseObject(text, Animal.class);

        System.out.println(dog2);
    }

}

            

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

              import com.alibaba.fastjson.annotation.JSONType;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class TestIssue3479 {

    @JSONType(seeAlso = {Dog.class, Cat.class}, typeKey = "typeKey")
    public static abstract class Animal {

        private String typeKey;

            

Reported by PMD.

This abstract class does not have any abstract methods
Design

Line: 10

              public class TestIssue3479 {

    @JSONType(seeAlso = {Dog.class, Cat.class}, typeKey = "typeKey")
    public static abstract class Animal {

        private String typeKey;

        public String getTypeKey() {
            return typeKey;

            

Reported by PMD.

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

Line: 20

                      map.put("self", map);

        String text = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        System.out.println(text);
        Assert.assertEquals("{\"@type\":\"java.util.HashMap\",\"self\":{\"$ref\":\"@\"}}",
                            text);

        Map<String, Object> entity2 = (Map<String, Object>) JSON.parse(text);
        Assert.assertEquals(map.getClass(), entity2.getClass());

            

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

    @SuppressWarnings("unchecked")
	public void test_self() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("self", map);

        String text = JSON.toJSONString(map, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 25

                                          text);

        Map<String, Object> entity2 = (Map<String, Object>) JSON.parse(text);
        Assert.assertEquals(map.getClass(), entity2.getClass());
        Assert.assertSame(entity2, entity2.get("self"));
    }
    

}

            

Reported by PMD.

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

Line: 26

              
        Map<String, Object> entity2 = (Map<String, Object>) JSON.parse(text);
        Assert.assertEquals(map.getClass(), entity2.getClass());
        Assert.assertSame(entity2, entity2.get("self"));
    }
    

}

            

Reported by PMD.

src/test/java/com/alibaba/fastjson/deserializer/issues3796/bean/ObjectA.java
4 issues
This class has a bunch of public methods and attributes
Design

Line: 1

              package com.alibaba.fastjson.deserializer.issues3796.bean;



public class ObjectA {

    private static final String NULL = "NULL";
    
    private String a = NULL;

            

Reported by PMD.

The class 'ObjectA' is suspected to be a Data Class (WOC=2.222%, NOPA=0, NOAM=44, WMC=45)
Design

Line: 5

              


public class ObjectA {

    private static final String NULL = "NULL";
    
    private String a = NULL;


            

Reported by PMD.

Too many fields
Design

Line: 5

              


public class ObjectA {

    private static final String NULL = "NULL";
    
    private String a = NULL;


            

Reported by PMD.

The String literal 'NULL' appears 5 times in this file; the first occurrence is on line 7
Error

Line: 7

              
public class ObjectA {

    private static final String NULL = "NULL";
    
    private String a = NULL;

    private String b = NULL;


            

Reported by PMD.

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

Line: 17

              
        String text = JSON.toJSONString(user);
        
        System.out.println(text);
        
        JSON.parseObject(text, User.class);
    }

    public static class User implements Serializable {

            

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

              import com.alibaba.fastjson.JSON;

public class Bug_for_jared1 extends TestCase {
    public void test_for_jared1() throws Exception {
        User user = new User();

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

            

Reported by PMD.

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

Line: 12

              import com.alibaba.fastjson.JSON;

public class Bug_for_jared1 extends TestCase {
    public void test_for_jared1() throws Exception {
        User user = new User();

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

            

Reported by PMD.

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

Line: 22

                      JSON.parseObject(text, User.class);
    }

    public static class User implements Serializable {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

            

Reported by PMD.

src/test/java/com/alibaba/fastjson/deserializer/javabean/ConvertDO.java
4 issues
Too many fields
Design

Line: 24

              @Data
@NoArgsConstructor
@AllArgsConstructor
public class ConvertDO implements Serializable {

    private static final long serialVersionUID = 3987648902475498726L;

    private int inta;
    private Integer intb;

            

Reported by PMD.

Avoid unused imports such as 'java.time.LocalDate'
Design

Line: 10

              import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

            

Reported by PMD.

Avoid unused imports such as 'java.time.LocalDateTime'
Design

Line: 11

              
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;
import java.util.Map;


            

Reported by PMD.

Avoid unused imports such as 'java.time.LocalTime'
Design

Line: 12

              import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**

            

Reported by PMD.

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

Line: 13

              
public class JSONObjectTest_getBigInteger extends TestCase {

    public void test_get_float() throws Exception {
        JSONObject obj = new JSONObject();
        obj.put("value", 123.45F);
        Assert.assertTrue(123.45F == ((Float) obj.get("value")).floatValue());
        Assert.assertEquals(new BigInteger("123"), obj.getBigInteger("value"));
    }

            

Reported by PMD.

The String literal 'value' appears 9 times in this file; the first occurrence is on line 15
Error

Line: 15

              
    public void test_get_float() throws Exception {
        JSONObject obj = new JSONObject();
        obj.put("value", 123.45F);
        Assert.assertTrue(123.45F == ((Float) obj.get("value")).floatValue());
        Assert.assertEquals(new BigInteger("123"), obj.getBigInteger("value"));
    }
    
    public void test_get_double() throws Exception {

            

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

                      Assert.assertEquals(new BigInteger("123"), obj.getBigInteger("value"));
    }
    
    public void test_get_double() throws Exception {
        JSONObject obj = new JSONObject();
        obj.put("value", 123.45D);
        Assert.assertTrue(123.45D == ((Double) obj.get("value")).doubleValue());
        Assert.assertEquals(new BigInteger("123"), obj.getBigInteger("value"));
    }

            

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

                      Assert.assertEquals(new BigInteger("123"), obj.getBigInteger("value"));
    }
    
    public void test_get_empty() throws Exception {
        JSONObject obj = new JSONObject();
        obj.put("value", "");
        Assert.assertEquals("", obj.get("value"));
        Assert.assertNull(obj.getBigInteger("value"));
    }

            

Reported by PMD.