The following issues were found

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

    public void test_list_map() throws Exception {
        JSONPath path = new JSONPath("$[?(@.name)]");

        List<Entity> entities = new ArrayList<Entity>();
        entities.add(new Entity(1001, "ljw2083"));
        entities.add(new Entity(1002, "wenshao"));

            

Reported by PMD.

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

Line: 23

                      entities.add(new Entity(1003, null));

        List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(2, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
        Assert.assertSame(entities.get(1), result.get(1));
    }

    public static class Entity {

            

Reported by PMD.

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

Line: 24

              
        List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(2, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
        Assert.assertSame(entities.get(1), result.get(1));
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 25

                      List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(2, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
        Assert.assertSame(entities.get(1), result.get(1));
    }

    public static class Entity {

        private Integer id;

            

Reported by PMD.

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

Line: 28

                      Assert.assertSame(entities.get(1), result.get(1));
    }

    public static class Entity {

        private Integer id;
        private String  name;

        public Entity(Integer id, String name){

            

Reported by PMD.

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

    public void test_0() throws Exception {
        String text = "{}";

        ParserConfig config = new ParserConfig();

        config.addDeny(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: 33

                      JSON.parseObject(text, B.class, config, JSON.DEFAULT_PARSER_FEATURE);
    }

    public void test_1() throws Exception {
        String text = "{}";

        ParserConfig config = new ParserConfig();

        config.addDeny(null);

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.json.bvtVO.deny.A'
Design

Line: 8

              import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.json.bvtVO.deny.A;

import junit.framework.TestCase;

public class DenyTest extends TestCase {


            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '22'-'26').
Error

Line: 22

                      config.addDeny(null);
        config.addDeny("com.alibaba.json.bvtVO.deny");

        Exception error = null;
        try {
            JSON.parseObject("{\"@type\":\"com.alibaba.json.bvtVO.deny$A\"}", Object.class, config, JSON.DEFAULT_PARSER_FEATURE);
        } catch (JSONException ex) {
            error = ex;
        }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '41'-'45').
Error

Line: 41

                      config.addDeny(null);
        config.addDeny("com.alibaba.json.bvt.parser.deser.deny.DenyTest.B");

        Exception error = null;
        try {
            JSON.parseObject("{\"@type\":\"LLLcom.alibaba.json.bvt.parser.deser.deny.DenyTest$B;;;\"}", Object.class, config, JSON.DEFAULT_PARSER_FEATURE);
        } catch (JSONException ex) {
            error = ex;
        }

            

Reported by PMD.

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

    public void test_0() throws Exception {
        new JavaBeanSerializer(A.class, Collections.<String, String> emptyMap());
    }

    public static class A {


            

Reported by PMD.

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

Line: 12

              
public class JavaBeanSerializerTest2 extends TestCase {

    public void test_0() throws Exception {
        new JavaBeanSerializer(A.class, Collections.<String, String> emptyMap());
    }

    public static class A {


            

Reported by PMD.

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

Line: 16

                      new JavaBeanSerializer(A.class, Collections.<String, String> emptyMap());
    }

    public static class A {

        @JSONField(name = "uid")
        private int     id;
        private String  name;


            

Reported by PMD.

Returning 'bytes' may expose an internal array.
Design

Line: 31

                      private byte[]  bytes;

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

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

            

Reported by PMD.

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

Line: 34

                          return bytes;
        }

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

        public boolean isB2() {
            return b2;

            

Reported by PMD.

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

    public void test_null() throws Exception {
        Entity value = JSON.parseObject("{value:null}", Entity.class);
        Assert.assertNull(value.getValue());
    }

    public void test_empty() throws Exception {

            

Reported by PMD.

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

Line: 14

              
    public void test_null() throws Exception {
        Entity value = JSON.parseObject("{value:null}", Entity.class);
        Assert.assertNull(value.getValue());
    }

    public void test_empty() throws Exception {
        Entity value = JSON.parseObject("{value:[]}", Entity.class);
        Assert.assertEquals(0, value.getValue().size());

            

Reported by PMD.

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

Line: 17

                      Assert.assertNull(value.getValue());
    }

    public void test_empty() throws Exception {
        Entity value = JSON.parseObject("{value:[]}", Entity.class);
        Assert.assertEquals(0, value.getValue().size());
    }

    private static class Entity {

            

Reported by PMD.

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

Line: 19

              
    public void test_empty() throws Exception {
        Entity value = JSON.parseObject("{value:[]}", Entity.class);
        Assert.assertEquals(0, value.getValue().size());
    }

    private static class Entity {

        private Collection value;

            

Reported by PMD.

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

Line: 19

              
    public void test_empty() throws Exception {
        Entity value = JSON.parseObject("{value:[]}", Entity.class);
        Assert.assertEquals(0, value.getValue().size());
    }

    private static class Entity {

        private Collection value;

            

Reported by PMD.

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

Line: 15

                      model.name = "wenshao";
        
        String text = JSON.toJSONString(model);
        System.out.println(text);
    }
    
    @JSONType(includes="name")
    public static class Model {
        public int 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: 9

              import junit.framework.TestCase;

public class JSONTypeIncludesTest extends TestCase {
    public void test_includes() throws Exception {
        Model model = new Model();
        model.id = 1001;
        model.name = "wenshao";
        
        String text = JSON.toJSONString(model);

            

Reported by PMD.

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

Line: 9

              import junit.framework.TestCase;

public class JSONTypeIncludesTest extends TestCase {
    public void test_includes() throws Exception {
        Model model = new Model();
        model.id = 1001;
        model.name = "wenshao";
        
        String text = JSON.toJSONString(model);

            

Reported by PMD.

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

Line: 20

                  
    @JSONType(includes="name")
    public static class Model {
        public int id;
        public String name;
    }
}

            

Reported by PMD.

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

Line: 21

                  @JSONType(includes="name")
    public static class Model {
        public int id;
        public String name;
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/ref/RefTest24.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 RefTest24
        extends TestCase {
    public void test_ref() throws Exception {
        ByteCodeDO codeDO = new ByteCodeDO();
        codeDO.id = 1001;

        Map<String, Object> data = new LinkedHashMap();
        Map<String, Object> m1 = new LinkedHashMap();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

              
        Object o = JSON.parseObject(str, Feature.OrderedField);

        assertEquals(str, JSON.toJSONString(o, SerializerFeature.WriteMapNullValue));
    }

    public static class ByteCodeDO {
        public int id;
    }

            

Reported by PMD.

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

Line: 37

                  }

    public static class ByteCodeDO {
        public int id;
    }

}

            

Reported by PMD.

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

Line: 4

              package com.alibaba.json.bvt.ref;

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

import java.util.HashMap;

            

Reported by PMD.

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

Line: 9

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

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by wenshao on 16/8/23.

            

Reported by PMD.

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

	public void test_0() throws Exception {
		SerializeWriter out = new SerializeWriter(1);
		out.config(SerializerFeature.QuoteFieldNames, true);
		out.config(SerializerFeature.UseSingleQuotes, true);
		out.writeFieldValue(',', "name", (Enum) 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: 19

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

	public void test_1() throws Exception {
		SerializeWriter out = new SerializeWriter(1);
		out.config(SerializerFeature.QuoteFieldNames, true);
		out.config(SerializerFeature.UseSingleQuotes, true);
		out.writeFieldName("名称");
		Assert.assertEquals("'名称':", out.toString());

            

Reported by PMD.

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

Line: 27

              		Assert.assertEquals("'名称':", out.toString());
	}

	public void test_2() throws Exception {
		SerializeWriter out = new SerializeWriter(1);
		out.config(SerializerFeature.QuoteFieldNames, false);
		out.writeFieldName("名称");
		Assert.assertEquals("名称:", out.toString());
	}

            

Reported by PMD.

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

Line: 34

              		Assert.assertEquals("名称:", out.toString());
	}

	public void test_3() throws Exception {
		SerializeWriter out = new SerializeWriter(1);
		out.config(SerializerFeature.QuoteFieldNames, false);
		out.writeFieldName("a\n\n\n\n");
		Assert.assertEquals("\"a\\n\\n\\n\\n\":", 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: 41

              		Assert.assertEquals("\"a\\n\\n\\n\\n\":", out.toString());
	}
	
	public void test_4() throws Exception {
		SerializeWriter out = new SerializeWriter(1);
		out.config(SerializerFeature.QuoteFieldNames, false);
		out.config(SerializerFeature.UseSingleQuotes, true);
		out.writeFieldName("a\n\n\n\n");
		Assert.assertEquals("'a\\n\\n\\n\\n':", out.toString());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/TestSpecial3.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 TestSpecial3 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('\u000B');

            

Reported by PMD.

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

Line: 9

              
public class TestSpecial3 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('\u000B');

            

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('\u000B');
        }


            

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('\u000B');
        }


            

Reported by PMD.

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

    public void test_pattern() throws Exception {
        Assert.assertEquals(Pattern.compile("abc").pattern(), JSON.parseObject("'abc'", Pattern.class).pattern());

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

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

            

Reported by PMD.

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

Line: 18

              public class PatternDeserializerTest extends TestCase {

    public void test_pattern() throws Exception {
        Assert.assertEquals(Pattern.compile("abc").pattern(), JSON.parseObject("'abc'", Pattern.class).pattern());

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

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

            

Reported by PMD.

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

Line: 18

              public class PatternDeserializerTest extends TestCase {

    public void test_pattern() throws Exception {
        Assert.assertEquals(Pattern.compile("abc").pattern(), JSON.parseObject("'abc'", Pattern.class).pattern());

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

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

            

Reported by PMD.

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

Line: 23

                      Assert.assertEquals(null, JSON.parseObject("null", Pattern.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());
    }
}

            

Reported by PMD.

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

Line: 24

              
        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());
    }
}

            

Reported by PMD.

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

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void test_0() throws Exception {
        Map root = Collections.singletonMap("company", //
                                            Collections.singletonMap("departs", //
                                                                     Arrays.asList( //
                                                                                    Collections.singletonMap("id",

            

Reported by PMD.

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

Line: 30

                                                          ));

        List<Object> ids = (List<Object>) JSONPath.eval(root, "$..id");
        Assert.assertEquals(3, ids.size());
        Assert.assertEquals(1001, ids.get(0));
        Assert.assertEquals(1002, ids.get(1));
        Assert.assertEquals(1003, ids.get(2));
    }


            

Reported by PMD.

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

Line: 31

              
        List<Object> ids = (List<Object>) JSONPath.eval(root, "$..id");
        Assert.assertEquals(3, ids.size());
        Assert.assertEquals(1001, ids.get(0));
        Assert.assertEquals(1002, ids.get(1));
        Assert.assertEquals(1003, ids.get(2));
    }

    public static class Root {

            

Reported by PMD.

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

Line: 32

                      List<Object> ids = (List<Object>) JSONPath.eval(root, "$..id");
        Assert.assertEquals(3, ids.size());
        Assert.assertEquals(1001, ids.get(0));
        Assert.assertEquals(1002, ids.get(1));
        Assert.assertEquals(1003, ids.get(2));
    }

    public static class Root {


            

Reported by PMD.

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

Line: 33

                      Assert.assertEquals(3, ids.size());
        Assert.assertEquals(1001, ids.get(0));
        Assert.assertEquals(1002, ids.get(1));
        Assert.assertEquals(1003, ids.get(2));
    }

    public static class Root {

    }

            

Reported by PMD.