The following issues were found

src/main/java/com/alibaba/fastjson/asm/ClassWriter.java
40 issues
Too many fields
Design

Line: 36

               * 
 * @author Eric Bruneton
 */
public class ClassWriter {
    /**
     * Minor and major version numbers of the class to be generated.
     */
    int                     version;


            

Reported by PMD.

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

Line: 40

                  /**
     * Minor and major version numbers of the class to be generated.
     */
    int                     version;

    /**
     * Index of the next item to be added in the constant pool.
     */
    int                     index;

            

Reported by PMD.

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

Line: 45

                  /**
     * Index of the next item to be added in the constant pool.
     */
    int                     index;

    /**
     * The constant pool of this class.
     */
    final ByteVector        pool;

            

Reported by PMD.

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

Line: 50

                  /**
     * The constant pool of this class.
     */
    final ByteVector        pool;

    /**
     * The constant pool's hash table data.
     */
    Item[]                  items;

            

Reported by PMD.

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

Line: 55

                  /**
     * The constant pool's hash table data.
     */
    Item[]                  items;

    /**
     * The threshold of the constant pool's hash table.
     */
    int                     threshold;

            

Reported by PMD.

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

Line: 60

                  /**
     * The threshold of the constant pool's hash table.
     */
    int                     threshold;

    /**
     * A reusable key used to look for items in the {@link #items} hash table.
     */
    final Item              key;

            

Reported by PMD.

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

Line: 65

                  /**
     * A reusable key used to look for items in the {@link #items} hash table.
     */
    final Item              key;

    /**
     * A reusable key used to look for items in the {@link #items} hash table.
     */
    final Item              key2;

            

Reported by PMD.

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

Line: 70

                  /**
     * A reusable key used to look for items in the {@link #items} hash table.
     */
    final Item              key2;

    /**
     * A reusable key used to look for items in the {@link #items} hash table.
     */
    final Item              key3;

            

Reported by PMD.

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

Line: 75

                  /**
     * A reusable key used to look for items in the {@link #items} hash table.
     */
    final Item              key3;

    /**
     * A type table used to temporarily store internal names that will not necessarily be stored in the constant pool.
     * This type table is used by the control flow and data flow analysis algorithm used to compute stack map frames
     * from scratch. This array associates to each index <tt>i</tt> the Item whose index is <tt>i</tt>. All Item objects

            

Reported by PMD.

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

Line: 90

                  /**
     * The access flags of this class.
     */
    private int             access;

    /**
     * The constant pool item that contains the internal name of this class.
     */
    private int             name;

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/util/ASMUtils.java
40 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: 15

              import java.lang.reflect.Method;
import java.lang.reflect.Type;

public class ASMUtils {

    public static final String JAVA_VM_NAME = System.getProperty("java.vm.name");
    
    public static final boolean IS_ANDROID = isAndroid(JAVA_VM_NAME);
	

            

Reported by PMD.

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

Line: 15

              import java.lang.reflect.Method;
import java.lang.reflect.Type;

public class ASMUtils {

    public static final String JAVA_VM_NAME = System.getProperty("java.vm.name");
    
    public static final boolean IS_ANDROID = isAndroid(JAVA_VM_NAME);
	

            

Reported by PMD.

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

Line: 15

              import java.lang.reflect.Method;
import java.lang.reflect.Type;

public class ASMUtils {

    public static final String JAVA_VM_NAME = System.getProperty("java.vm.name");
    
    public static final boolean IS_ANDROID = isAndroid(JAVA_VM_NAME);
	

            

Reported by PMD.

When doing a String.toLowerCase()/toUpperCase() call, use a Locale
Error

Line: 26

                          return false;
        }
        
        String lowerVMName = vmName.toLowerCase();
        
        return lowerVMName.contains("dalvik") //
               || lowerVMName.contains("lemur") // aliyun-vm name
        ;
    }

            

Reported by PMD.

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

Line: 28

                      
        String lowerVMName = vmName.toLowerCase();
        
        return lowerVMName.contains("dalvik") //
               || lowerVMName.contains("lemur") // aliyun-vm name
        ;
    }

