The following issues were found

src/test/java/com/alibaba/json/bvt/path/JSONPath_11.java
5 issues
System.out.println is used
Design

Line: 36

                              "]";

        JSONArray array = JSON.parseArray(json);
        System.out.println(JSONPath.eval(array, "$[0,1][CN='t1c1CN']"));
    }

//    public void test_path_2() throws Exception {
////        File file = new File("/Users/wenshao/Downloads/test");
////        String json = FileUtils.readFileToString(file);

            

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 JSONPath_11 extends TestCase {

    public void test(){
        String json = "[\n" +
                "  [\n" +
                "    {\n" +
                "      \"CN\": \"t1c1CN\",\n" +
                "      \"FP\": \"t1c1FP\"\n" +

            

Reported by PMD.

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

Line: 11

              
public class JSONPath_11 extends TestCase {

    public void test(){
        String json = "[\n" +
                "  [\n" +
                "    {\n" +
                "      \"CN\": \"t1c1CN\",\n" +
                "      \"FP\": \"t1c1FP\"\n" +

            

Reported by PMD.

The String literal ' {\n' appears 4 times in this file; the first occurrence is on line 14
Error

Line: 14

                  public void test(){
        String json = "[\n" +
                "  [\n" +
                "    {\n" +
                "      \"CN\": \"t1c1CN\",\n" +
                "      \"FP\": \"t1c1FP\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"CN\": \"t1c2CN\",\n" +

            

Reported by PMD.

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

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import junit.framework.TestCase;

public class JSONPath_11 extends TestCase {


            

Reported by PMD.

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

    public void test_string() throws Exception {
        char[] chars = new char[1024];
        Arrays.fill(chars, '0');
        StringBuilder buf = new StringBuilder();
        buf.append("[\"");
        for (int i = 0; i < 16; ++i) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 21

                      buf.append("[\"");
        for (int i = 0; i < 16; ++i) {
            buf.append("\\\\");
            buf.append(new String(chars));
        }
        buf.append("\"]");
        
        String text = buf.toString();
        JSONArray array = (JSONArray) JSON.parse(text);

            

Reported by PMD.

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

Line: 27

                      
        String text = buf.toString();
        JSONArray array = (JSONArray) JSON.parse(text);
        Assert.assertEquals(1, array.size());
        
        String item = (String) array.get(0);
        Assert.assertEquals(16 * 1024 + 16, item.length());
        
        for (int i = 0; i < 16; ++i) {

            

Reported by PMD.

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

Line: 29

                      JSONArray array = (JSONArray) JSON.parse(text);
        Assert.assertEquals(1, array.size());
        
        String item = (String) array.get(0);
        Assert.assertEquals(16 * 1024 + 16, item.length());
        
        for (int i = 0; i < 16; ++i) {
            Assert.assertTrue(item.charAt(i * 1025) == '\\');
            for (int j = 0; j < 1024; ++j) {

            

Reported by PMD.

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

Line: 30

                      Assert.assertEquals(1, array.size());
        
        String item = (String) array.get(0);
        Assert.assertEquals(16 * 1024 + 16, item.length());
        
        for (int i = 0; i < 16; ++i) {
            Assert.assertTrue(item.charAt(i * 1025) == '\\');
            for (int j = 0; j < 1024; ++j) {
                Assert.assertTrue(item.charAt(i * 1025 + j + 1) == '0');    

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/ref/RefTest9.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 RefTest9 extends TestCase {

    public void test_bug_for_wanglin() throws Exception {
        VO vo = new VO();
        A a = new A();
        vo.setA(a);
        vo.getValues().add(a);


            

Reported by PMD.

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

Line: 18

                      VO vo = new VO();
        A a = new A();
        vo.setA(a);
        vo.getValues().add(a);

        String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"a\":{},\"values\":[{\"$ref\":\"$.a\"}]}", text);
        
        VO vo2 = JSON.parseObject(text, VO.class);

            

Reported by PMD.

Avoid unused local variables such as 'vo2'.
Design

Line: 23

                      String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"a\":{},\"values\":[{\"$ref\":\"$.a\"}]}", text);
        
        VO vo2 = JSON.parseObject(text, VO.class);
    }

    public static class VO {

        private A      a;

            

Reported by PMD.

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

Line: 26

                      VO vo2 = JSON.parseObject(text, VO.class);
    }

    public static class VO {

        private A      a;
        private Set<A> values = new HashSet<A>();

        public A getA() {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'vo2' (lines '23'-'24').
Error

Line: 23

                      String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"a\":{},\"values\":[{\"$ref\":\"$.a\"}]}", text);
        
        VO vo2 = JSON.parseObject(text, VO.class);
    }

    public static class VO {

        private A      a;

            

Reported by PMD.

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

Line: 11

              import com.alibaba.fastjson.JSON;

public class MapDeserializerTest extends TestCase {
    protected void setUp() throws Exception {
        com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.parser.deser.MapDeserializerTest.");
    }

    public void test_0() throws Exception {
        JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.MapDeserializerTest$MyMap\"}", Map.class);

            

Reported by PMD.

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

Line: 12

              
public class MapDeserializerTest extends TestCase {
    protected void setUp() throws Exception {
        com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.parser.deser.MapDeserializerTest.");
    }

    public void test_0() throws Exception {
        JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.MapDeserializerTest$MyMap\"}", Map.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: 15

                      com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.parser.deser.MapDeserializerTest.");
    }

    public void test_0() throws Exception {
        JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.MapDeserializerTest$MyMap\"}", Map.class);
    }
    
    public static class MyMap extends HashMap {
        public MyMap () {

            

Reported by PMD.

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

Line: 15

                      com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.parser.deser.MapDeserializerTest.");
    }

    public void test_0() throws Exception {
        JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.MapDeserializerTest$MyMap\"}", Map.class);
    }
    
    public static class MyMap extends HashMap {
        public MyMap () {

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 19

                      JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.MapDeserializerTest$MyMap\"}", Map.class);
    }
    
    public static class MyMap extends HashMap {
        public MyMap () {
            
        }
    }
}

            

Reported by PMD.

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

Line: 20

                      VO vo = new VO();
        vo.setValue(buf.toString());
        
        System.out.println(JSON.toJSONString(vo));
    }

    public static class VO {

        private String 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: 9

              
public class TestSpecial2 extends TestCase {

    public void test_0() throws Exception {
        StringBuilder buf = new StringBuilder();
        buf.append('\r');
        buf.append('\r');
        for (int i = 0; i < 1000; ++i) {
            buf.append((char) 160);

            

Reported by PMD.

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

Line: 9

              
public class TestSpecial2 extends TestCase {

    public void test_0() throws Exception {
        StringBuilder buf = new StringBuilder();
        buf.append('\r');
        buf.append('\r');
        for (int i = 0; i < 1000; ++i) {
            buf.append((char) 160);

            

Reported by PMD.

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

Line: 11

              
    public void test_0() throws Exception {
        StringBuilder buf = new StringBuilder();
        buf.append('\r');
        buf.append('\r');
        for (int i = 0; i < 1000; ++i) {
            buf.append((char) 160);
        }


            

Reported by PMD.

StringBuffer (or StringBuilder).append is called 2 consecutive times with literals. Use a single append with a single combined String.
Performance

Line: 11

              
    public void test_0() throws Exception {
        StringBuilder buf = new StringBuilder();
        buf.append('\r');
        buf.append('\r');
        for (int i = 0; i < 1000; ++i) {
            buf.append((char) 160);
        }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/path/JSONPath_enum.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 JSONPath_enum extends TestCase {
    
    public void test_name() throws Exception {
        Model model = new Model();
        model.size = Size.Small;
        
        Assert.assertEquals(Size.Small.name(), JSONPath.eval(model, "$.size.name"));
    }

            

Reported by PMD.

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

Line: 15

                      Model model = new Model();
        model.size = Size.Small;
        
        Assert.assertEquals(Size.Small.name(), JSONPath.eval(model, "$.size.name"));
    }
    
    public void test_orginal() throws Exception {
        Model model = new Model();
        model.size = Size.Small;

            

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

                      Assert.assertEquals(Size.Small.name(), JSONPath.eval(model, "$.size.name"));
    }
    
    public void test_orginal() throws Exception {
        Model model = new Model();
        model.size = Size.Small;
        
        Assert.assertEquals(Size.Small.ordinal(), JSONPath.eval(model, "$.size.ordinal"));
    }

            

Reported by PMD.

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

Line: 22

                      Model model = new Model();
        model.size = Size.Small;
        
        Assert.assertEquals(Size.Small.ordinal(), JSONPath.eval(model, "$.size.ordinal"));
    }

    public static class Model {
        public Size size;
    }

            

Reported by PMD.

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

Line: 26

                  }

    public static class Model {
        public Size size;
    }
    
    public static enum Size {
        Big, Median, Small
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/SerializeWriterTest_3.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 SerializeWriterTest_3 extends TestCase {

    public void test_0() throws Exception {
        SerializeWriter out = new SerializeWriter(1);
        out.config(SerializerFeature.QuoteFieldNames, true);
        out.writeFieldValue(',', "name", "jobs");
        Assert.assertEquals(",\"name\":\"jobs\"", out.toString());
    }

            

Reported by PMD.

The String literal 'name' appears 4 times in this file; the first occurrence is on line 14
Error

Line: 14

                  public void test_0() throws Exception {
        SerializeWriter out = new SerializeWriter(1);
        out.config(SerializerFeature.QuoteFieldNames, true);
        out.writeFieldValue(',', "name", "jobs");
        Assert.assertEquals(",\"name\":\"jobs\"", out.toString());
    }

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

            

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

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

    public void test_1() throws Exception {
        SerializeWriter out = new SerializeWriter(1);
        out.config(SerializerFeature.QuoteFieldNames, false);
        out.writeFieldValue(',', "name", "jobs");
        Assert.assertEquals(",name:\"jobs\"", 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: 25

                      Assert.assertEquals(",name:\"jobs\"", out.toString());
    }
    
    public void test_null() throws Exception {
        SerializeWriter out = new SerializeWriter(1);
        out.config(SerializerFeature.QuoteFieldNames, true);
        out.writeFieldValue(',', "name", (String) null);
        Assert.assertEquals(",\"name\":null", 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: 32

                      Assert.assertEquals(",\"name\":null", out.toString());
    }

    public void test_null_1() throws Exception {
        SerializeWriter out = new SerializeWriter(1);
        out.config(SerializerFeature.QuoteFieldNames, false);
        out.writeFieldValue(',', "name", (String) null);
        Assert.assertEquals(",name:null", out.toString());
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/LongArraySerializerTest.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 LongArraySerializerTest extends TestCase {

    public void test_0() {
        Assert.assertEquals("[]", JSON.toJSONString(new long[0]));
        Assert.assertEquals("[1,2]", JSON.toJSONString(new long[] { 1, 2 }));
        Assert.assertEquals("[1,2,3,-4]", JSON.toJSONString(new long[] { 1, 2, 3, -4 }));
        Assert.assertEquals("{\"value\":null}", JSON.toJSONString(new Entity(), SerializerFeature.WriteMapNullValue));
        Assert.assertEquals("{\"value\":[]}", JSON.toJSONString(new Entity(), SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty));

            

Reported by PMD.

Returning 'value' may expose an internal array.
Design

Line: 26

                      private long[] value;

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

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

            

Reported by PMD.

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

Line: 29

                          return value;
        }

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

    }
}

            

Reported by PMD.

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

Line: 8

              import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeWriter;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class LongArraySerializerTest extends TestCase {

    public void test_0() {

            

Reported by PMD.

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

Line: 29

                          return value;
        }

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

    }
}

            

Reported by PMD.

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

               * Created by wenshao on 2016/10/11.
 */
public class TypeReferenceTest10 extends TestCase {
    public void test_same() throws Exception {
        Type type1 = getType();
        Type type2 = getType();

        assertEquals(type1, type2);
        assertSame(type1, type2);

            

Reported by PMD.

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

Line: 13

               * Created by wenshao on 2016/10/11.
 */
public class TypeReferenceTest10 extends TestCase {
    public void test_same() throws Exception {
        Type type1 = getType();
        Type type2 = getType();

        assertEquals(type1, type2);
        assertSame(type1, type2);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      Type type1 = getType();
        Type type2 = getType();

        assertEquals(type1, type2);
        assertSame(type1, type2);
    }

    Type getType() {
        return new TypeReference<Model<Integer>>() {}.getType();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      Type type2 = getType();

        assertEquals(type1, type2);
        assertSame(type1, type2);
    }

    Type getType() {
        return new TypeReference<Model<Integer>>() {}.getType();
    }

            

Reported by PMD.

Avoid unused imports such as 'org.junit.Assert'
Design

Line: 5

              
import com.alibaba.fastjson.TypeReference;
import junit.framework.TestCase;
import org.junit.Assert;

import java.lang.reflect.Type;

/**
 * Created by wenshao on 2016/10/11.

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/IntegerArrayFieldSerializerTest.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 IntegerArrayFieldSerializerTest extends TestCase {

    public void test_0() throws Exception {
        A a1 = new A();
        a1.setBytes(new int[] { 1, 2 });

        Assert.assertEquals("{\"bytes\":[1,2]}", JSON.toJSONString(a1));
    }

            

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

                      Assert.assertEquals("{\"bytes\":[1,2]}", JSON.toJSONString(a1));
    }

    public void test_1() throws Exception {
        A a1 = new A();

        Assert.assertEquals("{\"bytes\":null}", JSON.toJSONString(a1, SerializerFeature.WriteMapNullValue));
    }


            

Reported by PMD.

Returning 'bytes' may expose an internal array.
Design

Line: 29

                      private int[] bytes;

        public int[] getBytes() {
            return bytes;
        }

        public void setBytes(int[] bytes) {
            this.bytes = bytes;
        }

            

Reported by PMD.

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

Line: 32

                          return bytes;
        }

        public void setBytes(int[] bytes) {
            this.bytes = bytes;
        }

    }
}

            

Reported by PMD.

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

Line: 32

                          return bytes;
        }

        public void setBytes(int[] bytes) {
            this.bytes = bytes;
        }

    }
}

            

Reported by PMD.