The following issues were found

src/main/java/com/alibaba/fastjson/util/IOUtils.java
142 issues
Avoid reassigning parameters such as 'i'
Design

Line: 213

                      return 19;
    }

    public static void getChars(long i, int index, char[] buf) {
        long q;
        int r;
        int charPos = index;
        char sign = 0;


            

Reported by PMD.

Avoid reassigning parameters such as 'i'
Design

Line: 213

                      return 19;
    }

    public static void getChars(long i, int index, char[] buf) {
        long q;
        int r;
        int charPos = index;
        char sign = 0;


            

Reported by PMD.

Avoid reassigning parameters such as 'i'
Design

Line: 265

                   * buffer backwards starting with the least significant digit at the specified index (exclusive), and working
     * backwards from there. Will fail if i == Integer.MIN_VALUE
     */
    public static void getChars(int i, int index, char[] buf) {
        int q, r, p = index;
        char sign = 0;

        if (i < 0) {
            sign = '-';

            

Reported by PMD.

Avoid reassigning parameters such as 'i'
Design

Line: 265

                   * buffer backwards starting with the least significant digit at the specified index (exclusive), and working
     * backwards from there. Will fail if i == Integer.MIN_VALUE
     */
    public static void getChars(int i, int index, char[] buf) {
        int q, r, p = index;
        char sign = 0;

        if (i < 0) {
            sign = '-';

            

Reported by PMD.

Avoid reassigning parameters such as 'i'
Design

Line: 265

                   * buffer backwards starting with the least significant digit at the specified index (exclusive), and working
     * backwards from there. Will fail if i == Integer.MIN_VALUE
     */
    public static void getChars(int i, int index, char[] buf) {
        int q, r, p = index;
        char sign = 0;

        if (i < 0) {
            sign = '-';

            

Reported by PMD.

Avoid reassigning parameters such as 'offset'
Design

Line: 585

                      return dArr;
    }
    
    public static int encodeUTF8(char[] chars, int offset, int len, byte[] bytes) {
        int sl = offset + len;
        int dp = 0;
        int dlASCII = dp + Math.min(len, bytes.length);

        // ASCII only optimized loop

            

Reported by PMD.

Avoid reassigning parameters such as 'offset'
Design

Line: 585

                      return dArr;
    }
    
    public static int encodeUTF8(char[] chars, int offset, int len, byte[] bytes) {
        int sl = offset + len;
        int dp = 0;
        int dlASCII = dp + Math.min(len, bytes.length);

        // ASCII only optimized loop

            

Reported by PMD.

Avoid reassigning parameters such as 'offset'
Design

Line: 585

                      return dArr;
    }
    
    public static int encodeUTF8(char[] chars, int offset, int len, byte[] bytes) {
        int sl = offset + len;
        int dp = 0;
        int dlASCII = dp + Math.min(len, bytes.length);

        // ASCII only optimized loop

            

Reported by PMD.

Avoid reassigning parameters such as 'sp'
Design

Line: 654

                  /**
     * @deprecated
     */
    public static int decodeUTF8(byte[] sa, int sp, int len, char[] da) {
        final int sl = sp + len;
        int dp = 0;
        int dlASCII = Math.min(len, da.length);

        // ASCII only optimized loop

            

Reported by PMD.

Avoid reassigning parameters such as 'sp'
Design

Line: 654

                  /**
     * @deprecated
     */
    public static int decodeUTF8(byte[] sa, int sp, int len, char[] da) {
        final int sl = sp + len;
        int dp = 0;
        int dlASCII = Math.min(len, da.length);

        // ASCII only optimized loop

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/util/FieldInfo.java
124 issues
Overridable method 'genFieldNameChars' called during object construction
Error

Line: 86

                          fieldAccess = false;
        }
        
        name_chars = genFieldNameChars();

        if (field != null) {
            TypeUtils.setAccessible(field);
        }
        

            

Reported by PMD.

Overridable method 'getAnnotation' called during object construction
Error

Line: 168

                      }
        
        String format = null;
        JSONField annotation = getAnnotation();

        nameHashCode = nameHashCode64(name, annotation);

        boolean jsonDirect = false;
        if (annotation != null) {

            

Reported by PMD.

Overridable method 'genFieldNameChars' called during object construction
Error

Line: 189

                      }
        this.format = format;
        
        name_chars = genFieldNameChars();

        if (method != null) {
            TypeUtils.setAccessible(method);
        }


            

Reported by PMD.

Avoid reassigning parameters such as 'ordinal'
Design

Line: 58

                                   Class<?> fieldClass, // 
                     Type fieldType, // 
                     Field field, // 
                     int ordinal, // 
                     int serialzeFeatures, // 
                     int parserFeatures){
        if (ordinal < 0) {
            ordinal = 0;
        }

            

Reported by PMD.

Avoid reassigning parameters such as 'name'
Design

Line: 119

                              fieldAnnotation, methodAnnotation, label, null);
    }

    public FieldInfo(String name, //
                     Method method, //
                     Field field, //
                     Class<?> clazz, //
                     Type type, //
                     int ordinal, //

            

Reported by PMD.

Avoid reassigning parameters such as 'ordinal'
Design

Line: 124

                                   Field field, //
                     Class<?> clazz, //
                     Type type, //
                     int ordinal, //
                     int serialzeFeatures, //
                     int parserFeatures, //
                     JSONField fieldAnnotation, //
                     JSONField methodAnnotation, //
                     String label,

            

Reported by PMD.

Avoid reassigning parameters such as 'fieldType'
Design

Line: 296

                      return getFieldType(clazz, type, fieldType, null);
    }

    public static Type getFieldType(final Class<?> clazz, final Type type, Type fieldType, Map<TypeVariable, Type> genericInfo) {
        if (clazz == null || type == null) {
            return fieldType;
        }

        if (fieldType instanceof GenericArrayType) {

            

Reported by PMD.

Avoid reassigning parameters such as 'fieldType'
Design

Line: 296

                      return getFieldType(clazz, type, fieldType, null);
    }

    public static Type getFieldType(final Class<?> clazz, final Type type, Type fieldType, Map<TypeVariable, Type> genericInfo) {
        if (clazz == null || type == null) {
            return fieldType;
        }

        if (fieldType instanceof GenericArrayType) {

            

Reported by PMD.

Too many fields
Design

Line: 20

              import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField;

public class FieldInfo implements Comparable<FieldInfo> {

    public final String     name;
    public final Method     method;
    public final Field      field;


            

Reported by PMD.

The class 'FieldInfo' has a Standard Cyclomatic Complexity of 5 (Highest = 20).
Design

Line: 20

              import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField;

public class FieldInfo implements Comparable<FieldInfo> {

    public final String     name;
    public final Method     method;
    public final Field      field;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/JSONFieldDefaultValueTest.java
119 issues
Do not use the short type
Performance

Line: 65

              		@JSONField(defaultValue = "888") //shouldn't work
		private int anInt;
		@JSONField(defaultValue = "88") //shouldn't work
		private short aShort;
		@JSONField(defaultValue = "J") //shouldn't work
		private char aChar;
		@JSONField(defaultValue = "8") //shouldn't work
		private byte aByte;
		@JSONField(defaultValue = "8888") //shouldn't work

            

Reported by PMD.

Do not use the short type
Performance

Line: 144

              			this.anInt = anInt;
		}

		public short getaShort() {
			return aShort;
		}

		public void setaShort(short aShort) {
			this.aShort = aShort;

            

Reported by PMD.

Do not use the short type
Performance

Line: 148

              			return aShort;
		}

		public void setaShort(short aShort) {
			this.aShort = aShort;
		}

		public char getaChar() {
			return aChar;

            

Reported by PMD.

System.out.println is used
Design

Line: 11

              	public void test_default_value() throws Exception {
		Model m = new Model();
		String s = JSON.toJSONString(m);
		System.out.println(s);
		Model m2 = JSON.parseObject(s, Model.class);
		assertEquals("string", m2.getString());
		assertEquals(false, m2.getaBoolean());
		assertEquals(true, m2.getaBoolean2().booleanValue());
		assertEquals(0, m2.getAnInt());

            

Reported by PMD.

System.out.println is used
Design

Line: 35

              	public void test_not_null() throws Exception {
		Model m = new Model("test", true, 888, (short)88, 'J', (byte)8, 8888L, 8.8F, 88.88, false, 999, (short)99, 'C', (byte)9, 9999L, 9.9F, 99.99);
		String s = JSON.toJSONString(m);
		System.out.println(s);
		Model m2 = JSON.parseObject(s, Model.class);
		assertEquals("test", m2.getString());
		assertEquals(true, m2.getaBoolean());
		assertEquals(false, m2.getaBoolean2().booleanValue());
		assertEquals(888, m2.getAnInt());

            

Reported by PMD.

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

Line: 8

              import junit.framework.TestCase;

public class JSONFieldDefaultValueTest extends TestCase {
	public void test_default_value() throws Exception {
		Model m = new Model();
		String s = JSON.toJSONString(m);
		System.out.println(s);
		Model m2 = JSON.parseObject(s, Model.class);
		assertEquals("string", m2.getString());

            

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

              import junit.framework.TestCase;

public class JSONFieldDefaultValueTest extends TestCase {
	public void test_default_value() throws Exception {
		Model m = new Model();
		String s = JSON.toJSONString(m);
		System.out.println(s);
		Model m2 = JSON.parseObject(s, Model.class);
		assertEquals("string", m2.getString());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

              		String s = JSON.toJSONString(m);
		System.out.println(s);
		Model m2 = JSON.parseObject(s, Model.class);
		assertEquals("string", m2.getString());
		assertEquals(false, m2.getaBoolean());
		assertEquals(true, m2.getaBoolean2().booleanValue());
		assertEquals(0, m2.getAnInt());
		assertEquals(888, m2.getInteger().intValue());
		assertEquals(0, m2.getaShort());

            

Reported by PMD.

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

Line: 13

              		String s = JSON.toJSONString(m);
		System.out.println(s);
		Model m2 = JSON.parseObject(s, Model.class);
		assertEquals("string", m2.getString());
		assertEquals(false, m2.getaBoolean());
		assertEquals(true, m2.getaBoolean2().booleanValue());
		assertEquals(0, m2.getAnInt());
		assertEquals(888, m2.getInteger().intValue());
		assertEquals(0, m2.getaShort());

            

Reported by PMD.

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

Line: 14

              		System.out.println(s);
		Model m2 = JSON.parseObject(s, Model.class);
		assertEquals("string", m2.getString());
		assertEquals(false, m2.getaBoolean());
		assertEquals(true, m2.getaBoolean2().booleanValue());
		assertEquals(0, m2.getAnInt());
		assertEquals(888, m2.getInteger().intValue());
		assertEquals(0, m2.getaShort());
		assertEquals(88, m2.getaShort2().shortValue());

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/JavaBeanSerializer.java
117 issues
Overridable method 'getFieldSerializer' called during object construction
Error

Line: 101

                          getters = new FieldSerializer[beanInfo.fields.length];
            boolean hashNotMatch = false;
            for (int i = 0; i < getters.length; ++i) {
                FieldSerializer fieldSerializer = getFieldSerializer(beanInfo.fields[i].name);
                if (fieldSerializer == null) {
                    hashNotMatch = true;
                    break;
                }
                getters[i] = fieldSerializer;

            

Reported by PMD.

Avoid reassigning parameters such as 'typeKey'
Design

Line: 547

                      }
    }

    protected void writeClassName(JSONSerializer serializer, String typeKey, Object object) {
        if (typeKey == null) {
            typeKey = serializer.config.typeKey;
        }
        serializer.out.writeFieldName(typeKey, false);
        String typeName = this.beanInfo.typeName;

            

Reported by PMD.

Avoid reassigning parameters such as 'seperator'
Design

Line: 815

                  }
    
    protected char writeBefore(JSONSerializer jsonBeanDeser, //
                            Object object, char seperator) {
        
        if (jsonBeanDeser.beforeFilters != null) {
            for (BeforeFilter beforeFilter : jsonBeanDeser.beforeFilters) {
                seperator = beforeFilter.writeBefore(jsonBeanDeser, object, seperator);
            }

            

Reported by PMD.

Avoid reassigning parameters such as 'seperator'
Design

Line: 815

                  }
    
    protected char writeBefore(JSONSerializer jsonBeanDeser, //
                            Object object, char seperator) {
        
        if (jsonBeanDeser.beforeFilters != null) {
            for (BeforeFilter beforeFilter : jsonBeanDeser.beforeFilters) {
                seperator = beforeFilter.writeBefore(jsonBeanDeser, object, seperator);
            }

            

Reported by PMD.

Avoid reassigning parameters such as 'seperator'
Design

Line: 833

                  }
    
    protected char writeAfter(JSONSerializer jsonBeanDeser, // 
                           Object object, char seperator) {
        if (jsonBeanDeser.afterFilters != null) {
            for (AfterFilter afterFilter : jsonBeanDeser.afterFilters) {
                seperator = afterFilter.writeAfter(jsonBeanDeser, object, seperator);
            }
        }

            

Reported by PMD.

Avoid reassigning parameters such as 'seperator'
Design

Line: 833

                  }
    
    protected char writeAfter(JSONSerializer jsonBeanDeser, // 
                           Object object, char seperator) {
        if (jsonBeanDeser.afterFilters != null) {
            for (AfterFilter afterFilter : jsonBeanDeser.afterFilters) {
                seperator = afterFilter.writeAfter(jsonBeanDeser, object, seperator);
            }
        }

            

Reported by PMD.

The class 'JavaBeanSerializer' has a total cyclomatic complexity of 251 (highest 146).
Design

Line: 45

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JavaBeanSerializer extends SerializeFilterable implements ObjectSerializer {
    // serializers
    protected final FieldSerializer[] getters;
    protected final FieldSerializer[] sortedGetters;
    
    protected final SerializeBeanInfo  beanInfo;

            

Reported by PMD.

Possible God Class (WMC=251, ATFD=190, TCC=13.105%)
Design

Line: 45

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JavaBeanSerializer extends SerializeFilterable implements ObjectSerializer {
    // serializers
    protected final FieldSerializer[] getters;
    protected final FieldSerializer[] sortedGetters;
    
    protected final SerializeBeanInfo  beanInfo;

            

Reported by PMD.

The class 'JavaBeanSerializer' has a Modified Cyclomatic Complexity of 6 (Highest = 91).
Design

Line: 45

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JavaBeanSerializer extends SerializeFilterable implements ObjectSerializer {
    // serializers
    protected final FieldSerializer[] getters;
    protected final FieldSerializer[] sortedGetters;
    
    protected final SerializeBeanInfo  beanInfo;

            

Reported by PMD.

The class 'JavaBeanSerializer' has a Standard Cyclomatic Complexity of 6 (Highest = 91).
Design

Line: 45

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JavaBeanSerializer extends SerializeFilterable implements ObjectSerializer {
    // serializers
    protected final FieldSerializer[] getters;
    protected final FieldSerializer[] sortedGetters;
    
    protected final SerializeBeanInfo  beanInfo;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/date/DateFieldTest9.java
111 issues
This class has too many methods, consider refactoring it.
Design

Line: 14

              
import junit.framework.TestCase;

public class DateFieldTest9 extends TestCase {

    protected void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
        JSON.defaultLocale = Locale.CHINA;
    }

            

Reported by PMD.

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

Line: 16

              
public class DateFieldTest9 extends TestCase {

    protected void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
        JSON.defaultLocale = Locale.CHINA;
    }

    public void test_tw() 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: 21

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_tw() throws Exception {
        Entity vo = JSON.parseObject("{\"date\":\"2016/05/06\"}", Entity.class);

        Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);
        calendar.setTime(vo.date);
        Assert.assertEquals(2016, calendar.get(Calendar.YEAR));

            

Reported by PMD.

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

Line: 25

                      Entity vo = JSON.parseObject("{\"date\":\"2016/05/06\"}", Entity.class);

        Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);
        calendar.setTime(vo.date);
        Assert.assertEquals(2016, calendar.get(Calendar.YEAR));
        Assert.assertEquals(4, calendar.get(Calendar.MONTH));
        Assert.assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
        Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
        Assert.assertEquals(0, calendar.get(Calendar.MINUTE));

            

Reported by PMD.

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

Line: 26

              
        Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);
        calendar.setTime(vo.date);
        Assert.assertEquals(2016, calendar.get(Calendar.YEAR));
        Assert.assertEquals(4, calendar.get(Calendar.MONTH));
        Assert.assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
        Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
        Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
        Assert.assertEquals(0, calendar.get(Calendar.SECOND));

            

Reported by PMD.

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

Line: 27

                      Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);
        calendar.setTime(vo.date);
        Assert.assertEquals(2016, calendar.get(Calendar.YEAR));
        Assert.assertEquals(4, calendar.get(Calendar.MONTH));
        Assert.assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
        Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
        Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
        Assert.assertEquals(0, calendar.get(Calendar.SECOND));
        Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));

            

Reported by PMD.

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

Line: 28

                      calendar.setTime(vo.date);
        Assert.assertEquals(2016, calendar.get(Calendar.YEAR));
        Assert.assertEquals(4, calendar.get(Calendar.MONTH));
        Assert.assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
        Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
        Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
        Assert.assertEquals(0, calendar.get(Calendar.SECOND));
        Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));
    }

            

Reported by PMD.

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

Line: 29

                      Assert.assertEquals(2016, calendar.get(Calendar.YEAR));
        Assert.assertEquals(4, calendar.get(Calendar.MONTH));
        Assert.assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
        Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
        Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
        Assert.assertEquals(0, calendar.get(Calendar.SECOND));
        Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));
    }
    

            

Reported by PMD.

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

Line: 30

                      Assert.assertEquals(4, calendar.get(Calendar.MONTH));
        Assert.assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
        Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
        Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
        Assert.assertEquals(0, calendar.get(Calendar.SECOND));
        Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));
    }
    
    public void test_cn() throws Exception {

            

Reported by PMD.

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

Line: 31

                      Assert.assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
        Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
        Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
        Assert.assertEquals(0, calendar.get(Calendar.SECOND));
        Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));
    }
    
    public void test_cn() throws Exception {
        Entity vo = JSON.parseObject("{\"date\":\"2016-05-06\"}", Entity.class);

            

Reported by PMD.

src/test/java/com/alibaba/json/test/performance/JacksonGroupParser.java
111 issues
Avoid throwing raw exception types.
Design

Line: 50

                              } else if ("companies" == name) {
                    parseCompany(group.getCompanies());
                } else {
                    throw new RuntimeException("not match property : " + name);
                }
            }
        }

        accept(JsonToken.END_OBJECT);

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 87

                              } else if ("rootDepartment" == name) {
                    company.setRootDepartment(parseDepartment());
                } else {
                    throw new RuntimeException("not match property : " + name);
                }
            }
        }

        accept(JsonToken.END_OBJECT);

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 124

                              } else if ("members" == name) {
                    parseEmployee(company.getMembers());
                } else {
                    throw new RuntimeException("not match property : " + name);
                }
            }
        }

        accept(JsonToken.END_OBJECT);

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 167

                              } else if ("badboy" == name) {
                    emp.setBadboy(acceptBoolean(tok));
                } else {
                    throw new RuntimeException("not match property : " + name);
                }
            }
        }

        accept(JsonToken.END_OBJECT);

            