    public static String desc(Method method) {   

            

Reported by PMD.

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

Line: 29

                      String lowerVMName = vmName.toLowerCase();
        
        return lowerVMName.contains("dalvik") //
               || lowerVMName.contains("lemur") // aliyun-vm name
        ;
    }

    public static String desc(Method method) {   
    	Class<?>[] types = method.getParameterTypes();

            

Reported by PMD.

This for loop can be replaced by a foreach loop
Design

Line: 37

                  	Class<?>[] types = method.getParameterTypes();
        StringBuilder buf = new StringBuilder((types.length + 1) << 4);
        buf.append('(');
        for (int i = 0; i < types.length; ++i) {
            buf.append(desc(types[i]));
        }
        buf.append(')');
        buf.append(desc(method.getReturnType()));
        return buf.toString();

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 40

                      for (int i = 0; i < types.length; ++i) {
            buf.append(desc(types[i]));
        }
        buf.append(')');
        buf.append(desc(method.getReturnType()));
        return buf.toString();
    }

    public static String desc(Class<?> returnType) {

            

Reported by PMD.

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

Line: 61

                      } else {
            if (!parameterType.isPrimitive()) {
                String clsName = parameterType.getName();
                return clsName.replace('.', '/'); // 直接基于字符串替换,不使用正则替换
            } else {
                return getPrimitiveLetter(parameterType);
            }
        }
    }

            

Reported by PMD.

The method 'getPrimitiveLetter(Class)' has a cyclomatic complexity of 11.
Design

