The following issues were found

src/test/java/com/wheelchair/parser/JSONScannerTest.java
84 issues
This class has too many methods, consider refactoring it.
Design

Line: 13

              import com.diffblue.deeptestutils.Reflector;


public class JSONScannerTest {

    @Test
    public void checkDate1() throws Throwable {
        // Arrange
        char y0 = '2';

            

Reported by PMD.

The String literal 'com.alibaba.fastjson.parser.JSONScanner' appears 26 times in this file; the first occurrence is on line 28
Error

Line: 28

                      int d1 = 52;

        // Act
        Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result

            

Reported by PMD.

The String literal 'checkDate' appears 26 times in this file; the first occurrence is on line 29
Error

Line: 29

              
        // Act
        Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result
        Assert.assertEquals(true, retval);

            

Reported by PMD.

The String literal 'int' appears 52 times in this file; the first occurrence is on line 29
Error

Line: 29

              
        // Act
        Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result
        Assert.assertEquals(true, retval);

            

Reported by PMD.

The String literal 'char' appears 156 times in this file; the first occurrence is on line 29
Error

Line: 29

              
        // Act
        Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result
        Assert.assertEquals(true, retval);

            

Reported by PMD.

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

Line: 29

              
        // Act
        Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result
        Assert.assertEquals(true, retval);

            

Reported by PMD.

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

Line: 30

                      // Act
        Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result
        Assert.assertEquals(true, retval);
    }

            

Reported by PMD.

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

Line: 31

                      Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result
        Assert.assertEquals(true, retval);
    }
    @Test

            

Reported by PMD.

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

Line: 50

              
        // Act
        Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result
        Assert.assertEquals(false, retval);

            

Reported by PMD.

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

Line: 51

                      // Act
        Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
        Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
        m.setAccessible(true);
        boolean retval = (Boolean)m.invoke(null, y0, y1, y2, y3, M0, M1, d0, d1);

        // Assert result
        Assert.assertEquals(false, retval);
    }

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/JSONValidator.java
79 issues
Overridable method 'next' called during object construction
Error