Reported by PMD.

The class 'JacksonGroupParser' has a Modified Cyclomatic Complexity of 4 (Highest = 12).
Design

Line: 18

              import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

public class JacksonGroupParser {

    private JsonParser parser;

    public JacksonGroupParser(JsonParser parser) throws Exception{
        this.parser = parser;

            

Reported by PMD.

The class 'JacksonGroupParser' has a Standard Cyclomatic Complexity of 4 (Highest = 12).
Design

Line: 18

              import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

public class JacksonGroupParser {

    private JsonParser parser;

    public JacksonGroupParser(JsonParser parser) throws Exception{
        this.parser = parser;

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 18

              import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

public class JacksonGroupParser {

    private JsonParser parser;

    public JacksonGroupParser(JsonParser parser) throws Exception{
        this.parser = parser;

            

Reported by PMD.

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

Line: 20

              
public class JacksonGroupParser {

    private JsonParser parser;

    public JacksonGroupParser(JsonParser parser) throws Exception{
        this.parser = parser;
        parser.nextToken(); // move to the start of the
    }

            

Reported by PMD.

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

Line: 20

              
public class JacksonGroupParser {

    private JsonParser parser;

    public JacksonGroupParser(JsonParser parser) throws Exception{
        this.parser = parser;
        parser.nextToken(); // move to the start of the
    }

            

Reported by PMD.

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

Line: 22

              
    private JsonParser parser;

    public JacksonGroupParser(JsonParser parser) throws Exception{
        this.parser = parser;
        parser.nextToken(); // move to the start of the
    }

    public Group parseGroup() throws Exception {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/support/spring/mock/testcase/FastJsonHttpMessageConverterJSONPCaseTest.java
106 issues
This class has too many methods, consider refactoring it.
Design

Line: 37

              @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration
public class FastJsonHttpMessageConverterJSONPCaseTest {
    private static final MediaType APPLICATION_JAVASCRIPT = new MediaType("application", "javascript");

    @Autowired
    private WebApplicationContext wac;


            

Reported by PMD.

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

Line: 41

                  private static final MediaType APPLICATION_JAVASCRIPT = new MediaType("application", "javascript");

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @ComponentScan(basePackages = "com.alibaba.json.bvt.support.spring.mock.controller")
    @EnableWebMvc

            

Reported by PMD.

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

Line: 43

                  @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @ComponentScan(basePackages = "com.alibaba.json.bvt.support.spring.mock.controller")
    @EnableWebMvc
    @Configuration
    protected static class Config extends WebMvcConfigurerAdapter {

            

Reported by PMD.

The String literal 'UTF-8' appears 9 times in this file; the first occurrence is on line 70
Error

Line: 70

                  @Before
    public void setup() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) //
                .addFilter(new CharacterEncodingFilter("UTF-8", true)) // 设置服务器端返回的字符集为:UTF-8
                .build();
    }

    @Test
    public void isInjectComponent() {

            

Reported by PMD.

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

Line: 75

                  }

    @Test
    public void isInjectComponent() {
        wac.getBean(JSONPResponseBodyAdvice.class);
        wac.getBean(FastJsonViewResponseBodyAdvice.class);
    }

    @Test

            

Reported by PMD.

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

Line: 81

                  }

    @Test
    public void test1() throws Exception {
        mockMvc.perform(
                (post("/jsonp-fastjsonview/test1").characterEncoding("UTF-8")
                        .contentType(MediaType.APPLICATION_JSON))).andExpect(status().isOk()).andDo(print());
    }


            

Reported by PMD.

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

Line: 82

              
    @Test
    public void test1() throws Exception {
        mockMvc.perform(
                (post("/jsonp-fastjsonview/test1").characterEncoding("UTF-8")
                        .contentType(MediaType.APPLICATION_JSON))).andExpect(status().isOk()).andDo(print());
    }

    @Test

            

Reported by PMD.

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

Line: 82

              
    @Test
    public void test1() throws Exception {
        mockMvc.perform(
                (post("/jsonp-fastjsonview/test1").characterEncoding("UTF-8")
                        .contentType(MediaType.APPLICATION_JSON))).andExpect(status().isOk()).andDo(print());
    }

    @Test

            

Reported by PMD.

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

Line: 83

                  @Test
    public void test1() throws Exception {
        mockMvc.perform(
                (post("/jsonp-fastjsonview/test1").characterEncoding("UTF-8")
                        .contentType(MediaType.APPLICATION_JSON))).andExpect(status().isOk()).andDo(print());
    }

    @Test
    public void test1_2() throws Exception {

            

Reported by PMD.

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

Line: 83

                  @Test
    public void test1() throws Exception {
        mockMvc.perform(
                (post("/jsonp-fastjsonview/test1").characterEncoding("UTF-8")
                        .contentType(MediaType.APPLICATION_JSON))).andExpect(status().isOk()).andDo(print());
    }

    @Test
    public void test1_2() throws Exception {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/support/hsf/HSFJSONUtilsTest_1.java
103 issues
This class has too many methods, consider refactoring it.
Design

Line: 10

              import java.lang.reflect.Method;
import java.util.List;

public class HSFJSONUtilsTest_1 extends TestCase {
    private Method method_f2;
    private Method method_f3;
    private Method method_f4;
    private Method method_f5;
    private MethodLocator methodLocator;

            

Reported by PMD.

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

Line: 11

              import java.util.List;

public class HSFJSONUtilsTest_1 extends TestCase {
    private Method method_f2;
    private Method method_f3;
    private Method method_f4;
    private Method method_f5;
    private MethodLocator methodLocator;


            

Reported by PMD.

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

Line: 12

              
public class HSFJSONUtilsTest_1 extends TestCase {
    private Method method_f2;
    private Method method_f3;
    private Method method_f4;
    private Method method_f5;
    private MethodLocator methodLocator;

    protected void setUp() throws Exception {

            

Reported by PMD.

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

Line: 13

              public class HSFJSONUtilsTest_1 extends TestCase {
    private Method method_f2;
    private Method method_f3;
    private Method method_f4;
    private Method method_f5;
    private MethodLocator methodLocator;

    protected void setUp() throws Exception {
        method_f2 = Service.class.getMethod("f2", String.class, Model.class);

            

Reported by PMD.

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

Line: 14

                  private Method method_f2;
    private Method method_f3;
    private Method method_f4;
    private Method method_f5;
    private MethodLocator methodLocator;

    protected void setUp() throws Exception {
        method_f2 = Service.class.getMethod("f2", String.class, Model.class);
        method_f3 = Service.class.getMethod("f3", String.class, List.class);

            

Reported by PMD.

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

Line: 15

                  private Method method_f3;
    private Method method_f4;
    private Method method_f5;
    private MethodLocator methodLocator;

    protected void setUp() throws Exception {
        method_f2 = Service.class.getMethod("f2", String.class, Model.class);
        method_f3 = Service.class.getMethod("f3", String.class, List.class);
        method_f4 = Service.class.getMethod("f3", String.class, Model[].class);

            

Reported by PMD.

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

Line: 17

                  private Method method_f5;
    private MethodLocator methodLocator;

    protected void setUp() throws Exception {
        method_f2 = Service.class.getMethod("f2", String.class, Model.class);
        method_f3 = Service.class.getMethod("f3", String.class, List.class);
        method_f4 = Service.class.getMethod("f3", String.class, Model[].class);
        method_f5 = Service.class.getMethod("f3", int.class, long.class);


            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 29

                                  return null;
                }

                if (types[0].equals("int")) {
                    return method_f5;
                }

                if (types[1].equals("java.util.List")) {
                    return method_f3;

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 33

                                  return method_f5;
                }

                if (types[1].equals("java.util.List")) {
                    return method_f3;
                }

                if (types[1].equals("com.alibaba.json.bvt.support.hsf.HSFJSONUtilsTest_0$Model[]")) {
                    return method_f4;

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 37

                                  return method_f3;
                }

                if (types[1].equals("com.alibaba.json.bvt.support.hsf.HSFJSONUtilsTest_0$Model[]")) {
                    return method_f4;
                }

                return method_f2;
            }

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/parser/deserializer/MapDeserializer.java
99 issues
The class 'MapDeserializer' has a total cyclomatic complexity of 99 (highest 40).
Design

Line: 16

              import com.alibaba.fastjson.parser.*;
import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;

public class MapDeserializer extends ContextObjectDeserializer implements ObjectDeserializer {
    public static MapDeserializer instance = new MapDeserializer();

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, String format, int features)
    {

            

Reported by PMD.

Possible God Class (WMC=99, ATFD=128, TCC=0.000%)
Design

Line: 16

              import com.alibaba.fastjson.parser.*;
import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;

public class MapDeserializer extends ContextObjectDeserializer implements ObjectDeserializer {
    public static MapDeserializer instance = new MapDeserializer();

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, String format, int features)
    {

            

Reported by PMD.

The class 'MapDeserializer' has a Modified Cyclomatic Complexity of 8 (Highest = 29).
Design

Line: 16

              import com.alibaba.fastjson.parser.*;
import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;

public class MapDeserializer extends ContextObjectDeserializer implements ObjectDeserializer {
    public static MapDeserializer instance = new MapDeserializer();

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, String format, int features)
    {

            

Reported by PMD.

The class 'MapDeserializer' has a Standard Cyclomatic Complexity of 8 (Highest = 29).
Design

Line: 16

              import com.alibaba.fastjson.parser.*;
import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;

public class MapDeserializer extends ContextObjectDeserializer implements ObjectDeserializer {
    public static MapDeserializer instance = new MapDeserializer();

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, String format, int features)
    {

            

Reported by PMD.

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

Line: 27

                      }
        
        final JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken(JSONToken.COMMA);
            return null;
        }

        boolean unmodifiableMap = type instanceof Class

            

Reported by PMD.

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

Line: 35

                      boolean unmodifiableMap = type instanceof Class
                && "java.util.Collections$UnmodifiableMap".equals(((Class) type).getName());

        Map<Object, Object> map = (lexer.getFeatures() & Feature.OrderedField.mask) != 0
                ? createMap(type, lexer.getFeatures())
                : createMap(type);

        ParseContext context = parser.getContext();


            

Reported by PMD.

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

Line: 36

                              && "java.util.Collections$UnmodifiableMap".equals(((Class) type).getName());

        Map<Object, Object> map = (lexer.getFeatures() & Feature.OrderedField.mask) != 0
                ? createMap(type, lexer.getFeatures())
                : createMap(type);

        ParseContext context = parser.getContext();

        try {

            

Reported by PMD.

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

Line: 61

                  protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldName, Map map, int features) {
        if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;
            Type keyType = parameterizedType.getActualTypeArguments()[0];
            Type valueType = null;
            if(map.getClass().getName().equals("org.springframework.util.LinkedMultiValueMap")){
                valueType = List.class;
            }else{
                valueType = parameterizedType.getActualTypeArguments()[1];

            

Reported by PMD.

The initializer for variable 'valueType' is never used (overwritten on lines 64 and 66)
Design

Line: 62

                      if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;
            Type keyType = parameterizedType.getActualTypeArguments()[0];
            Type valueType = null;
            if(map.getClass().getName().equals("org.springframework.util.LinkedMultiValueMap")){
                valueType = List.class;
            }else{
                valueType = parameterizedType.getActualTypeArguments()[1];
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 63

                          ParameterizedType parameterizedType = (ParameterizedType) type;
            Type keyType = parameterizedType.getActualTypeArguments()[0];
            Type valueType = null;
            if(map.getClass().getName().equals("org.springframework.util.LinkedMultiValueMap")){
                valueType = List.class;
            }else{
                valueType = parameterizedType.getActualTypeArguments()[1];
            }
            if (String.class == keyType) {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/DefaultExtJSONParserTest.java
97 issues
System.out.println is used
Design

Line: 62

              
        String jsonString = JSON.toJSONString(user);

        System.out.println(jsonString);

        JSON.parseObject(jsonString);

        DefaultJSONParser parser = new DefaultJSONParser(jsonString);
        User user1 = new User();

            

Reported by PMD.

The class 'DefaultExtJSONParserTest' has a Modified Cyclomatic Complexity of 4 (Highest = 11).
Design

Line: 51

              
import junit.framework.TestCase;

public class DefaultExtJSONParserTest extends TestCase {

    public void test_parseObject() {
        new DefaultJSONParser("".toCharArray(), 0, ParserConfig.getGlobalInstance(), 0).close();
        User user = new User();
        user.setName("校长");

            

Reported by PMD.

The class 'DefaultExtJSONParserTest' has a Standard Cyclomatic Complexity of 4 (Highest = 11).
Design

Line: 51

              
import junit.framework.TestCase;

public class DefaultExtJSONParserTest extends TestCase {

    public void test_parseObject() {
        new DefaultJSONParser("".toCharArray(), 0, ParserConfig.getGlobalInstance(), 0).close();
        User user = new User();
        user.setName("校长");

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 51

              
import junit.framework.TestCase;

public class DefaultExtJSONParserTest extends TestCase {

    public void test_parseObject() {
        new DefaultJSONParser("".toCharArray(), 0, ParserConfig.getGlobalInstance(), 0).close();
        User user = new User();
        user.setName("校长");

            

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

              
public class DefaultExtJSONParserTest extends TestCase {

    public void test_parseObject() {
        new DefaultJSONParser("".toCharArray(), 0, ParserConfig.getGlobalInstance(), 0).close();
        User user = new User();
        user.setName("校长");
        user.setAge(3);
        user.setSalary(new BigDecimal("123456789.0123"));

            

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

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

    public void testCastCalendar() throws Exception {
        Calendar c = Calendar.getInstance();
        Date d = TypeUtils.castToDate(c);
        Assert.assertEquals(c.getTime(), d);
    }


            

Reported by PMD.

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

Line: 78

                  public void testCastCalendar() throws Exception {
        Calendar c = Calendar.getInstance();
        Date d = TypeUtils.castToDate(c);
        Assert.assertEquals(c.getTime(), d);
    }

    public void testCast() throws Exception {
        new TypeUtils();
        DefaultJSONParser parser = new DefaultJSONParser("");

            

Reported by PMD.

A Calendar is used to create a Date or DateTime, this is expensive.
Performance

Line: 78

                  public void testCastCalendar() throws Exception {
        Calendar c = Calendar.getInstance();
        Date d = TypeUtils.castToDate(c);
        Assert.assertEquals(c.getTime(), d);
    }

    public void testCast() throws Exception {
        new TypeUtils();
        DefaultJSONParser parser = new DefaultJSONParser("");

            

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

                      Assert.assertEquals(c.getTime(), d);
    }

    public void testCast() throws Exception {
        new TypeUtils();
        DefaultJSONParser parser = new DefaultJSONParser("");

        Assert.assertNull(castToByte(null));
        Assert.assertNull(castToShort(null));

            

Reported by PMD.

Avoid unused local variables such as 'parser'.
Design

Line: 83

              
    public void testCast() throws Exception {
        new TypeUtils();
        DefaultJSONParser parser = new DefaultJSONParser("");

        Assert.assertNull(castToByte(null));
        Assert.assertNull(castToShort(null));
        Assert.assertNull(castToInt(null));
        Assert.assertNull(castToLong(null));

            

Reported by PMD.