The following issues were found

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

Line: 10

              import java.util.*;

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

    public void test_for_issue() 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: 15

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_for_issue() throws Exception {
        Model model = new Model();
        model.values.add(new Date(1513755213202L));

        String json = JSON.toJSONString(model);
        assertEquals("{\"values\":[\"2017-12-20\"]}", json);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      model.values.add(new Date(1513755213202L));

        String json = JSON.toJSONString(model);
        assertEquals("{\"values\":[\"2017-12-20\"]}", json);
    }

    public static class Model {
        @JSONField(format = "yyyy-MM-dd")
        private List<Date> values = new ArrayList<Date>();

            

Reported by PMD.

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

Line: 25

              
    public static class Model {
        @JSONField(format = "yyyy-MM-dd")
        private List<Date> values = new ArrayList<Date>();

        public List<Date> getValues() {
            return values;
        }
    }

            

Reported by PMD.

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

Line: 25

              
    public static class Model {
        @JSONField(format = "yyyy-MM-dd")
        private List<Date> values = new ArrayList<Date>();

        public List<Date> getValues() {
            return values;
        }
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2100/Issue2150.java
5 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 7

              import junit.framework.TestCase;

public class Issue2150 extends TestCase {
    public void test_for_issue() throws Exception {
        int [][][] arr = new int[100][100][100];
        JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
        assertNotNull(jsonObj);
        assertNotNull(jsonObj.getJSONArray(0));
    }

            

Reported by PMD.

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

Line: 7

              import junit.framework.TestCase;

public class Issue2150 extends TestCase {
    public void test_for_issue() throws Exception {
        int [][][] arr = new int[100][100][100];
        JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
        assertNotNull(jsonObj);
        assertNotNull(jsonObj.getJSONArray(0));
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 10

                  public void test_for_issue() throws Exception {
        int [][][] arr = new int[100][100][100];
        JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
        assertNotNull(jsonObj);
        assertNotNull(jsonObj.getJSONArray(0));
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 11

                      int [][][] arr = new int[100][100][100];
        JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
        assertNotNull(jsonObj);
        assertNotNull(jsonObj.getJSONArray(0));
    }
}

            

Reported by PMD.

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

Line: 11

                      int [][][] arr = new int[100][100][100];
        JSONArray jsonObj = (JSONArray) JSONArray.toJSON(arr);
        assertNotNull(jsonObj);
        assertNotNull(jsonObj.getJSONArray(0));
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/jdk8/LocalTimeTest2.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

              
public class LocalTimeTest2 extends TestCase {

    public void test_for_issue() throws Exception {
        VO vo1 = JSON.parseObject("{\"date\":\"20:30:55\"}", VO.class);
        
        Assert.assertEquals(20, vo1.date.getHour());
        Assert.assertEquals(30, vo1.date.getMinute());
        Assert.assertEquals(55, vo1.date.getSecond());

            

Reported by PMD.

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

Line: 16

                  public void test_for_issue() throws Exception {
        VO vo1 = JSON.parseObject("{\"date\":\"20:30:55\"}", VO.class);
        
        Assert.assertEquals(20, vo1.date.getHour());
        Assert.assertEquals(30, vo1.date.getMinute());
        Assert.assertEquals(55, vo1.date.getSecond());
    }

    public static class VO {

            

Reported by PMD.

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

Line: 17

                      VO vo1 = JSON.parseObject("{\"date\":\"20:30:55\"}", VO.class);
        
        Assert.assertEquals(20, vo1.date.getHour());
        Assert.assertEquals(30, vo1.date.getMinute());
        Assert.assertEquals(55, vo1.date.getSecond());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 18

                      
        Assert.assertEquals(20, vo1.date.getHour());
        Assert.assertEquals(30, vo1.date.getMinute());
        Assert.assertEquals(55, vo1.date.getSecond());
    }

    public static class VO {

        public LocalTime date;

            

Reported by PMD.

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

Line: 23

              
    public static class VO {

        public LocalTime date;


    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1600/Issue1662.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

              import java.lang.reflect.Type;

public class Issue1662 extends TestCase {
    public void test_for_issue() throws Exception {

        ParserConfig.getGlobalInstance().putDeserializer(Model.class, new ModelValueDeserializer());
        String json = "{\"value\":123}";
        Model model = JSON.parseObject(json, Model.class);
        assertEquals("{\"value\":\"12300元\"}",JSON.toJSONString(model));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                      ParserConfig.getGlobalInstance().putDeserializer(Model.class, new ModelValueDeserializer());
        String json = "{\"value\":123}";
        Model model = JSON.parseObject(json, Model.class);
        assertEquals("{\"value\":\"12300元\"}",JSON.toJSONString(model));

    }

    public static class Model {
        @JSONField(serializeUsing = ModelValueSerializer.class, deserializeUsing = ModelValueDeserializer.class)

            

Reported by PMD.

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

Line: 29

              
    public static class Model {
        @JSONField(serializeUsing = ModelValueSerializer.class, deserializeUsing = ModelValueDeserializer.class)
        public int value;
    }

    public static class ModelValueSerializer implements ObjectSerializer {
        public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
                          int features) throws IOException {

            

Reported by PMD.

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

Line: 46

                      public Model deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
            JSONObject obj = (JSONObject)parser.parse();
            Model model = new Model();
            model.value = obj.getInteger("value") * 100;
            return model;
        }

        public int getFastMatchToken() {
            return 0;

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONArray'
Design

Line: 4

              package com.alibaba.json.bvt.issue_1600;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2000/Issue2012.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: 9

              import junit.framework.TestCase;

public class Issue2012 extends TestCase {
    public void test_for_issue() throws Exception {
        Model foo = new Model();
        foo.bytes = new byte[0];
        String str = JSON.toJSONString(foo, SerializerFeature.WriteClassName);
        assertEquals("{\"@type\":\"com.alibaba.json.bvt.issue_2000.Issue2012$Model\",\"bytes\":x''}", str);


            

Reported by PMD.

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

Line: 9

              import junit.framework.TestCase;

public class Issue2012 extends TestCase {
    public void test_for_issue() throws Exception {
        Model foo = new Model();
        foo.bytes = new byte[0];
        String str = JSON.toJSONString(foo, SerializerFeature.WriteClassName);
        assertEquals("{\"@type\":\"com.alibaba.json.bvt.issue_2000.Issue2012$Model\",\"bytes\":x''}", str);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

                      Model foo = new Model();
        foo.bytes = new byte[0];
        String str = JSON.toJSONString(foo, SerializerFeature.WriteClassName);
        assertEquals("{\"@type\":\"com.alibaba.json.bvt.issue_2000.Issue2012$Model\",\"bytes\":x''}", str);

        ParserConfig config = new ParserConfig();
        config.setAutoTypeSupport(true);
        foo = JSON.parseObject(str, Object.class,config);
        assertEquals(0, foo.bytes.length);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      ParserConfig config = new ParserConfig();
        config.setAutoTypeSupport(true);
        foo = JSON.parseObject(str, Object.class,config);
        assertEquals(0, foo.bytes.length);
    }

    public static class Model {
        public byte[] bytes;
    }

            

Reported by PMD.

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

Line: 22

                  }

    public static class Model {
        public byte[] bytes;
    }
}

            

Reported by PMD.

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

              
public class JSONReaderScannerTest__entity_string extends TestCase {

    public void test_scanInt() throws Exception {
        StringBuffer buf = new StringBuffer();
        buf.append('[');
        for (int i = 0; i < 10; ++i) {
            if (i != 0) {
                buf.append(',');

            

Reported by PMD.

Avoid concatenating nonliterals in a StringBuffer/StringBuilder constructor or append().
Performance

Line: 25

                          }
            //1000000000000
            //
            buf.append("{\"id\":\"" + i + "\"}");
            
        }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

            

Reported by PMD.

Ensure that resources like this StringReader object are closed after use
Error

Line: 30

                      }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

        JSONReaderScanner scanner = new JSONReaderScanner(reader);

        DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);

            

Reported by PMD.

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

Line: 37

                      DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);
        for (int i = 0; i < array.size(); ++i) {
            Assert.assertEquals(Integer.toString(i), array.get(i).getId()); 
        }
    }

    public static class VO {


            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONArray'
Design

Line: 10

              import org.junit.Assert;
import junit.framework.TestCase;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONReaderScanner;

public class JSONReaderScannerTest__entity_string extends TestCase {


            

Reported by PMD.

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

              
public class TestInitStringFieldAsEmpty2 extends TestCase {

    public void test_public() throws Exception {
        VO1 vo1 = JSON.parseObject("{\"id\":0,\"value\":33, \"o\":{}}", VO1.class, Feature.InitStringFieldAsEmpty);
        Assert.assertEquals("", vo1.getName());
        Assert.assertEquals("", vo1.getO().getValue());
    }


            

Reported by PMD.

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

Line: 13

              
    public void test_public() throws Exception {
        VO1 vo1 = JSON.parseObject("{\"id\":0,\"value\":33, \"o\":{}}", VO1.class, Feature.InitStringFieldAsEmpty);
        Assert.assertEquals("", vo1.getName());
        Assert.assertEquals("", vo1.getO().getValue());
    }

    public static class VO1 {


            

Reported by PMD.

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

Line: 14

                  public void test_public() throws Exception {
        VO1 vo1 = JSON.parseObject("{\"id\":0,\"value\":33, \"o\":{}}", VO1.class, Feature.InitStringFieldAsEmpty);
        Assert.assertEquals("", vo1.getName());
        Assert.assertEquals("", vo1.getO().getValue());
    }

    public static class VO1 {

        private int    id;

            

Reported by PMD.

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

Line: 14

                  public void test_public() throws Exception {
        VO1 vo1 = JSON.parseObject("{\"id\":0,\"value\":33, \"o\":{}}", VO1.class, Feature.InitStringFieldAsEmpty);
        Assert.assertEquals("", vo1.getName());
        Assert.assertEquals("", vo1.getO().getValue());
    }

    public static class VO1 {

        private int    id;

            

Reported by PMD.

The class 'VO1' is suspected to be a Data Class (WOC=0.000%, NOPA=0, NOAM=8, WMC=9)
Design

Line: 17

                      Assert.assertEquals("", vo1.getO().getValue());
    }

    public static class VO1 {

        private int    id;

        private String name;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/TestException.java
5 issues
Avoid throwing raw exception types.
Design

Line: 28

                  }

    public void f() {
        throw new RuntimeException();
    }
}

            

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

              
public class TestException extends TestCase {

    public void test_0() throws Exception {
        Exception error = null;

        try {
            f();
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 11

              
public class TestException extends TestCase {

    public void test_0() throws Exception {
        Exception error = null;

        try {
            f();
        } catch (Exception ex) {

            

Reported by PMD.

Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 16

              
        try {
            f();
        } catch (Exception ex) {
            error = ex;
        }

        String text = JSON.toJSONString(new Exception[] { error });


            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '12'-'17').
Error

Line: 12

              public class TestException extends TestCase {

    public void test_0() throws Exception {
        Exception error = null;

        try {
            f();
        } catch (Exception ex) {
            error = ex;

            

Reported by PMD.

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

              
public class JSONReaderScannerTest__entity_long extends TestCase {

    public void test_scanInt() throws Exception {
        StringBuffer buf = new StringBuffer();
        buf.append('[');
        for (int i = 0; i < 10; ++i) {
            if (i != 0) {
                buf.append(',');

            

Reported by PMD.

Avoid concatenating nonliterals in a StringBuffer/StringBuilder constructor or append().
Performance

Line: 26

                          //1000000000000
            //
            long value = (long) 1000000000000L + 1L + (long) i;
            buf.append("{\"id\":" + value + "}");
        }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());


            

Reported by PMD.

Ensure that resources like this StringReader object are closed after use
Error

Line: 30

                      }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

        JSONReaderScanner scanner = new JSONReaderScanner(reader);

        DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);

            

Reported by PMD.

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

Line: 38

                      List<VO> array = parser.parseArray(VO.class);
        for (int i = 0; i < array.size(); ++i) {
            long value = (long) 1000000000000L + 1L + (long) i;
            Assert.assertEquals(value, array.get(i).getId());
        }
    }

    public static class VO {


            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONArray'
Design

Line: 10

              import org.junit.Assert;
import junit.framework.TestCase;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONReaderScanner;

public class JSONReaderScannerTest__entity_long extends TestCase {


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/SafeModeTest.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 junit.framework.TestCase;

public class SafeModeTest extends TestCase {
    public void test_for_safeMode() throws Exception {
        ParserConfig config = new ParserConfig();

        String str = "{\"@type\":\"com.alibaba.json.bvt.parser.SafeModeTest$Entity\"}";
        JSON.parse(str);


            

Reported by PMD.

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

Line: 11

              import junit.framework.TestCase;

public class SafeModeTest extends TestCase {
    public void test_for_safeMode() throws Exception {
        ParserConfig config = new ParserConfig();

        String str = "{\"@type\":\"com.alibaba.json.bvt.parser.SafeModeTest$Entity\"}";
        JSON.parse(str);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                          catch (JSONException ex) {
                error = ex;
            }
            assertNotNull(error);
        }

        {
            Exception error = null;
            try {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 37

                          catch (JSONException ex) {
                error = ex;
            }
            assertNotNull(error);
        }
    }

    @JSONType
    public static class Entity {

            

Reported by PMD.

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

Line: 18

                      JSON.parse(str);

        {
            Exception error = null;
            try {
                JSON.parse(str, config, Feature.SafeMode);
            }
            catch (JSONException ex) {
                error = ex;

            

Reported by PMD.