Line: 411

              
        public UTF8Validator(byte[] bytes) {
            this.bytes = bytes;
            next();
            skipWhiteSpace();
        }

        void next() {
            ++pos;

            

Reported by PMD.

Overridable method 'next' called during object construction
Error

Line: 444

                              buf = new byte[1024 * 8];
            }

            next();
            skipWhiteSpace();
        }

        void next() {
            if (pos < end) {

            

Reported by PMD.

Overridable method 'next' called during object construction
Error

Line: 495

              
        public UTF16Validator(String str) {
            this.str = str;
            next();
            skipWhiteSpace();
        }

        void next() {
            ++pos;

            

Reported by PMD.

Overridable method 'next' called during object construction
Error

Line: 572

                              buf = new char[1024 * 8];
            }

            next();
            skipWhiteSpace();
        }

        void next() {
            if (pos < end) {

            

Reported by PMD.

Possible God Class (WMC=110, ATFD=9, TCC=17.582%)
Design

Line: 8

              import java.io.InputStream;
import java.io.Reader;

public abstract class JSONValidator implements Cloneable, Closeable {
    public enum Type {
        Object, Array, Value
    }

    protected boolean eof;

            

Reported by PMD.

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

Line: 8

              import java.io.InputStream;
import java.io.Reader;

public abstract class JSONValidator implements Cloneable, Closeable {
    public enum Type {
        Object, Array, Value
    }

    protected boolean eof;

            

Reported by PMD.

The class 'JSONValidator' has a total cyclomatic complexity of 110 (highest 81).
Design

Line: 8

              import java.io.InputStream;
import java.io.Reader;

public abstract class JSONValidator implements Cloneable, Closeable {
    public enum Type {
        Object, Array, Value
    }

    protected boolean eof;

            

Reported by PMD.

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

Line: 8

              import java.io.InputStream;
import java.io.Reader;

public abstract class JSONValidator implements Cloneable, Closeable {
    public enum Type {
        Object, Array, Value
    }

    protected boolean eof;

            

Reported by PMD.

The class 'JSONValidator' has a Modified Cyclomatic Complexity of 5 (Highest = 43).
Design

Line: 8

              import java.io.InputStream;
import java.io.Reader;

public abstract class JSONValidator implements Cloneable, Closeable {
    public enum Type {
        Object, Array, Value
    }

    protected boolean eof;

            

Reported by PMD.

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

Line: 13

                      Object, Array, Value
    }

    protected boolean eof;
    protected int pos = -1;
    protected char ch;
    protected Type type;
    private Boolean validateResult;


            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/DateCodec.java
78 issues
The class 'DateCodec' has a Standard Cyclomatic Complexity of 17 (Highest = 31).
Design

Line: 41

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class DateCodec extends AbstractDateDeserializer implements ObjectSerializer, ObjectDeserializer {

    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

            

Reported by PMD.

Possible God Class (WMC=59, ATFD=96, TCC=0.000%)
Design

Line: 41

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class DateCodec extends AbstractDateDeserializer implements ObjectSerializer, ObjectDeserializer {

    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

            

Reported by PMD.

The class 'DateCodec' has a Modified Cyclomatic Complexity of 17 (Highest = 31).
Design

Line: 41

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class DateCodec extends AbstractDateDeserializer implements ObjectSerializer, ObjectDeserializer {

    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

            

Reported by PMD.

The method 'write(JSONSerializer, Object, Object, Type, int)' has a NCSS line count of 152.
Design

Line: 45

              
    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

        if (object == null) {
            out.writeNull();
            return;

            

Reported by PMD.

The method write() has an NCSS line count of 152
Design

Line: 45

              
    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

        if (object == null) {
            out.writeNull();
            return;

            

Reported by PMD.

The method 'write(JSONSerializer, Object, Object, Type, int)' has an NPath complexity of 6658560, current threshold is 200
Design

Line: 45

              
    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

        if (object == null) {
            out.writeNull();
            return;

            

Reported by PMD.

The method 'write(JSONSerializer, Object, Object, Type, int)' has a cyclomatic complexity of 35.
Design

Line: 45

              
    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

        if (object == null) {
            out.writeNull();
            return;

            

Reported by PMD.

Avoid really long methods.
Design

Line: 45

              
    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

        if (object == null) {
            out.writeNull();
            return;

            

Reported by PMD.

The method 'write' has a Modified Cyclomatic Complexity of 31.
Design

Line: 45

              
    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

        if (object == null) {
            out.writeNull();
            return;

            

Reported by PMD.

The method 'write' has a Standard Cyclomatic Complexity of 31.
Design

Line: 45

              
    public final static DateCodec instance = new DateCodec();
    
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

        if (object == null) {
            out.writeNull();
            return;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/basicType/LongTest2_obj.java
77 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

               * Created by wenshao on 11/08/2017.
 */
public class LongTest2_obj extends TestCase {
    public void test_0() throws Exception {
        String json = "{\"v1\":-1883391953414482124,\"v2\":-3019416596934963650,\"v3\":6497525620823745793,\"v4\":2136224289077142499,\"v5\":-2090575024006307745}";
        String json2 = "{\"v1\":\"-1883391953414482124\",\"v2\":\"-3019416596934963650\",\"v3\":\"6497525620823745793\",\"v4\":\"2136224289077142499\",\"v5\":\"-2090575024006307745\"}";

        Model m1 = JSON.parseObject(json, Model.class);
        Model m2 = JSON.parseObject(json2, Model.class);

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 11/08/2017.
 */
public class LongTest2_obj extends TestCase {
    public void test_0() throws Exception {
        String json = "{\"v1\":-1883391953414482124,\"v2\":-3019416596934963650,\"v3\":6497525620823745793,\"v4\":2136224289077142499,\"v5\":-2090575024006307745}";
        String json2 = "{\"v1\":\"-1883391953414482124\",\"v2\":\"-3019416596934963650\",\"v3\":\"6497525620823745793\",\"v4\":\"2136224289077142499\",\"v5\":\"-2090575024006307745\"}";

        Model m1 = JSON.parseObject(json, Model.class);
        Model m2 = JSON.parseObject(json2, Model.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      Model m1 = JSON.parseObject(json, Model.class);
        Model m2 = JSON.parseObject(json2, Model.class);

        assertNotNull(m1);
        assertNotNull(m2);

        assertEquals(-1883391953414482124L, m1.v1.longValue());
        assertEquals(-3019416596934963650L, m1.v2.longValue());
        assertEquals(6497525620823745793L, m1.v3.longValue());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      Model m2 = JSON.parseObject(json2, Model.class);

        assertNotNull(m1);
        assertNotNull(m2);

        assertEquals(-1883391953414482124L, m1.v1.longValue());
        assertEquals(-3019416596934963650L, m1.v2.longValue());
        assertEquals(6497525620823745793L, m1.v3.longValue());
        assertEquals(2136224289077142499L, m1.v4.longValue());

            

Reported by PMD.

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

Line: 24

                      assertNotNull(m1);
        assertNotNull(m2);

        assertEquals(-1883391953414482124L, m1.v1.longValue());
        assertEquals(-3019416596934963650L, m1.v2.longValue());
        assertEquals(6497525620823745793L, m1.v3.longValue());
        assertEquals(2136224289077142499L, m1.v4.longValue());
        assertEquals(-2090575024006307745L, m1.v5.longValue());


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                      assertNotNull(m1);
        assertNotNull(m2);

        assertEquals(-1883391953414482124L, m1.v1.longValue());
        assertEquals(-3019416596934963650L, m1.v2.longValue());
        assertEquals(6497525620823745793L, m1.v3.longValue());
        assertEquals(2136224289077142499L, m1.v4.longValue());
        assertEquals(-2090575024006307745L, m1.v5.longValue());


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                      assertNotNull(m2);

        assertEquals(-1883391953414482124L, m1.v1.longValue());
        assertEquals(-3019416596934963650L, m1.v2.longValue());
        assertEquals(6497525620823745793L, m1.v3.longValue());
        assertEquals(2136224289077142499L, m1.v4.longValue());
        assertEquals(-2090575024006307745L, m1.v5.longValue());

        assertEquals(-1883391953414482124L, m2.v1.longValue());

            

Reported by PMD.

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

Line: 25

                      assertNotNull(m2);

        assertEquals(-1883391953414482124L, m1.v1.longValue());
        assertEquals(-3019416596934963650L, m1.v2.longValue());
        assertEquals(6497525620823745793L, m1.v3.longValue());
        assertEquals(2136224289077142499L, m1.v4.longValue());
        assertEquals(-2090575024006307745L, m1.v5.longValue());

        assertEquals(-1883391953414482124L, m2.v1.longValue());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

              
        assertEquals(-1883391953414482124L, m1.v1.longValue());
        assertEquals(-3019416596934963650L, m1.v2.longValue());
        assertEquals(6497525620823745793L, m1.v3.longValue());
        assertEquals(2136224289077142499L, m1.v4.longValue());
        assertEquals(-2090575024006307745L, m1.v5.longValue());

        assertEquals(-1883391953414482124L, m2.v1.longValue());
        assertEquals(-3019416596934963650L, m2.v2.longValue());

            

Reported by PMD.

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

Line: 26

              
        assertEquals(-1883391953414482124L, m1.v1.longValue());
        assertEquals(-3019416596934963650L, m1.v2.longValue());
        assertEquals(6497525620823745793L, m1.v3.longValue());
        assertEquals(2136224289077142499L, m1.v4.longValue());
        assertEquals(-2090575024006307745L, m1.v5.longValue());

        assertEquals(-1883391953414482124L, m2.v1.longValue());
        assertEquals(-3019416596934963650L, m2.v2.longValue());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/TypeUtilsTest.java
76 issues
Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 52

                  public void test_cast_Integer() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1L);
        Assert.assertEquals(new Integer(1), json.getObject("id", int.class));
    }

    public void test_cast_Integer_2() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1L);

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 58

                  public void test_cast_Integer_2() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1L);
        Assert.assertEquals(new Integer(1), json.getObject("id", Integer.class));
    }

    public void test_cast_to_long() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);

            

Reported by PMD.

Avoid instantiating Long objects.Call Long.valueOf() instead
Performance

Line: 64

                  public void test_cast_to_long() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);
        Assert.assertEquals(new Long(1), json.getObject("id", long.class));
    }

    public void test_cast_to_Long() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);

            

Reported by PMD.

Avoid instantiating Long objects.Call Long.valueOf() instead
Performance

Line: 70

                  public void test_cast_to_Long() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);
        Assert.assertEquals(new Long(1), json.getObject("id", Long.class));
    }

    public void test_cast_to_short() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);

            

Reported by PMD.

Avoid instantiating Short objects. Call Short.valueOf() instead
Performance

Line: 76

                  public void test_cast_to_short() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);
        Assert.assertEquals(new Short((short) 1), json.getObject("id", short.class));
    }

    public void test_cast_to_Short() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);

            

Reported by PMD.

Avoid instantiating Short objects. Call Short.valueOf() instead
Performance

Line: 82

                  public void test_cast_to_Short() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);
        Assert.assertEquals(new Short((short) 1), json.getObject("id", Short.class));
    }

    public void test_cast_to_byte() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);

            

Reported by PMD.

Avoid instantiating Byte objects. Call Byte.valueOf() instead
Performance

Line: 88

                  public void test_cast_to_byte() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);
        Assert.assertEquals(new Byte((byte) 1), json.getObject("id", byte.class));
    }

    public void test_cast_to_Byte() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);

            

Reported by PMD.

Avoid instantiating Byte objects. Call Byte.valueOf() instead
Performance

Line: 94

                  public void test_cast_to_Byte() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);
        Assert.assertEquals(new Byte((byte) 1), json.getObject("id", Byte.class));
    }

    public void test_cast_to_BigInteger() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", 1);

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 1

              package com.alibaba.json.bvt.parser;