Line: 69

                  }
    

    public static String getPrimitiveLetter(Class<?> type) {
        if (Integer.TYPE == type) {
            return "I";
        } else if (Void.TYPE == type) {
            return "V";
        } else if (Boolean.TYPE == type) {

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/SerializeFilterable.java
40 issues
Avoid reassigning parameters such as 'key'
Design

Line: 179

                  
    protected String processKey(JSONSerializer jsonBeanDeser, //
                             Object object, //
                             String key, //
                             Object propertyValue) {

        if (jsonBeanDeser.nameFilters != null) {
            for (NameFilter nameFilter : jsonBeanDeser.nameFilters) {
                key = nameFilter.process(object, key, propertyValue);

            

Reported by PMD.

Avoid reassigning parameters such as 'key'
Design

Line: 179

                  
    protected String processKey(JSONSerializer jsonBeanDeser, //
                             Object object, //
                             String key, //
                             Object propertyValue) {

        if (jsonBeanDeser.nameFilters != null) {
            for (NameFilter nameFilter : jsonBeanDeser.nameFilters) {
                key = nameFilter.process(object, key, propertyValue);

            

Reported by PMD.

Avoid reassigning parameters such as 'propertyValue'
Design

Line: 209

                                             BeanContext beanContext,
                               Object object, //
                               String key, //
                               Object propertyValue, //
                               int features) {

        if (propertyValue != null) {
            if ((SerializerFeature.isEnabled(jsonBeanDeser.out.features, features, SerializerFeature.WriteNonStringValueAsString)  //
                    || (beanContext != null && (beanContext.getFeatures() & SerializerFeature.WriteNonStringValueAsString.mask) != 0))

            

Reported by PMD.

Avoid reassigning parameters such as 'propertyValue'
Design

Line: 209

                                             BeanContext beanContext,
                               Object object, //
                               String key, //
                               Object propertyValue, //
                               int features) {

        if (propertyValue != null) {
            if ((SerializerFeature.isEnabled(jsonBeanDeser.out.features, features, SerializerFeature.WriteNonStringValueAsString)  //
                    || (beanContext != null && (beanContext.getFeatures() & SerializerFeature.WriteNonStringValueAsString.mask) != 0))

            

Reported by PMD.

Avoid reassigning parameters such as 'propertyValue'
Design

Line: 209

                                             BeanContext beanContext,
                               Object object, //
                               String key, //
                               Object propertyValue, //
                               int features) {

        if (propertyValue != null) {
            if ((SerializerFeature.isEnabled(jsonBeanDeser.out.features, features, SerializerFeature.WriteNonStringValueAsString)  //
                    || (beanContext != null && (beanContext.getFeatures() & SerializerFeature.WriteNonStringValueAsString.mask) != 0))

            

Reported by PMD.

Avoid reassigning parameters such as 'propertyValue'
Design

Line: 209

                                             BeanContext beanContext,
                               Object object, //
                               String key, //
                               Object propertyValue, //
                               int features) {

        if (propertyValue != null) {
            if ((SerializerFeature.isEnabled(jsonBeanDeser.out.features, features, SerializerFeature.WriteNonStringValueAsString)  //
                    || (beanContext != null && (beanContext.getFeatures() & SerializerFeature.WriteNonStringValueAsString.mask) != 0))

            

Reported by PMD.

Avoid reassigning parameters such as 'propertyValue'
Design

Line: 209

                                             BeanContext beanContext,
                               Object object, //
                               String key, //
                               Object propertyValue, //
                               int features) {

        if (propertyValue != null) {
            if ((SerializerFeature.isEnabled(jsonBeanDeser.out.features, features, SerializerFeature.WriteNonStringValueAsString)  //
                    || (beanContext != null && (beanContext.getFeatures() & SerializerFeature.WriteNonStringValueAsString.mask) != 0))

            

Reported by PMD.

Avoid reassigning parameters such as 'propertyValue'
Design

Line: 209

                                             BeanContext beanContext,
                               Object object, //
                               String key, //
                               Object propertyValue, //
                               int features) {

        if (propertyValue != null) {
            if ((SerializerFeature.isEnabled(jsonBeanDeser.out.features, features, SerializerFeature.WriteNonStringValueAsString)  //
                    || (beanContext != null && (beanContext.getFeatures() & SerializerFeature.WriteNonStringValueAsString.mask) != 0))

            

Reported by PMD.

Avoid reassigning parameters such as 'propertyValue'
Design

Line: 209

                                             BeanContext beanContext,
                               Object object, //
                               String key, //
                               Object propertyValue, //
                               int features) {

        if (propertyValue != null) {
            if ((SerializerFeature.isEnabled(jsonBeanDeser.out.features, features, SerializerFeature.WriteNonStringValueAsString)  //
                    || (beanContext != null && (beanContext.getFeatures() & SerializerFeature.WriteNonStringValueAsString.mask) != 0))

            

Reported by PMD.

This abstract class does not have any abstract methods
Design

Line: 9

              
import com.alibaba.fastjson.JSON;

public abstract class SerializeFilterable {

    protected List<BeforeFilter>       beforeFilters       = null;
    protected List<AfterFilter>        afterFilters        = null;
    protected List<PropertyFilter>     propertyFilters     = null;
    protected List<ValueFilter>        valueFilters        = null;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_scanFieldStringArray.java
40 issues
This class has too many methods, consider refactoring it.
Design

Line: 11

              import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;

public class JSONScannerTest_scanFieldStringArray extends TestCase {

    public void test_string() throws Exception {
        String text = "{\"value\":[1]}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());

            

Reported by PMD.

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

Line: 13

              
public class JSONScannerTest_scanFieldStringArray extends TestCase {

    public void test_string() throws Exception {
        String text = "{\"value\":[1]}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }


            

Reported by PMD.

The String literal '[1]' appears 5 times in this file; the first occurrence is on line 16
Error

Line: 16

                  public void test_string() throws Exception {
        String text = "{\"value\":[1]}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }

    public void test_string_1() throws Exception {
        String text = "{\"value\":[\"1\"]}";
        VO obj = JSON.parseObject(text, VO.class);

            

Reported by PMD.

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

Line: 16

                  public void test_string() throws Exception {
        String text = "{\"value\":[1]}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }

    public void test_string_1() throws Exception {
        String text = "{\"value\":[\"1\"]}";
        VO obj = JSON.parseObject(text, VO.class);

            

Reported by PMD.

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

Line: 16

                  public void test_string() throws Exception {
        String text = "{\"value\":[1]}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }

    public void test_string_1() throws Exception {
        String text = "{\"value\":[\"1\"]}";
        VO obj = JSON.parseObject(text, VO.class);

            

Reported by PMD.

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

Line: 19

                      Assert.assertEquals("[1]", obj.getValue().toString());
    }

    public void test_string_1() throws Exception {
        String text = "{\"value\":[\"1\"]}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }
    

            

Reported by PMD.

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

Line: 22

                  public void test_string_1() throws Exception {
        String text = "{\"value\":[\"1\"]}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }
    
    public void test_string_2() throws Exception {
        String text = "{\"value\":['1']}";
        VO obj = JSON.parseObject(text, VO.class);

            

Reported by PMD.

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

Line: 22

                  public void test_string_1() throws Exception {
        String text = "{\"value\":[\"1\"]}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }
    
    public void test_string_2() throws Exception {
        String text = "{\"value\":['1']}";
        VO obj = JSON.parseObject(text, VO.class);

            

Reported by PMD.

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

Line: 25

                      Assert.assertEquals("[1]", obj.getValue().toString());
    }
    
    public void test_string_2() throws Exception {
        String text = "{\"value\":['1']}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }
    

            

Reported by PMD.

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

Line: 28

                  public void test_string_2() throws Exception {
        String text = "{\"value\":['1']}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("[1]", obj.getValue().toString());
    }
    
    public void test_string_3() throws Exception {
        String text = "{\"value\":[\"1\\t2\"]}";
        VO obj = JSON.parseObject(text, VO.class);

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/ObjectArrayCodec.java
40 issues
The class 'ObjectArrayCodec' has a Standard Cyclomatic Complexity of 7 (Highest = 12).
Design

Line: 35

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

    public static final ObjectArrayCodec instance = new ObjectArrayCodec();

    public ObjectArrayCodec(){
    }

            

Reported by PMD.

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

Line: 35

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

    public static final ObjectArrayCodec instance = new ObjectArrayCodec();

    public ObjectArrayCodec(){
    }

            

Reported by PMD.

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

Line: 42

                  public ObjectArrayCodec(){
    }

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

        Object[] array = (Object[]) object;


            

Reported by PMD.

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

Line: 42

                  public ObjectArrayCodec(){
    }

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

        Object[] array = (Object[]) object;


            

Reported by PMD.

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

Line: 42

                  public ObjectArrayCodec(){
    }

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

        Object[] array = (Object[]) object;


            

Reported by PMD.

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

Line: 42

                  public ObjectArrayCodec(){
    }

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

        Object[] array = (Object[]) object;


            

Reported by PMD.

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

Line: 95

                                  if (serializer.containsReference(item)) {
                        serializer.writeReference(item);
                    } else {
                        Class<?> clazz = item.getClass();

                        if (clazz == preClazz) {
                            preWriter.write(serializer, item, i, null, 0);
                        } else {
                            preClazz = clazz;

            

Reported by PMD.

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

Line: 98

                                      Class<?> clazz = item.getClass();

                        if (clazz == preClazz) {
                            preWriter.write(serializer, item, i, null, 0);
                        } else {
                            preClazz = clazz;
                            preWriter = serializer.getObjectWriter(clazz);

                            preWriter.write(serializer, item, i, null, 0);

            

Reported by PMD.

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

Line: 103

                                          preClazz = clazz;
                            preWriter = serializer.getObjectWriter(clazz);

                            preWriter.write(serializer, item, i, null, 0);
                        }
                    }
                    out.append(',');
                }
            }

            

Reported by PMD.

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

Line: 128

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

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/date/DateFieldTest10.java
40 issues
JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 16

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

    public void test_for_zero() throws Exception {

            

Reported by PMD.

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

Line: 21

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_for_zero() throws Exception {
        String text = "{\"date\":\"0000-00-00\"}";

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Object object = format.parse("0000-00-00");
        JSON.parseObject(text, Model.class);

            

Reported by PMD.

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

Line: 21

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_for_zero() throws Exception {
        String text = "{\"date\":\"0000-00-00\"}";

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Object object = format.parse("0000-00-00");
        JSON.parseObject(text, Model.class);

            

Reported by PMD.

When instantiating a SimpleDateFormat object, specify a Locale
Error

Line: 24

                  public void test_for_zero() throws Exception {
        String text = "{\"date\":\"0000-00-00\"}";

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Object object = format.parse("0000-00-00");
        JSON.parseObject(text, Model.class);
    }

    public void test_1() throws Exception {

            

Reported by PMD.

Avoid unused local variables such as 'object'.
Design

Line: 25

                      String text = "{\"date\":\"0000-00-00\"}";

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Object object = format.parse("0000-00-00");
        JSON.parseObject(text, Model.class);
    }

    public void test_1() throws Exception {
        String text = "{\"date\":\"2017-08-14 19:05:30.000|America/Los_Angeles\"}";

            

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

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

    public void test_1() throws Exception {
        String text = "{\"date\":\"2017-08-14 19:05:30.000|America/Los_Angeles\"}";
        JSON.parseObject(text, Model.class);
    }

    public void test_2() throws Exception {

            

Reported by PMD.

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

Line: 29

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

    public void test_1() throws Exception {
        String text = "{\"date\":\"2017-08-14 19:05:30.000|America/Los_Angeles\"}";
        JSON.parseObject(text, Model.class);
    }

    public void test_2() throws Exception {

            

Reported by PMD.

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

Line: 34

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

    public void test_2() throws Exception {
        String text = "{\"date\":\"2017-08-16T04:29Z\"}";
        Model model = JSON.parseObject(text, Model.class);

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Object object = format.parse("2017-08-16 04:29");

            

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

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

    public void test_2() throws Exception {
        String text = "{\"date\":\"2017-08-16T04:29Z\"}";
        Model model = JSON.parseObject(text, Model.class);

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Object object = format.parse("2017-08-16 04:29");

            

Reported by PMD.

Avoid unused local variables such as 'model'.
Design

Line: 36

              
    public void test_2() throws Exception {
        String text = "{\"date\":\"2017-08-16T04:29Z\"}";
        Model model = JSON.parseObject(text, Model.class);

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Object object = format.parse("2017-08-16 04:29");
//        assertEquals(object, model.date);
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_symbol.java
40 issues
This class has too many methods, consider refactoring it.
Design

Line: 15

               * 
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONScannerTest_symbol extends TestCase {

    public void test_0() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"name\"");

            

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

               */
public class JSONScannerTest_symbol extends TestCase {

    public void test_0() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("name".equals(symbol));

            

Reported by PMD.

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

Line: 26

                      lexer.close();
    }

    public void test_1() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"nick name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("nick name".equals(symbol));

            

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

                      lexer.close();
    }

    public void test_2() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"nick \\\"name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("nick \"name" == symbol);

            

Reported by PMD.

Use equals() to compare strings instead of '==' or '!='
Error

Line: 40

              
        JSONScanner lexer = new JSONScanner("\"nick \\\"name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("nick \"name" == symbol);
        lexer.close();
    }

    public void test_3() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 40

              
        JSONScanner lexer = new JSONScanner("\"nick \\\"name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("nick \"name" == symbol);
        lexer.close();
    }

    public void test_3() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

            

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

                      lexer.close();
    }

    public void test_3() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"nick \\\\name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("nick \\name" == symbol);

            

Reported by PMD.

Use equals() to compare strings instead of '==' or '!='
Error

Line: 49

              
        JSONScanner lexer = new JSONScanner("\"nick \\\\name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("nick \\name" == symbol);
        lexer.close();
    }

    public void test_4() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 49

              
        JSONScanner lexer = new JSONScanner("\"nick \\\\name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("nick \\name" == symbol);
        lexer.close();
    }

    public void test_4() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

            

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

                      lexer.close();
    }

    public void test_4() throws Exception {
        SymbolTable symbolTable = new SymbolTable(512);

        JSONScanner lexer = new JSONScanner("\"nick \\/name\"");
        String symbol = lexer.scanSymbol(symbolTable, '"');
        Assert.assertTrue("nick /name" == symbol);

            

Reported by PMD.

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

Line: 154

                      Assert.assertEquals(3, array.getByteValue("2"));
        Assert.assertEquals(3, array.getShort("2").shortValue());
        Assert.assertEquals(3, array.getShortValue("2"));
        Assert.assertEquals(new Integer(222), array.getInteger("1"));
        Assert.assertEquals(new Long(222), array.getLong("1"));
        Assert.assertEquals(new BigDecimal("222"), array.getBigDecimal("1"));

        Assert.assertEquals(true, array.getBooleanValue("4"));
        Assert.assertTrue(2.0F == array.getFloat("5").floatValue());

            

Reported by PMD.

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

Line: 155

                      Assert.assertEquals(3, array.getShort("2").shortValue());
        Assert.assertEquals(3, array.getShortValue("2"));
        Assert.assertEquals(new Integer(222), array.getInteger("1"));
        Assert.assertEquals(new Long(222), array.getLong("1"));
        Assert.assertEquals(new BigDecimal("222"), array.getBigDecimal("1"));

        Assert.assertEquals(true, array.getBooleanValue("4"));
        Assert.assertTrue(2.0F == array.getFloat("5").floatValue());
        Assert.assertTrue(2.0F == array.getFloatValue("5"));

            

Reported by PMD.

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

Line: 29

              
import com.alibaba.fastjson.JSONObject;

public class JSONObjectTest extends TestCase {

    public void test_toJSONObject() throws Exception {
        {
            Assert.assertNull(JSONObject.parse(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: 31

              
public class JSONObjectTest extends TestCase {

    public void test_toJSONObject() throws Exception {
        {
            Assert.assertNull(JSONObject.parse(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: 37

                      }
    }

    public void test_writeJSONString() throws Exception {
        {
            StringWriter out = new StringWriter();
            new JSONObject().writeJSONString(out);
            Assert.assertEquals("{}", out.toString());
        }

            

Reported by PMD.

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

Line: 45

                      }
    }

    public void test_getLong() throws Exception {
        JSONObject json = new JSONObject(true);
        json.put("A", 55L);
        json.put("B", 55);
        json.put("K", true);
        Assert.assertEquals(json.getLong("A").longValue(), 55L);

            

Reported by PMD.

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

Line: 50

                      json.put("A", 55L);
        json.put("B", 55);
        json.put("K", true);
        Assert.assertEquals(json.getLong("A").longValue(), 55L);
        Assert.assertEquals(json.getLong("B").longValue(), 55L);
        Assert.assertEquals(json.getLong("C"), null);
        Assert.assertEquals(json.getBooleanValue("K"), true);
        Assert.assertEquals(json.getBoolean("K"), Boolean.TRUE);
    }

            

Reported by PMD.

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

Line: 51

                      json.put("B", 55);
        json.put("K", true);
        Assert.assertEquals(json.getLong("A").longValue(), 55L);
        Assert.assertEquals(json.getLong("B").longValue(), 55L);
        Assert.assertEquals(json.getLong("C"), null);
        Assert.assertEquals(json.getBooleanValue("K"), true);
        Assert.assertEquals(json.getBoolean("K"), Boolean.TRUE);
    }


            

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

                      Assert.assertEquals(json.getBoolean("K"), Boolean.TRUE);
    }

    public void test_getLong_1() throws Exception {
        JSONObject json = new JSONObject(false);
        json.put("A", 55L);
        json.put("B", 55);
        Assert.assertEquals(json.getLong("A").longValue(), 55L);
        Assert.assertEquals(json.getLong("B").longValue(), 55L);

            

Reported by PMD.

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

Line: 61

                      JSONObject json = new JSONObject(false);
        json.put("A", 55L);
        json.put("B", 55);
        Assert.assertEquals(json.getLong("A").longValue(), 55L);
        Assert.assertEquals(json.getLong("B").longValue(), 55L);
        Assert.assertEquals(json.getLong("C"), null);
    }

    public void test_getDate() throws Exception {

            

Reported by PMD.

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

Line: 9

              import java.net.InetSocketAddress;

public class JSONPath_extract_1 extends TestCase {
    public void test_0() throws Exception {
        String json = "[{\"id\":1001},{\"id\":1002},{\"id\":1003},[1],123,-4,\"a\\\"bc\"]";

        assertEquals("{\"id\":1001}"
                , JSONPath.extract(json, "$.0")
                    .toString());

            

Reported by PMD.

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

Line: 9

              import java.net.InetSocketAddress;

public class JSONPath_extract_1 extends TestCase {
    public void test_0() throws Exception {
        String json = "[{\"id\":1001},{\"id\":1002},{\"id\":1003},[1],123,-4,\"a\\\"bc\"]";

        assertEquals("{\"id\":1001}"
                , JSONPath.extract(json, "$.0")
                    .toString());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

                  public void test_0() throws Exception {
        String json = "[{\"id\":1001},{\"id\":1002},{\"id\":1003},[1],123,-4,\"a\\\"bc\"]";

        assertEquals("{\"id\":1001}"
                , JSONPath.extract(json, "$.0")
                    .toString());

        assertEquals("{\"id\":1002}"
                , JSONPath.extract(json, "$.1")

            

Reported by PMD.

The String literal '$.0' appears 4 times in this file; the first occurrence is on line 13
Error

Line: 13

                      String json = "[{\"id\":1001},{\"id\":1002},{\"id\":1003},[1],123,-4,\"a\\\"bc\"]";

        assertEquals("{\"id\":1001}"
                , JSONPath.extract(json, "$.0")
                    .toString());

        assertEquals("{\"id\":1002}"
                , JSONPath.extract(json, "$.1")
                        .toString());

            

Reported by PMD.

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

Line: 13

                      String json = "[{\"id\":1001},{\"id\":1002},{\"id\":1003},[1],123,-4,\"a\\\"bc\"]";

        assertEquals("{\"id\":1001}"
                , JSONPath.extract(json, "$.0")
                    .toString());

        assertEquals("{\"id\":1002}"
                , JSONPath.extract(json, "$.1")
                        .toString());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                              , JSONPath.extract(json, "$.0")
                    .toString());

        assertEquals("{\"id\":1002}"
                , JSONPath.extract(json, "$.1")
                        .toString());


        assertEquals("{\"id\":1003}"

            

Reported by PMD.

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

Line: 17

                                  .toString());

        assertEquals("{\"id\":1002}"
                , JSONPath.extract(json, "$.1")
                        .toString());


        assertEquals("{\"id\":1003}"
                , JSONPath.extract(json, "$.2")

            

Reported by PMD.

The String literal '$.1' appears 4 times in this file; the first occurrence is on line 17
Error

Line: 17

                                  .toString());

        assertEquals("{\"id\":1002}"
                , JSONPath.extract(json, "$.1")
                        .toString());


        assertEquals("{\"id\":1003}"
                , JSONPath.extract(json, "$.2")

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                                      .toString());


        assertEquals("{\"id\":1003}"
                , JSONPath.extract(json, "$.2")
                        .toString());

        assertEquals("[1]"
                , JSONPath.extract(json, "$.3")

            

Reported by PMD.

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

Line: 22

              

        assertEquals("{\"id\":1003}"
                , JSONPath.extract(json, "$.2")
                        .toString());

        assertEquals("[1]"
                , JSONPath.extract(json, "$.3")
                        .toString());

            

Reported by PMD.

src/test/java/com/alibaba/json/test/JsonIteratorImageTest.java
39 issues
System.out.println is used
Design

Line: 43

                          long startMillis = System.currentTimeMillis();
            fastjson();
            long millis = System.currentTimeMillis() - startMillis;
            System.out.println("fastjson : " + millis);
        }

//        jsoniterator();
//        for (int i = 0; i < 5; ++i) {
//            long startMillis = System.currentTimeMillis();

            

Reported by PMD.

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

Line: 20

               * Created by wenshao on 27/12/2016.
 */
public class JsonIteratorImageTest extends TestCase {
    private String input = "{\"bitrate\":262144,\"duration\":18000000,\"format\":\"video/mpg4\",\"height\":480,\"persons\":[\"Bill Gates\",\"Steve Jobs\"],\"player\":\"JAVA\",\"size\":58982400,\"title\":\"Javaone Keynote\",\"uri\":\"http://javaone.com/keynote.mpg\",\"width\":640}";
    private byte[] inputBytes = input.getBytes();
    private TypeLiteral<Model> modelTypeLiteral; // this is thread-safe can reused
    private JsonIterator iter;

    private int COUNT = 1000 * 1000 * 1;

            

Reported by PMD.

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

Line: 20

               * Created by wenshao on 27/12/2016.
 */
public class JsonIteratorImageTest extends TestCase {
    private String input = "{\"bitrate\":262144,\"duration\":18000000,\"format\":\"video/mpg4\",\"height\":480,\"persons\":[\"Bill Gates\",\"Steve Jobs\"],\"player\":\"JAVA\",\"size\":58982400,\"title\":\"Javaone Keynote\",\"uri\":\"http://javaone.com/keynote.mpg\",\"width\":640}";
    private byte[] inputBytes = input.getBytes();
    private TypeLiteral<Model> modelTypeLiteral; // this is thread-safe can reused
    private JsonIterator iter;

    private int COUNT = 1000 * 1000 * 1;

            

Reported by PMD.

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

Line: 21

               */
public class JsonIteratorImageTest extends TestCase {
    private String input = "{\"bitrate\":262144,\"duration\":18000000,\"format\":\"video/mpg4\",\"height\":480,\"persons\":[\"Bill Gates\",\"Steve Jobs\"],\"player\":\"JAVA\",\"size\":58982400,\"title\":\"Javaone Keynote\",\"uri\":\"http://javaone.com/keynote.mpg\",\"width\":640}";
    private byte[] inputBytes = input.getBytes();
    private TypeLiteral<Model> modelTypeLiteral; // this is thread-safe can reused
    private JsonIterator iter;

    private int COUNT = 1000 * 1000 * 1;


            

Reported by PMD.

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

Line: 22

              public class JsonIteratorImageTest extends TestCase {
    private String input = "{\"bitrate\":262144,\"duration\":18000000,\"format\":\"video/mpg4\",\"height\":480,\"persons\":[\"Bill Gates\",\"Steve Jobs\"],\"player\":\"JAVA\",\"size\":58982400,\"title\":\"Javaone Keynote\",\"uri\":\"http://javaone.com/keynote.mpg\",\"width\":640}";
    private byte[] inputBytes = input.getBytes();
    private TypeLiteral<Model> modelTypeLiteral; // this is thread-safe can reused
    private JsonIterator iter;

    private int COUNT = 1000 * 1000 * 1;

    protected void setUp() throws Exception {

            

Reported by PMD.

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

Line: 23

                  private String input = "{\"bitrate\":262144,\"duration\":18000000,\"format\":\"video/mpg4\",\"height\":480,\"persons\":[\"Bill Gates\",\"Steve Jobs\"],\"player\":\"JAVA\",\"size\":58982400,\"title\":\"Javaone Keynote\",\"uri\":\"http://javaone.com/keynote.mpg\",\"width\":640}";
    private byte[] inputBytes = input.getBytes();
    private TypeLiteral<Model> modelTypeLiteral; // this is thread-safe can reused
    private JsonIterator iter;

    private int COUNT = 1000 * 1000 * 1;

    protected void setUp() throws Exception {
        inputBytes = input.getBytes();

            

Reported by PMD.

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

Line: 25

                  private TypeLiteral<Model> modelTypeLiteral; // this is thread-safe can reused
    private JsonIterator iter;

    private int COUNT = 1000 * 1000 * 1;

    protected void setUp() throws Exception {
        inputBytes = input.getBytes();
        iter = new JsonIterator();
        modelTypeLiteral = new TypeLiteral<Model>() {

            

Reported by PMD.

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

Line: 25

                  private TypeLiteral<Model> modelTypeLiteral; // this is thread-safe can reused
    private JsonIterator iter;

    private int COUNT = 1000 * 1000 * 1;

    protected void setUp() throws Exception {
        inputBytes = input.getBytes();
        iter = new JsonIterator();
        modelTypeLiteral = new TypeLiteral<Model>() {

            

Reported by PMD.

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

Line: 27

              
    private int COUNT = 1000 * 1000 * 1;

    protected void setUp() throws Exception {
        inputBytes = input.getBytes();
        iter = new JsonIterator();
        modelTypeLiteral = new TypeLiteral<Model>() {
        };
    }

            

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

                      };
    }

    public void test_for_iterator() throws Exception {
        iter.reset(inputBytes);
        Model m2 = iter.read(modelTypeLiteral);

        fastjson();
        for (int i = 0; i < 5; ++i) {

            

Reported by PMD.