The following issues were found

src/test/java/com/alibaba/json/bvt/serializer/enum_/EnumTest2.java
5 issues
System.out.println is used
Design

Line: 23

                  public void test_enum() throws Exception {
        Date date = new Date(1308841916550L);
        Assert.assertEquals("1308841916550", JSON.toJSONString(date)); // 1308841916550
        System.out.println(JSON.toJSONString(date, SerializerFeature.UseISO8601DateFormat)); // "2011-06-23T23:11:56.550"
        SerializerFeature[] features = {SerializerFeature.UseISO8601DateFormat, SerializerFeature.UseSingleQuotes };
        System.out.println(JSON.toJSONString(date, features)); // '2011-06-23T23:11:56.550'
    }

    public void test_enum_noasm() throws Exception {

            

Reported by PMD.

System.out.println is used
Design

Line: 25

                      Assert.assertEquals("1308841916550", JSON.toJSONString(date)); // 1308841916550
        System.out.println(JSON.toJSONString(date, SerializerFeature.UseISO8601DateFormat)); // "2011-06-23T23:11:56.550"
        SerializerFeature[] features = {SerializerFeature.UseISO8601DateFormat, SerializerFeature.UseSingleQuotes };
        System.out.println(JSON.toJSONString(date, features)); // '2011-06-23T23:11:56.550'
    }

    public void test_enum_noasm() throws Exception {
        SerializeConfig mapping = new SerializeConfig();
        mapping.setAsmEnable(false);

            

Reported by PMD.

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

Line: 15

              import com.alibaba.fastjson.serializer.SerializerFeature;

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

    public void test_enum() throws Exception {

            

Reported by PMD.

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

Line: 20

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_enum() throws Exception {
        Date date = new Date(1308841916550L);
        Assert.assertEquals("1308841916550", JSON.toJSONString(date)); // 1308841916550
        System.out.println(JSON.toJSONString(date, SerializerFeature.UseISO8601DateFormat)); // "2011-06-23T23:11:56.550"
        SerializerFeature[] features = {SerializerFeature.UseISO8601DateFormat, SerializerFeature.UseSingleQuotes };
        System.out.println(JSON.toJSONString(date, features)); // '2011-06-23T23:11:56.550'

            

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

                      System.out.println(JSON.toJSONString(date, features)); // '2011-06-23T23:11:56.550'
    }

    public void test_enum_noasm() throws Exception {
        SerializeConfig mapping = new SerializeConfig();
        mapping.setAsmEnable(false);
        
        Date date = new Date(1308841916550L);
        Assert.assertEquals("1308841916550", JSON.toJSONString(date, mapping)); // 1308841916550

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/filters/ContextValueClassLevelTest.java
5 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

              
public class ContextValueClassLevelTest extends TestCase {

    public void test_0() throws Exception {
        Object[] array = { new ModelA(), new ModelB() };

        SerializeConfig config = new SerializeConfig();
        config.addFilter(ModelA.class, //
                         new ContextValueFilter() {

            

Reported by PMD.

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

Line: 9

              import com.alibaba.fastjson.serializer.BeanContext;
import com.alibaba.fastjson.serializer.ContextValueFilter;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.ValueFilter;

import junit.framework.TestCase;

public class ContextValueClassLevelTest extends TestCase {


            

Reported by PMD.

Found 'DU'-anomaly for variable 'array' (lines '16'-'39').
Error

Line: 16

              public class ContextValueClassLevelTest extends TestCase {

    public void test_0() throws Exception {
        Object[] array = { new ModelA(), new ModelB() };

        SerializeConfig config = new SerializeConfig();
        config.addFilter(ModelA.class, //
                         new ContextValueFilter() {


            

Reported by PMD.

Found 'DU'-anomaly for variable 'array' (lines '16'-'39').
Error

Line: 16

              public class ContextValueClassLevelTest extends TestCase {

    public void test_0() throws Exception {
        Object[] array = { new ModelA(), new ModelB() };

        SerializeConfig config = new SerializeConfig();
        config.addFilter(ModelA.class, //
                         new ContextValueFilter() {


            

Reported by PMD.

Found 'DU'-anomaly for variable 'array' (lines '16'-'39').
Error

Line: 16

              public class ContextValueClassLevelTest extends TestCase {

    public void test_0() throws Exception {
        Object[] array = { new ModelA(), new ModelB() };

        SerializeConfig config = new SerializeConfig();
        config.addFilter(ModelA.class, //
                         new ContextValueFilter() {


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/stream/JSONWriterTest.java
5 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

              @SuppressWarnings("deprecation")
public class JSONWriterTest extends TestCase {

    public void test_0() throws Exception {
        StringWriter out = new StringWriter();

        JSONWriter writer = new JSONWriter(out);
        writer.writeStartObject();
        writer.writeEndObject();

            

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("{}", out.toString());
    }

    public void test_1() throws Exception {
        StringWriter out = new StringWriter();

        JSONWriter writer = new JSONWriter(out);
        writer.writeStartObject();
        writer.writeKey("id");

            

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

                      Assert.assertEquals("{\"id\":33}", out.toString());
    }

    public void test_2() throws Exception {
        StringWriter out = new StringWriter();

        JSONWriter writer = new JSONWriter(out);
        writer.writeStartObject();


            

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

                      Assert.assertEquals("{\"id\":33,\"name\":\"jobs\"}", out.toString());
    }

    public void test_3() throws Exception {
        StringWriter out = new StringWriter();

        JSONWriter writer = new JSONWriter(out);
        writer.writeStartObject();


            

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

                      Assert.assertEquals("{\"id\":33,\"name\":\"jobs\",\"children\":[{},{}]}", out.toString());
    }

    public void test_4() throws Exception {
        StringWriter out = new StringWriter();

        JSONWriter writer = new JSONWriter(out);

        writer.writeStartArray();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/TestEnum.java
5 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

                      Big, Medium, Small
    }

    public void test_enum() throws Exception {
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:0}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":0}", VO.class).getValue());
    }

            

Reported by PMD.

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

Line: 15

                  }

    public void test_enum() throws Exception {
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:0}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":0}", VO.class).getValue());
    }


            

Reported by PMD.

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

Line: 16

              
    public void test_enum() throws Exception {
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:0}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":0}", VO.class).getValue());
    }

    public static class VO {

            

Reported by PMD.

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

Line: 17

                  public void test_enum() throws Exception {
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:0}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":0}", VO.class).getValue());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 18

                      Assert.assertEquals(Type.Big, JSON.parseObject("{value:\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":\"Big\"}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{value:0}", VO.class).getValue());
        Assert.assertEquals(Type.Big, JSON.parseObject("{\"value\":0}", VO.class).getValue());
    }

    public static class VO {

        private Type value;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/util/AntiCollisionHashMapTest_writeClassName.java
5 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: 11

              import java.util.Map;

public class AntiCollisionHashMapTest_writeClassName extends TestCase {
    public void test_for_bug() throws Exception {
        Model m = JSON.parseObject("{\"value\":{\"@type\":\"com.alibaba.fastjson.util.AntiCollisionHashMap\"}}", Model.class);
        assertTrue(m.value.getInnerMap() instanceof AntiCollisionHashMap);
    }

    public static class Model {

            

Reported by PMD.

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

Line: 13

              public class AntiCollisionHashMapTest_writeClassName extends TestCase {
    public void test_for_bug() throws Exception {
        Model m = JSON.parseObject("{\"value\":{\"@type\":\"com.alibaba.fastjson.util.AntiCollisionHashMap\"}}", Model.class);
        assertTrue(m.value.getInnerMap() instanceof AntiCollisionHashMap);
    }

    public static class Model {
        public JSONObject value;
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

              public class AntiCollisionHashMapTest_writeClassName extends TestCase {
    public void test_for_bug() throws Exception {
        Model m = JSON.parseObject("{\"value\":{\"@type\":\"com.alibaba.fastjson.util.AntiCollisionHashMap\"}}", Model.class);
        assertTrue(m.value.getInnerMap() instanceof AntiCollisionHashMap);
    }

    public static class Model {
        public JSONObject value;
    }

            

Reported by PMD.

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

Line: 17

                  }

    public static class Model {
        public JSONObject value;
    }
}

            

Reported by PMD.

Avoid unused imports such as 'java.util.Map'
Design

Line: 8

              import com.alibaba.fastjson.util.AntiCollisionHashMap;
import junit.framework.TestCase;

import java.util.Map;

public class AntiCollisionHashMapTest_writeClassName extends TestCase {
    public void test_for_bug() throws Exception {
        Model m = JSON.parseObject("{\"value\":{\"@type\":\"com.alibaba.fastjson.util.AntiCollisionHashMap\"}}", Model.class);
        assertTrue(m.value.getInnerMap() instanceof AntiCollisionHashMap);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/URLDeserializerTest.java
5 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: 18

              
public class URLDeserializerTest extends TestCase {

    public void test_url() throws Exception {
        Assert.assertEquals(new URL("http://www.alibaba.com"), JSON.parseObject("'http://www.alibaba.com'", URL.class));

        Assert.assertEquals(null, JSON.parseObject("null", URL.class));

        DefaultJSONParser parser = new DefaultJSONParser("null", ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);

            

Reported by PMD.

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

Line: 24

                      Assert.assertEquals(null, JSON.parseObject("null", URL.class));

        DefaultJSONParser parser = new DefaultJSONParser("null", ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
        Assert.assertEquals(null, MiscCodec.instance.deserialze(parser, null, null));
        Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());

    }

    public void test_url_error() throws Exception {

            

Reported by PMD.

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

Line: 25

              
        DefaultJSONParser parser = new DefaultJSONParser("null", ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
        Assert.assertEquals(null, MiscCodec.instance.deserialze(parser, null, null));
        Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());

    }

    public void test_url_error() throws Exception {
        JSONException ex = 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: 29

              
    }

    public void test_url_error() throws Exception {
        JSONException ex = null;
        try {
            JSON.parseObject("'123'", URL.class);
        } catch (JSONException e) {
            ex = e;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ex' (lines '30'-'34').
Error

Line: 30

                  }

    public void test_url_error() throws Exception {
        JSONException ex = null;
        try {
            JSON.parseObject("'123'", URL.class);
        } catch (JSONException e) {
            ex = e;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/list/ListStringFieldTest_createError.java
5 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: 17

              
public class ListStringFieldTest_createError extends TestCase {

    public void test_null() throws Exception {
        Exception error = null;
        try {
            String text = "{\"values\":[]}";
            JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {

            

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

                      Assert.assertNotNull(error);
    }
    
    public void test_reader() throws Exception {
        Exception error = null;
        try {
            String text = "{\"values\":[]}";
            JSONReader reader = new JSONReader(new StringReader(text));
            reader.readObject(Model.class);

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 54

              
    }

    public static class MyErrorList<T> extends ArrayList<T> {

        public MyErrorList(){
            throw new IllegalStateException();
        }
    }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '18'-'23').
Error

Line: 18

              public class ListStringFieldTest_createError extends TestCase {

    public void test_null() throws Exception {
        Exception error = null;
        try {
            String text = "{\"values\":[]}";
            JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);
        } catch (JSONException ex) {
            error = ex;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '29'-'35').
Error

Line: 29

                  }
    
    public void test_reader() throws Exception {
        Exception error = null;
        try {
            String text = "{\"values\":[]}";
            JSONReader reader = new JSONReader(new StringReader(text));
            reader.readObject(Model.class);
        } catch (JSONException ex) {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/DefaultObjectDeserializerTest7.java
5 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: 12

              
public class DefaultObjectDeserializerTest7 extends TestCase {

    public void test_0() throws Exception {
        VO<A> vo = JSON.parseObject("{\"value\":[{\"id\":123}]}", new TypeReference<VO<A>>() {
        });
        A a = vo.getValue()[0];
        Assert.assertEquals(123, a.getId());
    }

            

Reported by PMD.

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

Line: 16

                      VO<A> vo = JSON.parseObject("{\"value\":[{\"id\":123}]}", new TypeReference<VO<A>>() {
        });
        A a = vo.getValue()[0];
        Assert.assertEquals(123, a.getId());
    }
    
    public static class VO<T> {

        private T[] value;

            

Reported by PMD.

Returning 'value' may expose an internal array.
Design

Line: 24

                      private T[] value;

        public T[] getValue() {
            return value;
        }

        public void setValue(T[] value) {
            this.value = value;
        }

            

Reported by PMD.

The user-supplied array 'value' is stored directly.
Design

Line: 27

                          return value;
        }

        public void setValue(T[] value) {
            this.value = value;
        }

    }


            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 27

                          return value;
        }

        public void setValue(T[] value) {
            this.value = value;
        }

    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/creator/JSONCreatorTest_error3.java
5 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 JSONCreatorTest_error3 extends TestCase {

    public void test_create() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("{\"id\":123,\"name\":\"abc\"}").toJavaObject(Entity.class);
        } catch (JSONException ex) {
            error = ex;

            

Reported by PMD.

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

Line: 17

                  public void test_create() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("{\"id\":123,\"name\":\"abc\"}").toJavaObject(Entity.class);
        } catch (JSONException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }

            

Reported by PMD.

Avoid unused constructor parameters such as 'id'.
Design

Line: 30

                      private final String name;

        @JSONCreator
        public Entity(@JSONField(name = "id") int id, @JSONField(name = "name") String name){
            throw new UnsupportedOperationException();
        }

        public int getId() {
            return id;

            

Reported by PMD.

Avoid unused constructor parameters such as 'name'.
Design

Line: 30

                      private final String name;

        @JSONCreator
        public Entity(@JSONField(name = "id") int id, @JSONField(name = "name") String name){
            throw new UnsupportedOperationException();
        }

        public int getId() {
            return id;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '15'-'19').
Error

Line: 15

              public class JSONCreatorTest_error3 extends TestCase {

    public void test_create() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("{\"id\":123,\"name\":\"abc\"}").toJavaObject(Entity.class);
        } catch (JSONException ex) {
            error = ex;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/stream/LargeTest.java
5 issues
Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 24

                          list.add(Integer.toString(i));
        }
        File file = File.createTempFile("fastjson-stream-large", "json");
        JSONWriter writer = new JSONWriter(new FileWriter(file));
        writer.startArray();
        writer.writeObject(list);
        writer.endArray();
        writer.close();


            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 32

              
        System.out.println(FileUtils.readFileToString(file));

        JSONReader reader = new JSONReader(new FileReader(file));
        reader.startArray();
        reader.readObject();
        reader.endArray();
        reader.close();


            

Reported by PMD.

System.out.println is used
Design

Line: 30

                      writer.endArray();
        writer.close();

        System.out.println(FileUtils.readFileToString(file));

        JSONReader reader = new JSONReader(new FileReader(file));
        reader.startArray();
        reader.readObject();
        reader.endArray();

            

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

              
public class LargeTest extends TestCase {

    public void test_0() throws Exception {
        List<String> list = new ArrayList<String>(1000 * 1);
        for (int i = 0; i < 100 * 1; ++i) {
            list.add(Integer.toString(i));
        }
        File file = File.createTempFile("fastjson-stream-large", "json");

            

Reported by PMD.

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

Line: 18

              
public class LargeTest extends TestCase {

    public void test_0() throws Exception {
        List<String> list = new ArrayList<String>(1000 * 1);
        for (int i = 0; i < 100 * 1; ++i) {
            list.add(Integer.toString(i));
        }
        File file = File.createTempFile("fastjson-stream-large", "json");

            

Reported by PMD.