import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

            

Reported by PMD.

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

Line: 26

              import com.alibaba.fastjson.util.TypeUtils;

@SuppressWarnings("rawtypes")
public class TypeUtilsTest extends TestCase {

    public void test_0() throws Exception {
        HashMap map = new HashMap();

        Assert.assertTrue(map == TypeUtils.castToJavaBean(map, Map.class));

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/asm/ClassReader.java
75 issues
Avoid reassigning parameters such as 'u'
Design

Line: 184

                      return u + 2;
    }

    private int readMethod(TypeCollector classVisitor, char[] c, int u) {
        int v;
        int w;
        int j;
        String attrName;
        int k;

            

Reported by PMD.

Avoid reassigning parameters such as 'u'
Design

Line: 184

                      return u + 2;
    }

    private int readMethod(TypeCollector classVisitor, char[] c, int u) {
        int v;
        int w;
        int j;
        String attrName;
        int k;

            

Reported by PMD.

Avoid reassigning parameters such as 'u'
Design

Line: 184

                      return u + 2;
    }

    private int readMethod(TypeCollector classVisitor, char[] c, int u) {
        int v;
        int w;
        int j;
        String attrName;
        int k;

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 288

                              | ((b[index + 2] & 0xFF) << 8) | (b[index + 3] & 0xFF);
    }

