The following issues were found

src/test/java/com/alibaba/json/bvt/ArrayRefTest.java
8 issues
System.out.println is used
Design

Line: 33

                          text = JSON.toJSONString(groups);
        }
        
        System.out.println(text);
        
        List<Group> groups = JSON.parseObject(text, new TypeReference<List<Group>>() {});
        Assert.assertEquals(6, groups.size());
        
        Assert.assertEquals(0, groups.get(0).getId());

            

Reported by PMD.

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

Line: 14

              
public class ArrayRefTest extends TestCase {

    public void test_0() throws Exception {
        String text;
        {
            List<Group> groups = new ArrayList<Group>();
            
            Group g0 = new Group(0);

            

Reported by PMD.

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

Line: 38

                      List<Group> groups = JSON.parseObject(text, new TypeReference<List<Group>>() {});
        Assert.assertEquals(6, groups.size());
        
        Assert.assertEquals(0, groups.get(0).getId());
        Assert.assertEquals(1, groups.get(1).getId());
        Assert.assertEquals(2, groups.get(2).getId());
        Assert.assertEquals(0, groups.get(3).getId());
        Assert.assertEquals(1, groups.get(4).getId());
        Assert.assertEquals(2, groups.get(5).getId());

            

Reported by PMD.

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

Line: 39

                      Assert.assertEquals(6, groups.size());
        
        Assert.assertEquals(0, groups.get(0).getId());
        Assert.assertEquals(1, groups.get(1).getId());
        Assert.assertEquals(2, groups.get(2).getId());
        Assert.assertEquals(0, groups.get(3).getId());
        Assert.assertEquals(1, groups.get(4).getId());
        Assert.assertEquals(2, groups.get(5).getId());
    }

            

Reported by PMD.

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

Line: 40

                      
        Assert.assertEquals(0, groups.get(0).getId());
        Assert.assertEquals(1, groups.get(1).getId());
        Assert.assertEquals(2, groups.get(2).getId());
        Assert.assertEquals(0, groups.get(3).getId());
        Assert.assertEquals(1, groups.get(4).getId());
        Assert.assertEquals(2, groups.get(5).getId());
    }


            

Reported by PMD.

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

Line: 41

