The following issues were found

src/test/java/com/alibaba/json/bvt/support/hsf/HSFJSONUtilsTest_0.java
72 issues
System.out.println is used
Design

Line: 143

                              "    \t\t}]\n" +
                "    ]\n" +
                "]";
        System.out.println(json);
        Object[] values = HSFJSONUtils.parseInvocationArguments(json, methodLocator);
        assertNotNull(values);
        assertEquals(1, values.length);

        List list = (List) values[0];

            

Reported by PMD.

System.out.println is used
Design

Line: 198

                          Object[] values = HSFJSONUtils.parseInvocationArguments(json, methodLocator);
        }
        long millis = System.currentTimeMillis() - start;
        System.out.println("millis : " + millis);
    }

    public static class Service {
        public void f1() {


            

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_0 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_0 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_0 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("f4", List.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("f4", List.class);
        method_f5 = Service.class.getMethod("f4", User[].class);


            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 29

                                  return method_f2;
                }

                if (types.length == 1 && types[0].equals("java.util.List")) {
                    return method_f4;
                }

                if (types.length == 1 && types[0].equals("com.alibaba.json.bvt.support.hsf.HSFJSONUtilsTest_0.User[]")) {
                    return method_f5;

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 33

                                  return method_f4;
                }

                if (types.length == 1 && types[0].equals("com.alibaba.json.bvt.support.hsf.HSFJSONUtilsTest_0.User[]")) {
                    return method_f5;
                }

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

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/util/AntiCollisionHashMapTest.java
71 issues
The method 'test_0()' has a NCSS line count of 80.
Design

Line: 15

              import java.util.Map;

public class AntiCollisionHashMapTest extends TestCase {
    public void test_0() throws Exception {
        AntiCollisionHashMap m = new AntiCollisionHashMap(3, 0.75f);

        for (int i = 0; i < 100; ++i) {
            m.put(i, i);
        }

            

Reported by PMD.

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

Line: 15

              import java.util.Map;

public class AntiCollisionHashMapTest extends TestCase {
    public void test_0() throws Exception {
        AntiCollisionHashMap m = new AntiCollisionHashMap(3, 0.75f);

        for (int i = 0; i < 100; ++i) {
            m.put(i, i);
        }

            

Reported by PMD.

Avoid really long methods.
Design

Line: 15

              import java.util.Map;

public class AntiCollisionHashMapTest extends TestCase {
    public void test_0() throws Exception {
        AntiCollisionHashMap m = new AntiCollisionHashMap(3, 0.75f);

        for (int i = 0; i < 100; ++i) {
            m.put(i, i);
        }

            

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

              import java.util.Map;

public class AntiCollisionHashMapTest extends TestCase {
    public void test_0() throws Exception {
        AntiCollisionHashMap m = new AntiCollisionHashMap(3, 0.75f);

        for (int i = 0; i < 100; ++i) {
            m.put(i, i);
        }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                      }

        AntiCollisionHashMap m2 = new AntiCollisionHashMap(m);
        assertEquals(m.size(), m2.size());

        AntiCollisionHashMap m3 = new AntiCollisionHashMap(3, 0.75f);
        m3.putAll(m);
        assertEquals(m.size(), m2.size());


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

              
        AntiCollisionHashMap m3 = new AntiCollisionHashMap(3, 0.75f);
        m3.putAll(m);
        assertEquals(m.size(), m2.size());

        AntiCollisionHashMap m4 = (AntiCollisionHashMap) m.clone();
        m4.hashCode();
        m4.size();
        m4.isEmpty();

            

Reported by PMD.

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

Line: 30

                      assertEquals(m.size(), m2.size());

        AntiCollisionHashMap m4 = (AntiCollisionHashMap) m.clone();
        m4.hashCode();
        m4.size();
        m4.isEmpty();
        m4.values().iterator();
        m4.keySet().iterator();
        m4.values().contains(1);

            

Reported by PMD.

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

Line: 31

              
        AntiCollisionHashMap m4 = (AntiCollisionHashMap) m.clone();
        m4.hashCode();
        m4.size();
        m4.isEmpty();
        m4.values().iterator();
        m4.keySet().iterator();
        m4.values().contains(1);
        m4.values().contains(null);

            

Reported by PMD.

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

Line: 32

                      AntiCollisionHashMap m4 = (AntiCollisionHashMap) m.clone();
        m4.hashCode();
        m4.size();
        m4.isEmpty();
        m4.values().iterator();
        m4.keySet().iterator();
        m4.values().contains(1);
        m4.values().contains(null);
        m4.values().iterator().next();

            

Reported by PMD.

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

Line: 33

                      m4.hashCode();
        m4.size();
        m4.isEmpty();
        m4.values().iterator();
        m4.keySet().iterator();
        m4.values().contains(1);
        m4.values().contains(null);
        m4.values().iterator().next();
        m4.values().remove(1);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2700/Issue2784.java
70 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 12

              import java.util.Date;

public class Issue2784 extends TestCase {
    public void test_for_issue() throws Exception {
        Model m = new Model();
        m.time = java.time.LocalDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"time\":"
                + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()

            

Reported by PMD.

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

Line: 12

              import java.util.Date;

public class Issue2784 extends TestCase {
    public void test_for_issue() throws Exception {
        Model m = new Model();
        m.time = java.time.LocalDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"time\":"
                + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()

            

Reported by PMD.

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

Line: 14

              public class Issue2784 extends TestCase {
    public void test_for_issue() throws Exception {
        Model m = new Model();
        m.time = java.time.LocalDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"time\":"
                + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()
                + "}", str);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      Model m = new Model();
        m.time = java.time.LocalDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"time\":"
                + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()
                + "}", str);

        Model m1 = JSON.parseObject(str, Model.class);
        assertEquals(m.time, m1.time);

            

Reported by PMD.

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

Line: 17

                      m.time = java.time.LocalDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"time\":"
                + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()
                + "}", str);

        Model m1 = JSON.parseObject(str, Model.class);
        assertEquals(m.time, m1.time);
    }

            

Reported by PMD.

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

Line: 17

                      m.time = java.time.LocalDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"time\":"
                + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()
                + "}", str);

        Model m1 = JSON.parseObject(str, Model.class);
        assertEquals(m.time, m1.time);
    }

            

Reported by PMD.

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

Line: 17

                      m.time = java.time.LocalDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"time\":"
                + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()
                + "}", str);

        Model m1 = JSON.parseObject(str, Model.class);
        assertEquals(m.time, m1.time);
    }

            

Reported by PMD.

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

Line: 17

                      m.time = java.time.LocalDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"time\":"
                + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()
                + "}", str);

        Model m1 = JSON.parseObject(str, Model.class);
        assertEquals(m.time, m1.time);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                              + "}", str);

        Model m1 = JSON.parseObject(str, Model.class);
        assertEquals(m.time, m1.time);
    }

    public void test_for_issue_1() throws Exception {
        Model m = new Model();
        m.ztime = ZonedDateTime.now();

            

Reported by PMD.

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

Line: 24

                      assertEquals(m.time, m1.time);
    }

    public void test_for_issue_1() throws Exception {
        Model m = new Model();
        m.ztime = ZonedDateTime.now();
        String str = JSON.toJSONString(m);
        assertEquals("{\"ztime\":"
                + m.ztime.toInstant().toEpochMilli()

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/parser/deserializer/StackTraceElementDeserializer.java
67 issues
The class 'StackTraceElementDeserializer' has a Modified Cyclomatic Complexity of 20 (Highest = 38).
Design

Line: 12

              import com.alibaba.fastjson.parser.JSONLexer;
import com.alibaba.fastjson.parser.JSONToken;

public class StackTraceElementDeserializer implements ObjectDeserializer {

    public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {

            

Reported by PMD.

Possible God Class (WMC=52, ATFD=37, TCC=0.000%)
Design

Line: 12

              import com.alibaba.fastjson.parser.JSONLexer;
import com.alibaba.fastjson.parser.JSONToken;

public class StackTraceElementDeserializer implements ObjectDeserializer {

    public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {

            

Reported by PMD.

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

Line: 12

              import com.alibaba.fastjson.parser.JSONLexer;
import com.alibaba.fastjson.parser.JSONToken;

public class StackTraceElementDeserializer implements ObjectDeserializer {

    public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {

            

Reported by PMD.

The method 'deserialze(DefaultJSONParser, Type, Object)' has a cyclomatic complexity of 51.
Design

Line: 17

                  public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            return null;
        }

            

Reported by PMD.

The method 'deserialze' has a Standard Cyclomatic Complexity of 38.
Design

Line: 17

                  public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            return null;
        }

            

Reported by PMD.

The method 'deserialze' has a Modified Cyclomatic Complexity of 38.
Design

Line: 17

                  public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            return null;
        }

            

Reported by PMD.

Avoid really long methods.
Design

Line: 17

                  public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            return null;
        }

            

Reported by PMD.

The method 'deserialze(DefaultJSONParser, Type, Object)' has a NCSS line count of 113.
Design

Line: 17

                  public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            return null;
        }

            

Reported by PMD.

The method deserialze() has an NCSS line count of 113
Design

Line: 17

                  public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            return null;
        }

            

Reported by PMD.

The method 'deserialze(DefaultJSONParser, Type, Object)' has an NPath complexity of 2526, current threshold is 200
Design

Line: 17

                  public final static StackTraceElementDeserializer instance = new StackTraceElementDeserializer();

    @SuppressWarnings({ "unchecked", "unused" })
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.NULL) {
            lexer.nextToken();
            return null;
        }

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/util/Base64.java
67 issues
All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 11

               * @author Mikael Grev Date: 2004-aug-02 Time: 11:31:11
 * @deprecated internal api, don't use.
 */
public class Base64 {

    public static final char[] CA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
    public static final int[]  IA = new int[256];
    static {
        Arrays.fill(IA, -1);

            

Reported by PMD.

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

Line: 11

               * @author Mikael Grev Date: 2004-aug-02 Time: 11:31:11
 * @deprecated internal api, don't use.
 */
public class Base64 {

    public static final char[] CA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
    public static final int[]  IA = new int[256];
    static {
        Arrays.fill(IA, -1);

            

Reported by PMD.

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

Line: 11

               * @author Mikael Grev Date: 2004-aug-02 Time: 11:31:11
 * @deprecated internal api, don't use.
 */
public class Base64 {

    public static final char[] CA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
    public static final int[]  IA = new int[256];
    static {
        Arrays.fill(IA, -1);

            

Reported by PMD.

Too many control variables in the for statement
Design

Line: 17

                  public static final int[]  IA = new int[256];
    static {
        Arrays.fill(IA, -1);
        for (int i = 0, iS = CA.length; i < iS; i++)
            IA[CA[i]] = i;
        IA['='] = 0;
    }

    /**

            

Reported by PMD.

The method 'decodeFast' has a Modified Cyclomatic Complexity of 13.
Design

Line: 33

                   * @param chars The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
     * @return The decoded array of bytes. May be of length 0.
     */
    public static byte[] decodeFast(char[] chars, int offset, int charsLen) {
        // Check special case
        if (charsLen == 0) {
            return new byte[0];
        }


            

Reported by PMD.

The method 'decodeFast(char, int, int)' has a cyclomatic complexity of 16.
Design

Line: 33

                   * @param chars The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
     * @return The decoded array of bytes. May be of length 0.
     */
    public static byte[] decodeFast(char[] chars, int offset, int charsLen) {
        // Check special case
        if (charsLen == 0) {
            return new byte[0];
        }


            

Reported by PMD.

The method 'decodeFast(char, int, int)' has an NPath complexity of 3240, current threshold is 200
Design

Line: 33

                   * @param chars The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
     * @return The decoded array of bytes. May be of length 0.
     */
    public static byte[] decodeFast(char[] chars, int offset, int charsLen) {
        // Check special case
        if (charsLen == 0) {
            return new byte[0];
        }


            

Reported by PMD.

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

Line: 33

                   * @param chars The source array. Length 0 will return an empty array. <code>null</code> will throw an exception.
     * @return The decoded array of bytes. May be of length 0.
     */
    public static byte[] decodeFast(char[] chars, int offset, int charsLen) {
        // Check special case
        if (charsLen == 0) {
            return new byte[0];
        }


            

Reported by PMD.

Too many control variables in the for statement
Design

Line: 59

              
        // Decode all but the last 0 - 2 bytes.
        int d = 0;
        for (int cc = 0, eLen = (len / 3) * 3; d < eLen;) {
            // Assemble three bytes into an int from four "valid" characters.
            int i = IA[chars[sIx++]] << 18 | IA[chars[sIx++]] << 12 | IA[chars[sIx++]] << 6 | IA[chars[sIx++]];

            // Add the bytes
            bytes[d++] = (byte) (i >> 16);

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 69

                          bytes[d++] = (byte) i;

            // If line separator, jump over it.
            if (sepCnt > 0 && ++cc == 19) {
                sIx += 2;
                cc = 0;
            }
        }


            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/FieldSerializer.java
67 issues
The class 'FieldSerializer' has a Standard Cyclomatic Complexity of 11 (Highest = 35).
Design

Line: 32

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class FieldSerializer implements Comparable<FieldSerializer> {

    public final FieldInfo        fieldInfo;
    protected final boolean       writeNull;
    protected int                 features;


            

Reported by PMD.

The class 'FieldSerializer' has a total cyclomatic complexity of 81 (highest 49).
Design

Line: 32

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class FieldSerializer implements Comparable<FieldSerializer> {

    public final FieldInfo        fieldInfo;
    protected final boolean       writeNull;
    protected int                 features;


            

Reported by PMD.

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

Line: 32

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class FieldSerializer implements Comparable<FieldSerializer> {

    public final FieldInfo        fieldInfo;
    protected final boolean       writeNull;
    protected int                 features;


            

Reported by PMD.

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

Line: 34

               */
public class FieldSerializer implements Comparable<FieldSerializer> {

    public final FieldInfo        fieldInfo;
    protected final boolean       writeNull;
    protected int                 features;

    private final String          double_quoted_fieldPrefix;
    private String                single_quoted_fieldPrefix;

            

Reported by PMD.

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

Line: 35

              public class FieldSerializer implements Comparable<FieldSerializer> {

    public final FieldInfo        fieldInfo;
    protected final boolean       writeNull;
    protected int                 features;

    private final String          double_quoted_fieldPrefix;
    private String                single_quoted_fieldPrefix;
    private String                un_quoted_fieldPrefix;

            

Reported by PMD.

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

Line: 36

              
    public final FieldInfo        fieldInfo;
    protected final boolean       writeNull;
    protected int                 features;

    private final String          double_quoted_fieldPrefix;
    private String                single_quoted_fieldPrefix;
    private String                un_quoted_fieldPrefix;


            

Reported by PMD.

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

Line: 38

                  protected final boolean       writeNull;
    protected int                 features;

    private final String          double_quoted_fieldPrefix;
    private String                single_quoted_fieldPrefix;
    private String                un_quoted_fieldPrefix;

    protected BeanContext         fieldContext;


            

Reported by PMD.

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

Line: 39

                  protected int                 features;

    private final String          double_quoted_fieldPrefix;
    private String                single_quoted_fieldPrefix;
    private String                un_quoted_fieldPrefix;

    protected BeanContext         fieldContext;

    private String                format;

            

Reported by PMD.

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

Line: 40

              
    private final String          double_quoted_fieldPrefix;
    private String                single_quoted_fieldPrefix;
    private String                un_quoted_fieldPrefix;

    protected BeanContext         fieldContext;

    private String                format;
    protected boolean             writeEnumUsingToString  = false;

            

Reported by PMD.

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

Line: 42

                  private String                single_quoted_fieldPrefix;
    private String                un_quoted_fieldPrefix;

    protected BeanContext         fieldContext;

    private String                format;
    protected boolean             writeEnumUsingToString  = false;
    protected boolean             writeEnumUsingName      = false;
    protected boolean             disableCircularReferenceDetect = false;

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/MiscCodec.java
67 issues
Avoid reassigning parameters such as 'clazz'
Design

Line: 199

                  }

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
        JSONLexer lexer = parser.lexer;

        if (clazz == InetSocketAddress.class) {
            if (lexer.token() == JSONToken.NULL) {
                lexer.nextToken();

            

Reported by PMD.

Avoid using a branching statement as the last in a loop.
Error

Line: 236

                                  continue;
                }

                break;
            }

            parser.accept(JSONToken.RBRACE);

            return (T) new InetSocketAddress(address, port);

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 16

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

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;

            

Reported by PMD.

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

Line: 56

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
    private static      boolean   FILE_RELATIVE_PATH_SUPPORT = false;
    public final static MiscCodec instance                   = new MiscCodec();
    private static      Method    method_paths_get;
    private static      boolean   method_paths_get_error     = false;


            

Reported by PMD.

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

Line: 56

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
    private static      boolean   FILE_RELATIVE_PATH_SUPPORT = false;
    public final static MiscCodec instance                   = new MiscCodec();
    private static      Method    method_paths_get;
    private static      boolean   method_paths_get_error     = false;


            

Reported by PMD.

Possible God Class (WMC=88, ATFD=75, TCC=0.000%)
Design

Line: 56

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
    private static      boolean   FILE_RELATIVE_PATH_SUPPORT = false;
    public final static MiscCodec instance                   = new MiscCodec();
    private static      Method    method_paths_get;
    private static      boolean   method_paths_get_error     = false;


            

Reported by PMD.

The class 'MiscCodec' has a total cyclomatic complexity of 88 (highest 60).
Design

Line: 56

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
    private static      boolean   FILE_RELATIVE_PATH_SUPPORT = false;
    public final static MiscCodec instance                   = new MiscCodec();
    private static      Method    method_paths_get;
    private static      boolean   method_paths_get_error     = false;


            

Reported by PMD.

The field initializer for 'FILE_RELATIVE_PATH_SUPPORT' is never used (overwritten on line 63)
Design

Line: 57

               * @author wenshao[szujobs@hotmail.com]
 */
public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
    private static      boolean   FILE_RELATIVE_PATH_SUPPORT = false;
    public final static MiscCodec instance                   = new MiscCodec();
    private static      Method    method_paths_get;
    private static      boolean   method_paths_get_error     = false;

    static {

            

Reported by PMD.

Avoid using redundant field initializer for 'FILE_RELATIVE_PATH_SUPPORT'
Performance

Line: 57

               * @author wenshao[szujobs@hotmail.com]
 */
public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
    private static      boolean   FILE_RELATIVE_PATH_SUPPORT = false;
    public final static MiscCodec instance                   = new MiscCodec();
    private static      Method    method_paths_get;
    private static      boolean   method_paths_get_error     = false;

    static {

            

Reported by PMD.

Avoid using redundant field initializer for 'method_paths_get_error'
Performance

Line: 60

                  private static      boolean   FILE_RELATIVE_PATH_SUPPORT = false;
    public final static MiscCodec instance                   = new MiscCodec();
    private static      Method    method_paths_get;
    private static      boolean   method_paths_get_error     = false;

    static {
        FILE_RELATIVE_PATH_SUPPORT = "true".equals(IOUtils.getStringProperty("fastjson.deserializer.fileRelativePathSupport"));
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/test/TestASM.java
66 issues
Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 101

                      mw.visitEnd();

        byte[] code = cw.toByteArray();
        FileOutputStream fos = new FileOutputStream("Example.class");
        fos.write(code);
        fos.close();

        MyClassLoader loader = new MyClassLoader(com.alibaba.fastjson.serializer.ObjectSerializer.class.getClassLoader());


            

Reported by PMD.

System.out.println is used
Design

Line: 50

              
    public void test_asm() throws Exception {
        String text = JSON.toJSONString(EishayEncode.mediaContent);
        System.out.println(text);
    }
    
    public void test_1() throws Exception {
        ClassWriter cw = new ClassWriter();
        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "DateSerializer", "java/lang/Object", new String[] { "com/alibaba/fastjson/serializer/ObjectSerializer" });

            

Reported by PMD.

System.out.println is used
Design

Line: 116

                      Entity obj = new Entity();
        methods[0].invoke(instance, serializer, obj);

        System.out.println(out.toString());
    }

    String getCastType(Class<?> returnType) {
        if (returnType.isPrimitive()) {
            return getWrapperType(returnType);

            

Reported by PMD.

System.out.println is used
Design

Line: 239

                  public static class Foo {

        public void execute() {
            System.out.println("Hello World");
        }
    }

}

            

Reported by PMD.

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

Line: 17

              import com.alibaba.fastjson.serializer.SerializeWriter;
import com.alibaba.json.test.benchmark.encode.EishayEncode;

public class TestASM extends TestCase implements Opcodes {

    // public void test_0() throws Exception {
    //
    // ClassWriter cw = new ClassWriter(0);
    // cw.visit(V1_1, ACC_PUBLIC, "Example", null, "java/lang/Object", null);

            

Reported by PMD.

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

Line: 17

              import com.alibaba.fastjson.serializer.SerializeWriter;
import com.alibaba.json.test.benchmark.encode.EishayEncode;

public class TestASM extends TestCase implements Opcodes {

    // public void test_0() throws Exception {
    //
    // ClassWriter cw = new ClassWriter(0);
    // cw.visit(V1_1, ACC_PUBLIC, "Example", null, "java/lang/Object", null);

            

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

                  // exampleClass.getMethods()[0].invoke(null, new Object[] { null });
    // }

    public void test_asm() throws Exception {
        String text = JSON.toJSONString(EishayEncode.mediaContent);
        System.out.println(text);
    }
    
    public void test_1() throws Exception {

            

Reported by PMD.

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

Line: 48

                  // exampleClass.getMethods()[0].invoke(null, new Object[] { null });
    // }

    public void test_asm() throws Exception {
        String text = JSON.toJSONString(EishayEncode.mediaContent);
        System.out.println(text);
    }
    
    public void test_1() throws Exception {

            

Reported by PMD.

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

Line: 53

                      System.out.println(text);
    }
    
    public void test_1() throws Exception {
        ClassWriter cw = new ClassWriter();
        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "DateSerializer", "java/lang/Object", new String[] { "com/alibaba/fastjson/serializer/ObjectSerializer" });

        MethodVisitor mw = new MethodWriter(cw, ACC_PUBLIC, "<init>", "()V", null, null);
        mw.visitVarInsn(ALOAD, 0);

            

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

                      System.out.println(text);
    }
    
    public void test_1() throws Exception {
        ClassWriter cw = new ClassWriter();
        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "DateSerializer", "java/lang/Object", new String[] { "com/alibaba/fastjson/serializer/ObjectSerializer" });

        MethodVisitor mw = new MethodWriter(cw, ACC_PUBLIC, "<init>", "()V", null, null);
        mw.visitVarInsn(ALOAD, 0);

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/util/RyuDouble.java
62 issues
The class 'RyuDouble' has a Modified Cyclomatic Complexity of 46 (Highest = 82).
Design

Line: 22

              /**
 * An implementation of Ryu for double.
 */
public final class RyuDouble {
    private static final int[][] POW5_SPLIT = new int[326][4];
    private static final int[][] POW5_INV_SPLIT = new int[291][4];

    static {
        BigInteger mask = BigInteger.ONE.shiftLeft(31).subtract(BigInteger.ONE);

            

Reported by PMD.

The class 'RyuDouble' has a total cyclomatic complexity of 97 (highest 96).
Design

Line: 22

              /**
 * An implementation of Ryu for double.
 */
public final class RyuDouble {
    private static final int[][] POW5_SPLIT = new int[326][4];
    private static final int[][] POW5_INV_SPLIT = new int[291][4];

    static {
        BigInteger mask = BigInteger.ONE.shiftLeft(31).subtract(BigInteger.ONE);

            

Reported by PMD.

The class 'RyuDouble' has a Standard Cyclomatic Complexity of 46 (Highest = 82).
Design

Line: 22

              /**
 * An implementation of Ryu for double.
 */
public final class RyuDouble {
    private static final int[][] POW5_SPLIT = new int[326][4];
    private static final int[][] POW5_INV_SPLIT = new int[291][4];

    static {
        BigInteger mask = BigInteger.ONE.shiftLeft(31).subtract(BigInteger.ONE);

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 22

              /**
 * An implementation of Ryu for double.
 */
public final class RyuDouble {
    private static final int[][] POW5_SPLIT = new int[326][4];
    private static final int[][] POW5_INV_SPLIT = new int[291][4];

    static {
        BigInteger mask = BigInteger.ONE.shiftLeft(31).subtract(BigInteger.ONE);

            

Reported by PMD.

Avoid really long methods.
Design

Line: 74

                      return new String(result, 0, len);
    }

    public static int toString(double value, char[] result, int off) {
        final long DOUBLE_MANTISSA_MASK = 4503599627370495L; // (1L << 52) - 1;
        final int DOUBLE_EXPONENT_MASK = 2047; // (1 << 11) - 1;
        final int DOUBLE_EXPONENT_BIAS = 1023; // (1 << (11 - 1)) - 1;
        final long LOG10_5_NUMERATOR = 6989700L; // (long) (10000000L * Math.log10(5));
        final long LOG10_2_NUMERATOR = 3010299L; // (long) (10000000L * Math.log10(2));

            

Reported by PMD.

The method toString() has an NCSS line count of 384
Design

Line: 74

                      return new String(result, 0, len);
    }

    public static int toString(double value, char[] result, int off) {
        final long DOUBLE_MANTISSA_MASK = 4503599627370495L; // (1L << 52) - 1;
        final int DOUBLE_EXPONENT_MASK = 2047; // (1 << 11) - 1;
        final int DOUBLE_EXPONENT_BIAS = 1023; // (1 << (11 - 1)) - 1;
        final long LOG10_5_NUMERATOR = 6989700L; // (long) (10000000L * Math.log10(5));
        final long LOG10_2_NUMERATOR = 3010299L; // (long) (10000000L * Math.log10(2));

            

Reported by PMD.

The method 'toString(double, char, int)' has an NPath complexity of 2147483647, current threshold is 200
Design

Line: 74

                      return new String(result, 0, len);
    }

    public static int toString(double value, char[] result, int off) {
        final long DOUBLE_MANTISSA_MASK = 4503599627370495L; // (1L << 52) - 1;
        final int DOUBLE_EXPONENT_MASK = 2047; // (1 << 11) - 1;
        final int DOUBLE_EXPONENT_BIAS = 1023; // (1 << (11 - 1)) - 1;
        final long LOG10_5_NUMERATOR = 6989700L; // (long) (10000000L * Math.log10(5));
        final long LOG10_2_NUMERATOR = 3010299L; // (long) (10000000L * Math.log10(2));

            

Reported by PMD.

The method 'toString(double, char, int)' has a cyclomatic complexity of 96.
Design

Line: 74

                      return new String(result, 0, len);
    }

    public static int toString(double value, char[] result, int off) {
        final long DOUBLE_MANTISSA_MASK = 4503599627370495L; // (1L << 52) - 1;
        final int DOUBLE_EXPONENT_MASK = 2047; // (1 << 11) - 1;
        final int DOUBLE_EXPONENT_BIAS = 1023; // (1 << (11 - 1)) - 1;
        final long LOG10_5_NUMERATOR = 6989700L; // (long) (10000000L * Math.log10(5));
        final long LOG10_2_NUMERATOR = 3010299L; // (long) (10000000L * Math.log10(2));

            

Reported by PMD.

The method 'toString(double, char, int)' has a NCSS line count of 384.
Design

Line: 74

                      return new String(result, 0, len);
    }

    public static int toString(double value, char[] result, int off) {
        final long DOUBLE_MANTISSA_MASK = 4503599627370495L; // (1L << 52) - 1;
        final int DOUBLE_EXPONENT_MASK = 2047; // (1 << 11) - 1;
        final int DOUBLE_EXPONENT_BIAS = 1023; // (1 << (11 - 1)) - 1;
        final long LOG10_5_NUMERATOR = 6989700L; // (long) (10000000L * Math.log10(5));
        final long LOG10_2_NUMERATOR = 3010299L; // (long) (10000000L * Math.log10(2));

            

Reported by PMD.

The method 'toString' has a Standard Cyclomatic Complexity of 82.
Design

Line: 74

                      return new String(result, 0, len);
    }

    public static int toString(double value, char[] result, int off) {
        final long DOUBLE_MANTISSA_MASK = 4503599627370495L; // (1L << 52) - 1;
        final int DOUBLE_EXPONENT_MASK = 2047; // (1 << 11) - 1;
        final int DOUBLE_EXPONENT_BIAS = 1023; // (1 << (11 - 1)) - 1;
        final long LOG10_5_NUMERATOR = 6989700L; // (long) (10000000L * Math.log10(5));
        final long LOG10_2_NUMERATOR = 3010299L; // (long) (10000000L * Math.log10(2));

            

Reported by PMD.

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

Line: 68

                  public void test_5() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("[1,2,3,null]");
        Object[] array = parser.parseArray(new Type[] { Integer.class, BigDecimal.class, Long.class, String.class });
        Assert.assertEquals(new Integer(1), array[0]);
        Assert.assertEquals(new BigDecimal("2"), array[1]);
        Assert.assertEquals(new Long(3), array[2]);
        Assert.assertEquals(null, array[3]);
    }


            

Reported by PMD.

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

Line: 70

                      Object[] array = parser.parseArray(new Type[] { Integer.class, BigDecimal.class, Long.class, String.class });
        Assert.assertEquals(new Integer(1), array[0]);
        Assert.assertEquals(new BigDecimal("2"), array[1]);
        Assert.assertEquals(new Long(3), array[2]);
        Assert.assertEquals(null, array[3]);
    }

    public void test_error() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("{}");

            

Reported by PMD.

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

Line: 137

                      DefaultJSONParser parser = new DefaultJSONParser("[1,2,3]");
        Object[] array = parser.parseArray(new Type[] { Integer[].class });
        Integer[] values = (Integer[]) array[0];
        Assert.assertEquals(new Integer(1), values[0]);
        Assert.assertEquals(new Integer(2), values[1]);
        Assert.assertEquals(new Integer(3), values[2]);
    }

    public void test_11() throws Exception {

            

Reported by PMD.

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

Line: 138

                      Object[] array = parser.parseArray(new Type[] { Integer[].class });
        Integer[] values = (Integer[]) array[0];
        Assert.assertEquals(new Integer(1), values[0]);
        Assert.assertEquals(new Integer(2), values[1]);
        Assert.assertEquals(new Integer(3), values[2]);
    }

    public void test_11() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("[1]");

            

Reported by PMD.

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

Line: 139

                      Integer[] values = (Integer[]) array[0];
        Assert.assertEquals(new Integer(1), values[0]);
        Assert.assertEquals(new Integer(2), values[1]);
        Assert.assertEquals(new Integer(3), values[2]);
    }

    public void test_11() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("[1]");
        Object[] array = parser.parseArray(new Type[] { String.class });

            

Reported by PMD.

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

Line: 151

                  public void test_12() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("['1']");
        Object[] array = parser.parseArray(new Type[] { int.class });
        Assert.assertEquals(new Integer(1), array[0]);
    }

    public void test_13() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("['1']");
        Object[] array = parser.parseArray(new Type[] { Integer.class });

            

Reported by PMD.

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

Line: 157

                  public void test_13() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("['1']");
        Object[] array = parser.parseArray(new Type[] { Integer.class });
        Assert.assertEquals(new Integer(1), array[0]);
    }

    public void test_14() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("[]");
        Object[] array = parser.parseArray(new Type[] {});

            

Reported by PMD.

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

Line: 180

                      parser.config(Feature.AllowISO8601DateFormat, false);
        Object[] array = parser.parseArray(new Type[] { new TypeReference<List<Integer>>() {
        }.getType() });
        Assert.assertEquals(new Integer(1), ((List<Integer>) (array[0])).get(0));
    }

    public void test_17() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("[]");
        Object[] array = parser.parseArray(new Type[] { Integer[].class });

            

Reported by PMD.

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

Line: 21

              import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.JSONToken;

public class DefaultExtJSONParser_parseArray extends TestCase {

    public void test_0() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("[1,2,,,3]");
        List list = new ArrayList();
        parser.parseArray(int.class, list);

            

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

              
public class DefaultExtJSONParser_parseArray extends TestCase {

    public void test_0() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("[1,2,,,3]");
        List list = new ArrayList();
        parser.parseArray(int.class, list);
        Assert.assertEquals("[1, 2, 3]", list.toString());
    }

            

Reported by PMD.