    private String readUTF8(int index, final char[] buf) {
        int item = readUnsignedShort(index);
        String s = strings[item];
        if (s != null) {
            return s;
        }

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 298

                      return strings[item] = readUTF(index + 2, readUnsignedShort(index), buf);
    }

    private String readUTF(int index, final int utfLen, final char[] buf) {
        int endIndex = index + utfLen;
        byte[] b = this.b;
        int strLen = 0;
        int c;
        int st = 0;

            

Reported by PMD.

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

Line: 10

              /**
 * Created by wenshao on 05/08/2017.
 */
public class ClassReader {
    public  final byte[] b;
    private final int[] items;
    private final String[] strings;
    private final int maxStringLength;
    public  final int header;

            

Reported by PMD.

The class 'ClassReader' has a Standard Cyclomatic Complexity of 7 (Highest = 15).
Design

Line: 10

              /**
 * Created by wenshao on 05/08/2017.
 */
public class ClassReader {
    public  final byte[] b;
    private final int[] items;
    private final String[] strings;
    private final int maxStringLength;
    public  final int header;

            

Reported by PMD.

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

Line: 11

               * Created by wenshao on 05/08/2017.
 */
public class ClassReader {
    public  final byte[] b;
    private final int[] items;
    private final String[] strings;
    private final int maxStringLength;
    public  final int header;
    private boolean readAnnotations;

            

Reported by PMD.

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

Line: 12

               */
public class ClassReader {
    public  final byte[] b;
    private final int[] items;
    private final String[] strings;
    private final int maxStringLength;
    public  final int header;
    private boolean readAnnotations;


            

Reported by PMD.

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

Line: 13

              public class ClassReader {
    public  final byte[] b;
    private final int[] items;
    private final String[] strings;
    private final int maxStringLength;
    public  final int header;
    private boolean readAnnotations;

    public ClassReader(InputStream is, boolean readAnnotations) throws IOException {

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/JSONObject.java
74 issues
Do not use the short type
Performance

Line: 233

                      return castToShort(value);
    }

    public short getShortValue(String key) {
        Object value = get(key);

        Short shortVal = castToShort(value);
        if (shortVal == null) {
            return 0;

            

Reported by PMD.

Object clone() should be implemented with super.clone()
Error

Line: 401

                  }

    @Override
    public JSONObject clone() {
        return new JSONObject(map instanceof LinkedHashMap //
                ? new LinkedHashMap<String, Object>(map) //
                : new HashMap<String, Object>(map)
        );
    }

            

Reported by PMD.

High amount of different objects as members denotes a high coupling
Design

Line: 16

               * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.fastjson;

import static com.alibaba.fastjson.util.TypeUtils.castToBigDecimal;
import static com.alibaba.fastjson.util.TypeUtils.castToBigInteger;
import static com.alibaba.fastjson.util.TypeUtils.castToBoolean;
import static com.alibaba.fastjson.util.TypeUtils.castToByte;

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 16

               * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.fastjson;

import static com.alibaba.fastjson.util.TypeUtils.castToBigDecimal;
import static com.alibaba.fastjson.util.TypeUtils.castToBigInteger;
import static com.alibaba.fastjson.util.TypeUtils.castToBoolean;
import static com.alibaba.fastjson.util.TypeUtils.castToByte;

            

Reported by PMD.

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

Line: 49

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONObject extends JSON implements Map<String, Object>, Cloneable, Serializable, InvocationHandler {

    private static final long         serialVersionUID         = 1L;
    private static final int          DEFAULT_INITIAL_CAPACITY = 16;

    private final Map<String, Object> map;

            

Reported by PMD.

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

Line: 49

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONObject extends JSON implements Map<String, Object>, Cloneable, Serializable, InvocationHandler {

    private static final long         serialVersionUID         = 1L;
    private static final int          DEFAULT_INITIAL_CAPACITY = 16;

    private final Map<String, Object> map;

            

Reported by PMD.

The class 'JSONObject' has a Modified Cyclomatic Complexity of 2 (Highest = 20).
Design

Line: 49

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONObject extends JSON implements Map<String, Object>, Cloneable, Serializable, InvocationHandler {

    private static final long         serialVersionUID         = 1L;
    private static final int          DEFAULT_INITIAL_CAPACITY = 16;

    private final Map<String, Object> map;

            

Reported by PMD.

Possible God Class (WMC=127, ATFD=44, TCC=26.531%)
Design

Line: 49

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONObject extends JSON implements Map<String, Object>, Cloneable, Serializable, InvocationHandler {

    private static final long         serialVersionUID         = 1L;
    private static final int          DEFAULT_INITIAL_CAPACITY = 16;

    private final Map<String, Object> map;

            

Reported by PMD.

The class 'JSONObject' has a total cyclomatic complexity of 127 (highest 28).
Design

Line: 49

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONObject extends JSON implements Map<String, Object>, Cloneable, Serializable, InvocationHandler {

    private static final long         serialVersionUID         = 1L;
    private static final int          DEFAULT_INITIAL_CAPACITY = 16;

    private final Map<String, Object> map;

            

Reported by PMD.

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

Line: 54

                  private static final long         serialVersionUID         = 1L;
    private static final int          DEFAULT_INITIAL_CAPACITY = 16;

    private final Map<String, Object> map;

    public JSONObject(){
        this(DEFAULT_INITIAL_CAPACITY, false);
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/support/spring/security/DefaultSavedRequestTest.java
74 issues
System.out.println is used
Design

Line: 85

                  public void test_PreAuthenticatedAuthenticationToken() throws Exception {
        PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken("ppp", "cccc");
        String json = JSON.toJSONString(token);
        System.out.println(json);

        PreAuthenticatedAuthenticationToken token1 = JSON.parseObject(json, PreAuthenticatedAuthenticationToken.class);
        assertEquals("ppp", token1.getPrincipal());
        assertEquals("cccc", token1.getCredentials());
    }

            

Reported by PMD.

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

Line: 28

              /**
 * Created by wenshao on 11/08/2017.
 */
public class DefaultSavedRequestTest extends TestCase {
    ParserConfig config;

    protected void setUp() throws Exception {
        Field field = GenericFastJsonRedisSerializer.class.getDeclaredField("defaultRedisConfig");
        field.setAccessible(true);

            

Reported by PMD.

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

Line: 29

               * Created by wenshao on 11/08/2017.
 */
public class DefaultSavedRequestTest extends TestCase {
    ParserConfig config;

    protected void setUp() throws Exception {
        Field field = GenericFastJsonRedisSerializer.class.getDeclaredField("defaultRedisConfig");
        field.setAccessible(true);
        config = (ParserConfig) field.get(null);

            

Reported by PMD.

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

Line: 31

              public class DefaultSavedRequestTest extends TestCase {
    ParserConfig config;

    protected void setUp() throws Exception {
        Field field = GenericFastJsonRedisSerializer.class.getDeclaredField("defaultRedisConfig");
        field.setAccessible(true);
        config = (ParserConfig) field.get(null);
        config.addAccept("org.springframework.security.web.savedrequest.DefaultSavedRequest");
    }

            

Reported by PMD.

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

Line: 33

              
    protected void setUp() throws Exception {
        Field field = GenericFastJsonRedisSerializer.class.getDeclaredField("defaultRedisConfig");
        field.setAccessible(true);
        config = (ParserConfig) field.get(null);
        config.addAccept("org.springframework.security.web.savedrequest.DefaultSavedRequest");
    }
    public void test_for_issue() throws Exception {
        MockHttpServletRequest mockReq = new MockHttpServletRequest();

            

Reported by PMD.

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

Line: 34

                  protected void setUp() throws Exception {
        Field field = GenericFastJsonRedisSerializer.class.getDeclaredField("defaultRedisConfig");
        field.setAccessible(true);
        config = (ParserConfig) field.get(null);
        config.addAccept("org.springframework.security.web.savedrequest.DefaultSavedRequest");
    }
    public void test_for_issue() throws Exception {
        MockHttpServletRequest mockReq = new MockHttpServletRequest();
        DefaultSavedRequest request = new DefaultSavedRequest(mockReq, new PortResolver() {

            

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

                      config = (ParserConfig) field.get(null);
        config.addAccept("org.springframework.security.web.savedrequest.DefaultSavedRequest");
    }
    public void test_for_issue() throws Exception {
        MockHttpServletRequest mockReq = new MockHttpServletRequest();
        DefaultSavedRequest request = new DefaultSavedRequest(mockReq, new PortResolver() {

            public int getServerPort(ServletRequest servletRequest) {
                return 0;

            

Reported by PMD.

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

Line: 37

                      config = (ParserConfig) field.get(null);
        config.addAccept("org.springframework.security.web.savedrequest.DefaultSavedRequest");
    }
    public void test_for_issue() throws Exception {
        MockHttpServletRequest mockReq = new MockHttpServletRequest();
        DefaultSavedRequest request = new DefaultSavedRequest(mockReq, new PortResolver() {

            public int getServerPort(ServletRequest servletRequest) {
                return 0;

            

Reported by PMD.

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

Line: 56

                  }


    public void test_cookie() throws Exception {
        String json = "{\"name\":\"xx\",\"value\":\"xx\",\"comment\":\"xx\",\"domain\":\"xx\"}";
        SavedCookie cookie = JSON.parseObject(json, SavedCookie.class);
        assertEquals("xx", cookie.getName());
        assertEquals("{\"comment\":\"xx\",\"cookie\":{\"comment\":\"xx\",\"domain\":\"xx\",\"httpOnly\":false,\"maxAge\":0,\"name\":\"xx\",\"secure\":false,\"value\":\"xx\",\"version\":0},\"domain\":\"xx\",\"maxAge\":0,\"name\":\"xx\",\"secure\":false,\"value\":\"xx\",\"version\":0}", JSON.toJSONString(cookie));
    }

            

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

                  }


    public void test_cookie() throws Exception {
        String json = "{\"name\":\"xx\",\"value\":\"xx\",\"comment\":\"xx\",\"domain\":\"xx\"}";
        SavedCookie cookie = JSON.parseObject(json, SavedCookie.class);
        assertEquals("xx", cookie.getName());
        assertEquals("{\"comment\":\"xx\",\"cookie\":{\"comment\":\"xx\",\"domain\":\"xx\",\"httpOnly\":false,\"maxAge\":0,\"name\":\"xx\",\"secure\":false,\"value\":\"xx\",\"version\":0},\"domain\":\"xx\",\"maxAge\":0,\"name\":\"xx\",\"secure\":false,\"value\":\"xx\",\"version\":0}", JSON.toJSONString(cookie));
    }

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/JSON.java
74 issues
Avoid reassigning parameters such as 'featureValues'
Design

Line: 334

                  }

    @SuppressWarnings("unchecked")
    public static <T> T parseObject(String input, Type clazz, int featureValues, Feature... features) {
        if (input == null) {
            return null;
        }

        for (Feature feature : features) {

            

Reported by PMD.

Avoid reassigning parameters such as 'featureValues'
Design

Line: 367

              
    @SuppressWarnings("unchecked")
    public static <T> T parseObject(String input, Type clazz, ParserConfig config, ParseProcess processor,
                                          int featureValues, Feature... features) {
        if (input == null || input.length() == 0) {
            return null;
        }

        if (features != null) {

            

Reported by PMD.

Avoid reassigning parameters such as 'charset'
Design

Line: 435

                   */
    @SuppressWarnings("unchecked")
    public static <T> T parseObject(byte[] bytes, int offset, int len,
                                    Charset charset,
                                    Type clazz,
                                    ParserConfig config,
                                    ParseProcess processor,
                                    int featureValues,
                                    Feature... features) {

            

Reported by PMD.

Avoid reassigning parameters such as 'charset'
Design

Line: 559

                   */
    @SuppressWarnings("unchecked")
    public static <T> T parseObject(InputStream is, //
                                    Charset charset, //
                                    Type type, //
                                    ParserConfig config, //
                                    ParseProcess processor, //
                                    int featureValues, //
                                    Feature... features) throws IOException {

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 16

               * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.fastjson;

import java.io.*;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.nio.ByteBuffer;

            

Reported by PMD.

Possible God Class (WMC=227, ATFD=128, TCC=4.493%)
Design

Line: 65

               * 
 * @author wenshao[szujobs@hotmail.com]
 */
public abstract class JSON implements JSONStreamAware, JSONAware {
    public static TimeZone         defaultTimeZone      = TimeZone.getDefault();
    public static Locale           defaultLocale        = Locale.getDefault();
    public static String           DEFAULT_TYPE_KEY     = "@type";
    static final SerializeFilter[] emptyFilters         = new SerializeFilter[0];
    public static String           DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

            

Reported by PMD.

Avoid really long classes.
Design

Line: 65

               * 
 * @author wenshao[szujobs@hotmail.com]
 */
public abstract class JSON implements JSONStreamAware, JSONAware {
    public static TimeZone         defaultTimeZone      = TimeZone.getDefault();
    public static Locale           defaultLocale        = Locale.getDefault();
    public static String           DEFAULT_TYPE_KEY     = "@type";
    static final SerializeFilter[] emptyFilters         = new SerializeFilter[0];
    public static String           DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

            

Reported by PMD.

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

Line: 65

               * 
 * @author wenshao[szujobs@hotmail.com]
 */
public abstract class JSON implements JSONStreamAware, JSONAware {
    public static TimeZone         defaultTimeZone      = TimeZone.getDefault();
    public static Locale           defaultLocale        = Locale.getDefault();
    public static String           DEFAULT_TYPE_KEY     = "@type";
    static final SerializeFilter[] emptyFilters         = new SerializeFilter[0];
    public static String           DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

            

Reported by PMD.

The class 'JSON' has a total cyclomatic complexity of 227 (highest 22).
Design

Line: 65

               * 
 * @author wenshao[szujobs@hotmail.com]
 */
public abstract class JSON implements JSONStreamAware, JSONAware {
    public static TimeZone         defaultTimeZone      = TimeZone.getDefault();
    public static Locale           defaultLocale        = Locale.getDefault();
    public static String           DEFAULT_TYPE_KEY     = "@type";
    static final SerializeFilter[] emptyFilters         = new SerializeFilter[0];
    public static String           DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

            

Reported by PMD.

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

Line: 65

               * 
 * @author wenshao[szujobs@hotmail.com]
 */
public abstract class JSON implements JSONStreamAware, JSONAware {
    public static TimeZone         defaultTimeZone      = TimeZone.getDefault();
    public static Locale           defaultLocale        = Locale.getDefault();
    public static String           DEFAULT_TYPE_KEY     = "@type";
    static final SerializeFilter[] emptyFilters         = new SerializeFilter[0];
    public static String           DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/date/DateFieldTest11_reader.java
73 issues
System.out.println is used
Design

Line: 71

                      assertEquals(0, calendar.get(Calendar.SECOND));
        assertEquals(0, calendar.get(Calendar.MILLISECOND));

        System.out.println(vo.date0.getTime());
        System.out.println(vo.date1.getTime());
    }

    public static class Model {
        public Date date0;

            

Reported by PMD.

System.out.println is used
Design

Line: 72

                      assertEquals(0, calendar.get(Calendar.MILLISECOND));

        System.out.println(vo.date0.getTime());
        System.out.println(vo.date1.getTime());
    }

    public static class Model {
        public Date date0;
        public Date date1;

            

Reported by PMD.

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

Line: 19

               * Created by wenshao on 07/04/2017.
 */
public class DateFieldTest11_reader extends TestCase {
    protected void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
        JSON.defaultLocale = Locale.CHINA;
    }

    public void test_cn() 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: 24

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_cn() throws Exception {
        Model vo = new JSONReader(new StringReader("{\"date0\":\"2016-05-06\",\"date1\":\"2017-03-01\"}")).readObject(Model.class);

        Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);

        calendar.setTime(vo.date0);

            

Reported by PMD.

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

Line: 24

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_cn() throws Exception {
        Model vo = new JSONReader(new StringReader("{\"date0\":\"2016-05-06\",\"date1\":\"2017-03-01\"}")).readObject(Model.class);

        Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);

        calendar.setTime(vo.date0);

            

Reported by PMD.

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

Line: 29

              
        Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);

        calendar.setTime(vo.date0);
        assertEquals(2016, calendar.get(Calendar.YEAR));
        assertEquals(4, calendar.get(Calendar.MONTH));
        assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
        assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
        assertEquals(0, calendar.get(Calendar.MINUTE));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 30

                      Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);

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

            

Reported by PMD.

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

Line: 30

                      Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);

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

            

Reported by PMD.

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

Line: 31

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

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 31

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

            

Reported by PMD.