                      Assert.assertEquals(0, groups.get(0).getId());
        Assert.assertEquals(1, groups.get(1).getId());
        Assert.assertEquals(2, groups.get(2).getId());
        Assert.assertEquals(0, groups.get(3).getId());
        Assert.assertEquals(1, groups.get(4).getId());
        Assert.assertEquals(2, groups.get(5).getId());
    }

    public static class Group {

            

Reported by PMD.

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

Line: 42

                      Assert.assertEquals(1, groups.get(1).getId());
        Assert.assertEquals(2, groups.get(2).getId());
        Assert.assertEquals(0, groups.get(3).getId());
        Assert.assertEquals(1, groups.get(4).getId());
        Assert.assertEquals(2, groups.get(5).getId());
    }

    public static class Group {


            

Reported by PMD.

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

Line: 43

                      Assert.assertEquals(2, groups.get(2).getId());
        Assert.assertEquals(0, groups.get(3).getId());
        Assert.assertEquals(1, groups.get(4).getId());
        Assert.assertEquals(2, groups.get(5).getId());
    }

    public static class Group {

        private int id;

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 11/03/2017.
 */
public class Issue1063 extends TestCase {
    public void test_for_issue() throws Exception {
        long currentMillis = System.currentTimeMillis();
        TimestampBean bean = new TimestampBean();
        bean.setTimestamp(new Timestamp(currentMillis));
        String timestampJson = JSON.toJSONString(bean);


            

Reported by PMD.

Avoid unused local variables such as 'beanOfJSON'.
Design

Line: 21

                      String timestampJson = JSON.toJSONString(bean);

        // 这里能转换成功
        TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);

        // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);

            

Reported by PMD.

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

Line: 25

              
        // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
    }

    public static class TimestampBean {
        private Timestamp timestamp = null;

            

Reported by PMD.

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

Line: 26

                      // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
    }

    public static class TimestampBean {
        private Timestamp timestamp = null;


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                      // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
    }

    public static class TimestampBean {
        private Timestamp timestamp = null;


            

Reported by PMD.

Avoid using redundant field initializer for 'timestamp'
Performance

Line: 30

                  }

    public static class TimestampBean {
        private Timestamp timestamp = null;

        public Timestamp getTimestamp() {
            return timestamp;
        }


            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.serializer.SerializerFeature'
Design

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.sql.Timestamp;

/**

            

Reported by PMD.

Found 'DU'-anomaly for variable 'beanOfJSON' (lines '21'-'27').
Error

Line: 21

                      String timestampJson = JSON.toJSONString(bean);

        // 这里能转换成功
        TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);

        // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);

            

Reported by PMD.

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

Line: 17

                      to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

            

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

              

public class Issue87_treeset extends TestCase {
    public void test_for_issue() throws Exception {
        TestObject to = new TestObject();
        to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(text);

            

Reported by PMD.

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

Line: 12

              

public class Issue87_treeset extends TestCase {
    public void test_for_issue() throws Exception {
        TestObject to = new TestObject();
        to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(text);

            

Reported by PMD.

The value assigned to variable 'to' is never used
Design

Line: 19

                      String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

        private TreeSet<String> set = new TreeSet<String>();

            

Reported by PMD.

Avoid using implementation types like 'TreeSet'; use the interface instead
Design

Line: 24

                  
    public static class TestObject {

        private TreeSet<String> set = new TreeSet<String>();

        public TreeSet<String> getSet() {
            return set;
        }


            

Reported by PMD.

Avoid using implementation types like 'TreeSet'; use the interface instead
Design

Line: 26

              
        private TreeSet<String> set = new TreeSet<String>();

        public TreeSet<String> getSet() {
            return set;
        }

        public void setSet(TreeSet<String> set) {
            this.set = set;

            

Reported by PMD.

Avoid using implementation types like 'TreeSet'; use the interface instead
Design

Line: 30

                          return set;
        }

        public void setSet(TreeSet<String> set) {
            this.set = set;
        }

        public void add(String str) {
            set.add(str);

            

Reported by PMD.

Found 'DU'-anomaly for variable 'to' (lines '19'-'20').
Error

Line: 19

                      String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

        private TreeSet<String> set = new TreeSet<String>();

            

Reported by PMD.

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

Line: 13

              
public class LongFieldTest_primitive extends TestCase {

	public void test_codec() throws Exception {
		V0 v = new V0();
		v.setValue(1001L);

		String text = JSON.toJSONString(v);


            

Reported by PMD.

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

Line: 21

              
		V0 v1 = JSON.parseObject(text, V0.class);

		Assert.assertEquals(v1.getValue(), v.getValue());
	}

	public void test_codec_null() throws Exception {
		V0 v = new V0();


            

Reported by PMD.

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

Line: 24

              		Assert.assertEquals(v1.getValue(), v.getValue());
	}

	public void test_codec_null() throws Exception {
		V0 v = new V0();

		SerializeConfig mapping = new SerializeConfig();
		mapping.setAsmEnable(false);


            

Reported by PMD.

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

Line: 36

              
		V0 v1 = JSON.parseObject(text, V0.class);

		Assert.assertEquals(v1.getValue(), v.getValue());
	}

	public void test_codec_null_asm() throws Exception {
		V0 v = new V0();


            

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

              		Assert.assertEquals(v1.getValue(), v.getValue());
	}

	public void test_codec_null_asm() throws Exception {
		V0 v = new V0();

		SerializeConfig mapping = new SerializeConfig();
		mapping.setAsmEnable(true);


            

Reported by PMD.

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

Line: 55

              		V0 v1 = JSON.parseObject(text, V0.class, config,
				JSON.DEFAULT_PARSER_FEATURE);

		Assert.assertEquals(v1.getValue(), v.getValue());
	}

	public void test_codec_null_1() throws Exception {
		V0 v = new V0();


            

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

              		Assert.assertEquals(v1.getValue(), v.getValue());
	}

	public void test_codec_null_1() throws Exception {
		V0 v = new V0();

		SerializeConfig mapping = new SerializeConfig();
		mapping.setAsmEnable(false);


            

Reported by PMD.

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

Line: 71

              
		V0 v1 = JSON.parseObject(text, V0.class);

		Assert.assertEquals(123, v1.getValue());
	}

	public static class V0 {

		private long value = 123L;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/LongFieldTest_2_stream.java
8 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: 16

              
public class LongFieldTest_2_stream extends TestCase {

    public void test_min() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v);


            

Reported by PMD.

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

Line: 24

              
        JSONReader reader = new JSONReader(new StringReader(text));
        V0 v1 = reader.readObject(V0.class);
        Assert.assertEquals(v1.getValue(), v.getValue());
        reader.close();
    }
    
    public void test_max() throws Exception {
        V0 v = new V0();

            

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

                      reader.close();
    }
    
    public void test_max() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v);


            

Reported by PMD.

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

Line: 37

                      JSONReader reader = new JSONReader(new StringReader(text));
        V0 v1 = reader.readObject(V0.class);

        Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_min_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

            

Reported by PMD.

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

Line: 40

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_min_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);


            

Reported by PMD.

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

Line: 49

                      JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
        V0 v1 = reader.readObject(V0.class);

        Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_max_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

            

Reported by PMD.

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

Line: 52

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_max_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);


            

Reported by PMD.

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

Line: 61

                      JSONReader reader = new JSONReader(new StringReader(text), Feature.SupportArrayToBean);
        V0 v1 = reader.readObject(V0.class);

        Assert.assertEquals(v.getValue(), v1.getValue());
    }

    public static class V0 {

        private Long value;

            

Reported by PMD.

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

Line: 14

              
public class LongFieldTest_2_private extends TestCase {

    public void test_min() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v);


            

Reported by PMD.

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

Line: 22

              
        V0 v1 = JSON.parseObject(text, V0.class);

        Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_max() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

            

Reported by PMD.

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

Line: 25

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_max() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v);


            

Reported by PMD.

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

Line: 33

              
        V0 v1 = JSON.parseObject(text, V0.class);

        Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_min_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

            

Reported by PMD.

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

Line: 36

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_min_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);


            

Reported by PMD.

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

Line: 44

              
        V0 v1 = JSON.parseObject(text, V0.class, Feature.SupportArrayToBean);

        Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_max_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

            

Reported by PMD.

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

Line: 47

                      Assert.assertEquals(v1.getValue(), v.getValue());
    }
    
    public void test_max_array() throws Exception {
        V0 v = new V0();
        v.setValue(Long.MIN_VALUE);

        String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);


            

Reported by PMD.

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

Line: 55

              
        V0 v1 = JSON.parseObject(text, V0.class, Feature.SupportArrayToBean);

        Assert.assertEquals(v1.getValue(), v.getValue());
    }

    private static class V0 {

        private Long value;

            

Reported by PMD.

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

Line: 14

              public class Issue821 extends TestCase {
    public void test_for_issue() throws Exception {
        String str1 = "{\"v\":[\" \",\"a\",\"x\",\"a\"]}";
        System.out.println(str1);

        char[] c =  JSON.parseObject(str1, new  com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
        assertEquals(4, c.length);
        assertEquals(c[0], ' ');
        assertEquals(c[1], 'a');

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 10/03/2017.
 */
public class Issue821 extends TestCase {
    public void test_for_issue() throws Exception {
        String str1 = "{\"v\":[\" \",\"a\",\"x\",\"a\"]}";
        System.out.println(str1);

        char[] c =  JSON.parseObject(str1, new  com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
        assertEquals(4, c.length);

            

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

               * Created by wenshao on 10/03/2017.
 */
public class Issue821 extends TestCase {
    public void test_for_issue() throws Exception {
        String str1 = "{\"v\":[\" \",\"a\",\"x\",\"a\"]}";
        System.out.println(str1);

        char[] c =  JSON.parseObject(str1, new  com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
        assertEquals(4, c.length);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      System.out.println(str1);

        char[] c =  JSON.parseObject(str1, new  com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
        assertEquals(4, c.length);
        assertEquals(c[0], ' ');
        assertEquals(c[1], 'a');
        assertEquals(c[2], 'x');
        assertEquals(c[3], 'a');
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
        char[] c =  JSON.parseObject(str1, new  com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
        assertEquals(4, c.length);
        assertEquals(c[0], ' ');
        assertEquals(c[1], 'a');
        assertEquals(c[2], 'x');
        assertEquals(c[3], 'a');
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      char[] c =  JSON.parseObject(str1, new  com.alibaba.fastjson.TypeReference<Map<String, char[]>>() {}).get("v");
        assertEquals(4, c.length);
        assertEquals(c[0], ' ');
        assertEquals(c[1], 'a');
        assertEquals(c[2], 'x');
        assertEquals(c[3], 'a');
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      assertEquals(4, c.length);
        assertEquals(c[0], ' ');
        assertEquals(c[1], 'a');
        assertEquals(c[2], 'x');
        assertEquals(c[3], 'a');
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      assertEquals(c[0], ' ');
        assertEquals(c[1], 'a');
        assertEquals(c[2], 'x');
        assertEquals(c[3], 'a');
    }
}

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/util/ASMClassLoader.java
8 issues
High amount of different objects as members denotes a high coupling
Design

Line: 1

              package com.alibaba.fastjson.util;

import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONAware;

            

Reported by PMD.

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

Line: 1

              package com.alibaba.fastjson.util;

import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONAware;

            

Reported by PMD.

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

Line: 148

                  }

    static ClassLoader getParentClassLoader() {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        if (contextClassLoader != null) {
            try {
                contextClassLoader.loadClass(JSON.class.getName());
                return contextClassLoader;
            } catch (ClassNotFoundException e) {

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 153

                          try {
                contextClassLoader.loadClass(JSON.class.getName());
                return contextClassLoader;
            } catch (ClassNotFoundException e) {
                // skip
            }
        }
        return JSON.class.getClassLoader();
    }

            

Reported by PMD.

In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
Error

Line: 157

                              // skip
            }
        }
        return JSON.class.getClassLoader();
    }

    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        Class<?> mappingClass = classMapping.get(name);
        if (mappingClass != null) {

            

Reported by PMD.

A catch statement that catches an exception only to rethrow it should be avoided.
Design

Line: 168

                      
        try {
            return super.loadClass(name, resolve);
        } catch (ClassNotFoundException e) {
            throw e;
        }
    }

    public Class<?> defineClassPublic(String name, byte[] b, int off, int len) throws ClassFormatError {

            

Reported by PMD.

In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
Error

Line: 180

                  }

    public boolean isExternalClass(Class<?> clazz) {
        ClassLoader classLoader = clazz.getClassLoader();

        if (classLoader == null) {
            return false;
        }


            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 188

              
        ClassLoader current = this;
        while (current != null) {
            if (current == classLoader) {
                return false;
            }

            current = current.getParent();
        }

            

Reported by PMD.

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

Line: 9

              
public class Issue208 extends TestCase {

    public void test_for_issue() throws Exception {
            VO vo = new VO ();
            vo.序号 = 1001;
            vo.名称 = "张三";
            
            String text = JSON.toJSONString(vo);

            

Reported by PMD.

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

Line: 9

              
public class Issue208 extends TestCase {

    public void test_for_issue() throws Exception {
            VO vo = new VO ();
            vo.序号 = 1001;
            vo.名称 = "张三";
            
            String text = JSON.toJSONString(vo);

            

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

                          
    }
    
    public void test_for_issue_1() throws Exception {
        实体 vo = new 实体 ();
        vo.序号 = 1001;
        vo.名称 = "张三";
        
        String text = JSON.toJSONString(vo);

            

Reported by PMD.

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

Line: 19

                          
    }
    
    public void test_for_issue_1() throws Exception {
        实体 vo = new 实体 ();
        vo.序号 = 1001;
        vo.名称 = "张三";
        
        String text = JSON.toJSONString(vo);

            

Reported by PMD.

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

Line: 30

              
    public static class VO {

        public int    序号;
        public String 名称;
    }
    
    public static class 实体  {


            

Reported by PMD.

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

Line: 31

                  public static class VO {

        public int    序号;
        public String 名称;
    }
    
    public static class 实体  {

        public int    序号;

            

Reported by PMD.

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

Line: 36

                  
    public static class 实体  {

        public int    序号;
        public String 名称;
    }
}

            

Reported by PMD.

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

Line: 37

                  public static class 实体  {

        public int    序号;
        public String 名称;
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue1063_date.java
8 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: 15

               * Created by wenshao on 11/03/2017.
 */
public class Issue1063_date extends TestCase {
    public void test_for_issue() throws Exception {
        long currentMillis = System.currentTimeMillis();
        TimestampBean bean = new TimestampBean();
        bean.setTimestamp(new Date(currentMillis));
        String timestampJson = JSON.toJSONString(bean);


            

Reported by PMD.

Avoid unused local variables such as 'beanOfJSON'.
Design

Line: 22

                      String timestampJson = JSON.toJSONString(bean);

        // 这里能转换成功
        TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);

        // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);

            

Reported by PMD.

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

Line: 26

              
        // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
    }

    public static class TimestampBean {
        private Date timestamp = null;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

                      // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
    }

    public static class TimestampBean {
        private Date timestamp = null;


            

Reported by PMD.

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

Line: 27

                      // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);
    }

    public static class TimestampBean {
        private Date timestamp = null;


            

Reported by PMD.

Avoid using redundant field initializer for 'timestamp'
Performance

Line: 31

                  }

    public static class TimestampBean {
        private Date timestamp = null;

        public Date getTimestamp() {
            return timestamp;
        }


            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.serializer.SerializerFeature'
Design

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.sql.Date;
import java.sql.Timestamp;


            

Reported by PMD.

Found 'DU'-anomaly for variable 'beanOfJSON' (lines '22'-'28').
Error

Line: 22

                      String timestampJson = JSON.toJSONString(bean);

        // 这里能转换成功
        TimestampBean beanOfJSON = JSON.parseObject(timestampJson, TimestampBean.class);

        // 这里抛异常 java.lang.NumberFormatException
        JSONObject jsonObject = JSON.parseObject(timestampJson);
        Timestamp timestamp2 = jsonObject.getObject("timestamp", Timestamp.class);
        assertEquals(currentMillis/1000, timestamp2.getTime() / 1000);

            

Reported by PMD.