The following issues were found

src/test/java/com/alibaba/json/bvt/parser/deser/list/ArrayListStringDeserializerTest.java
30 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: 19

              import com.alibaba.fastjson.parser.ParserConfig;

public class ArrayListStringDeserializerTest extends TestCase {
    public void test_null() throws Exception {
        Assert.assertNull(JSON.parseObject("null", new TypeReference<List<String>>() {
        }));
        
        Assert.assertNull(JSON.parseArray("null", new Type[] {new TypeReference<List<String>>() {
        }.getType()}));

            

Reported by PMD.

The String literal 'null' appears 8 times in this file; the first occurrence is on line 20
Error

Line: 20

              
public class ArrayListStringDeserializerTest extends TestCase {
    public void test_null() throws Exception {
        Assert.assertNull(JSON.parseObject("null", new TypeReference<List<String>>() {
        }));
        
        Assert.assertNull(JSON.parseArray("null", new Type[] {new TypeReference<List<String>>() {
        }.getType()}));
        

            

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

                      }.getType()}).get(0));
    }

    public void test_strings() throws Exception {
        Entity a = JSON.parseObject("{units:['NANOSECONDS', 'SECONDS', 3, null]}", Entity.class);
        Assert.assertEquals("NANOSECONDS", a.getUnits().get(0));
        Assert.assertEquals("SECONDS", a.getUnits().get(1));
        Assert.assertEquals("3", a.getUnits().get(2));
        Assert.assertEquals(null, a.getUnits().get(3));

            

Reported by PMD.

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

Line: 39

              
    public void test_strings() throws Exception {
        Entity a = JSON.parseObject("{units:['NANOSECONDS', 'SECONDS', 3, null]}", Entity.class);
        Assert.assertEquals("NANOSECONDS", a.getUnits().get(0));
        Assert.assertEquals("SECONDS", a.getUnits().get(1));
        Assert.assertEquals("3", a.getUnits().get(2));
        Assert.assertEquals(null, a.getUnits().get(3));

    }

            

Reported by PMD.

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

Line: 39

              
    public void test_strings() throws Exception {
        Entity a = JSON.parseObject("{units:['NANOSECONDS', 'SECONDS', 3, null]}", Entity.class);
        Assert.assertEquals("NANOSECONDS", a.getUnits().get(0));
        Assert.assertEquals("SECONDS", a.getUnits().get(1));
        Assert.assertEquals("3", a.getUnits().get(2));
        Assert.assertEquals(null, a.getUnits().get(3));

    }

            

Reported by PMD.

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

Line: 39

              
    public void test_strings() throws Exception {
        Entity a = JSON.parseObject("{units:['NANOSECONDS', 'SECONDS', 3, null]}", Entity.class);
        Assert.assertEquals("NANOSECONDS", a.getUnits().get(0));
        Assert.assertEquals("SECONDS", a.getUnits().get(1));
        Assert.assertEquals("3", a.getUnits().get(2));
        Assert.assertEquals(null, a.getUnits().get(3));

    }

            

Reported by PMD.

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

Line: 40

                  public void test_strings() throws Exception {
        Entity a = JSON.parseObject("{units:['NANOSECONDS', 'SECONDS', 3, null]}", Entity.class);
        Assert.assertEquals("NANOSECONDS", a.getUnits().get(0));
        Assert.assertEquals("SECONDS", a.getUnits().get(1));
        Assert.assertEquals("3", a.getUnits().get(2));
        Assert.assertEquals(null, a.getUnits().get(3));

    }


            

Reported by PMD.

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

Line: 40

                  public void test_strings() throws Exception {
        Entity a = JSON.parseObject("{units:['NANOSECONDS', 'SECONDS', 3, null]}", Entity.class);
        Assert.assertEquals("NANOSECONDS", a.getUnits().get(0));
        Assert.assertEquals("SECONDS", a.getUnits().get(1));
        Assert.assertEquals("3", a.getUnits().get(2));
        Assert.assertEquals(null, a.getUnits().get(3));

    }


            

Reported by PMD.

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

Line: 40

                  public void test_strings() throws Exception {
        Entity a = JSON.parseObject("{units:['NANOSECONDS', 'SECONDS', 3, null]}", Entity.class);
        Assert.assertEquals("NANOSECONDS", a.getUnits().get(0));
        Assert.assertEquals("SECONDS", a.getUnits().get(1));
        Assert.assertEquals("3", a.getUnits().get(2));
        Assert.assertEquals(null, a.getUnits().get(3));

    }


            

Reported by PMD.

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

Line: 41

                      Entity a = JSON.parseObject("{units:['NANOSECONDS', 'SECONDS', 3, null]}", Entity.class);
        Assert.assertEquals("NANOSECONDS", a.getUnits().get(0));
        Assert.assertEquals("SECONDS", a.getUnits().get(1));
        Assert.assertEquals("3", a.getUnits().get(2));
        Assert.assertEquals(null, a.getUnits().get(3));

    }

    public void test_strings_() throws Exception {

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/ListSerializer.java
30 issues
The class 'ListSerializer' has a Standard Cyclomatic Complexity of 20 (Highest = 19).
Design

Line: 27

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public final class ListSerializer implements ObjectSerializer {

    public static final ListSerializer instance = new ListSerializer();

    public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

            

Reported by PMD.

The class 'ListSerializer' has a Modified Cyclomatic Complexity of 20 (Highest = 19).
Design

Line: 27

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public final class ListSerializer implements ObjectSerializer {

    public static final ListSerializer instance = new ListSerializer();

    public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

            

Reported by PMD.

The method 'write' has a Modified Cyclomatic Complexity of 19.
Design

Line: 31

              
    public static final ListSerializer instance = new ListSerializer();

    public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

        boolean writeClassName = serializer.out.isEnabled(SerializerFeature.WriteClassName)
                || SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName);


            

Reported by PMD.

Avoid really long methods.
Design

Line: 31

              
    public static final ListSerializer instance = new ListSerializer();

    public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

        boolean writeClassName = serializer.out.isEnabled(SerializerFeature.WriteClassName)
                || SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName);


            

Reported by PMD.

The method 'write' has a Standard Cyclomatic Complexity of 19.
Design

Line: 31

              
    public static final ListSerializer instance = new ListSerializer();

    public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

        boolean writeClassName = serializer.out.isEnabled(SerializerFeature.WriteClassName)
                || SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName);


            

Reported by PMD.

The method 'write(JSONSerializer, Object, Object, Type, int)' has an NPath complexity of 1736, current threshold is 200
Design

Line: 31

              
    public static final ListSerializer instance = new ListSerializer();

    public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

        boolean writeClassName = serializer.out.isEnabled(SerializerFeature.WriteClassName)
                || SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName);


            

Reported by PMD.

The method 'write(JSONSerializer, Object, Object, Type, int)' has a cyclomatic complexity of 20.
Design

Line: 31

              
    public static final ListSerializer instance = new ListSerializer();

    public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

        boolean writeClassName = serializer.out.isEnabled(SerializerFeature.WriteClassName)
                || SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName);


            

Reported by PMD.

The method 'write(JSONSerializer, Object, Object, Type, int)' has a NCSS line count of 79.
Design

Line: 31

              
    public static final ListSerializer instance = new ListSerializer();

    public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

        boolean writeClassName = serializer.out.isEnabled(SerializerFeature.WriteClassName)
                || SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName);


            

Reported by PMD.

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

Line: 34

                  public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
                                                                                                       throws IOException {

        boolean writeClassName = serializer.out.isEnabled(SerializerFeature.WriteClassName)
                || SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName);

        SerializeWriter out = serializer.out;

        Type elementType = null;

            

Reported by PMD.

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

Line: 51

              
        List<?> list = (List<?>) object;

        if (list.size() == 0) {
            out.append("[]");
            return;
        }

        SerialContext context = serializer.context;

            

Reported by PMD.

src/test/java/com/alibaba/fastjson/deserializer/issue2779/LargeJavaBean.java
30 issues
This class has a bunch of public methods and attributes
Design

Line: 1

              package com.alibaba.fastjson.deserializer.issue2779;

import java.util.List;

public class LargeJavaBean {
    public List<Alphabet> getList100() {
        return list100;
    }


            

Reported by PMD.

The class 'LargeJavaBean' has a total cyclomatic complexity of 128 (highest 1).
Design

Line: 5

              
import java.util.List;

public class LargeJavaBean {
    public List<Alphabet> getList100() {
        return list100;
    }

    public void setList100(List<Alphabet> list100) {

            

Reported by PMD.

Too many fields
Design

Line: 5

              
import java.util.List;

public class LargeJavaBean {
    public List<Alphabet> getList100() {
        return list100;
    }

    public void setList100(List<Alphabet> list100) {

            

Reported by PMD.

Too many fields
Design

Line: 585

                  private List<Alphabet> list163;


    public static class Alphabet {
        // provide by zhaiyao, for fastjson test
        private List<Double> a;
        private List<Double> b;
        private List<Double> c;
        private List<Double> d;

            

Reported by PMD.

Avoid unused private fields such as 'a'.
Design

Line: 587

              
    public static class Alphabet {
        // provide by zhaiyao, for fastjson test
        private List<Double> a;
        private List<Double> b;
        private List<Double> c;
        private List<Double> d;
        private List<Double> e;
        private List<Double> f;

            

Reported by PMD.

Avoid unused private fields such as 'b'.
Design

Line: 588

                  public static class Alphabet {
        // provide by zhaiyao, for fastjson test
        private List<Double> a;
        private List<Double> b;
        private List<Double> c;
        private List<Double> d;
        private List<Double> e;
        private List<Double> f;
        private List<Double> g;

            

Reported by PMD.

Avoid unused private fields such as 'c'.
Design

Line: 589

                      // provide by zhaiyao, for fastjson test
        private List<Double> a;
        private List<Double> b;
        private List<Double> c;
        private List<Double> d;
        private List<Double> e;
        private List<Double> f;
        private List<Double> g;
        private List<Double> h;

            

Reported by PMD.

Avoid unused private fields such as 'd'.
Design

Line: 590

                      private List<Double> a;
        private List<Double> b;
        private List<Double> c;
        private List<Double> d;
        private List<Double> e;
        private List<Double> f;
        private List<Double> g;
        private List<Double> h;
        private List<Double> i;

            

Reported by PMD.

Avoid unused private fields such as 'e'.
Design

Line: 591

                      private List<Double> b;
        private List<Double> c;
        private List<Double> d;
        private List<Double> e;
        private List<Double> f;
        private List<Double> g;
        private List<Double> h;
        private List<Double> i;
        private List<Double> j;

            

Reported by PMD.

Avoid unused private fields such as 'f'.
Design

Line: 592

                      private List<Double> c;
        private List<Double> d;
        private List<Double> e;
        private List<Double> f;
        private List<Double> g;
        private List<Double> h;
        private List<Double> i;
        private List<Double> j;
        private List<Double> k;

            

Reported by PMD.

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

    public void test_enum() throws Exception {
        Assert.assertEquals(Type.A, JSON.parseObject("\"A\"", Type.class));
        Assert.assertEquals(Type.A, JSON.parseObject("" + Type.A.ordinal(), Type.class));
        Assert.assertEquals(Type.B, JSON.parseObject("" + Type.B.ordinal(), Type.class));
        Assert.assertEquals(Type.C, JSON.parseObject("" + Type.C.ordinal(), Type.class));
    }

            

Reported by PMD.

Do not add empty strings
Performance

Line: 18

              
    public void test_enum() throws Exception {
        Assert.assertEquals(Type.A, JSON.parseObject("\"A\"", Type.class));
        Assert.assertEquals(Type.A, JSON.parseObject("" + Type.A.ordinal(), Type.class));
        Assert.assertEquals(Type.B, JSON.parseObject("" + Type.B.ordinal(), Type.class));
        Assert.assertEquals(Type.C, JSON.parseObject("" + Type.C.ordinal(), Type.class));
    }

    public void test_enum_2() throws Exception {

            

Reported by PMD.

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

Line: 18

              
    public void test_enum() throws Exception {
        Assert.assertEquals(Type.A, JSON.parseObject("\"A\"", Type.class));
        Assert.assertEquals(Type.A, JSON.parseObject("" + Type.A.ordinal(), Type.class));
        Assert.assertEquals(Type.B, JSON.parseObject("" + Type.B.ordinal(), Type.class));
        Assert.assertEquals(Type.C, JSON.parseObject("" + Type.C.ordinal(), Type.class));
    }

    public void test_enum_2() throws Exception {

            

Reported by PMD.

Do not add empty strings
Performance

Line: 19

                  public void test_enum() throws Exception {
        Assert.assertEquals(Type.A, JSON.parseObject("\"A\"", Type.class));
        Assert.assertEquals(Type.A, JSON.parseObject("" + Type.A.ordinal(), Type.class));
        Assert.assertEquals(Type.B, JSON.parseObject("" + Type.B.ordinal(), Type.class));
        Assert.assertEquals(Type.C, JSON.parseObject("" + Type.C.ordinal(), Type.class));
    }

    public void test_enum_2() throws Exception {
        Assert.assertEquals(Type.A, TypeUtils.cast("A", Type.class, null));

            

Reported by PMD.

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

Line: 19

                  public void test_enum() throws Exception {
        Assert.assertEquals(Type.A, JSON.parseObject("\"A\"", Type.class));
        Assert.assertEquals(Type.A, JSON.parseObject("" + Type.A.ordinal(), Type.class));
        Assert.assertEquals(Type.B, JSON.parseObject("" + Type.B.ordinal(), Type.class));
        Assert.assertEquals(Type.C, JSON.parseObject("" + Type.C.ordinal(), Type.class));
    }

    public void test_enum_2() throws Exception {
        Assert.assertEquals(Type.A, TypeUtils.cast("A", Type.class, null));

            

Reported by PMD.

Do not add empty strings
Performance

Line: 20

                      Assert.assertEquals(Type.A, JSON.parseObject("\"A\"", Type.class));
        Assert.assertEquals(Type.A, JSON.parseObject("" + Type.A.ordinal(), Type.class));
        Assert.assertEquals(Type.B, JSON.parseObject("" + Type.B.ordinal(), Type.class));
        Assert.assertEquals(Type.C, JSON.parseObject("" + Type.C.ordinal(), Type.class));
    }

    public void test_enum_2() throws Exception {
        Assert.assertEquals(Type.A, TypeUtils.cast("A", Type.class, null));
        Assert.assertEquals(Type.A, TypeUtils.cast(Type.A.ordinal(), Type.class, null));

            

Reported by PMD.

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

Line: 20

                      Assert.assertEquals(Type.A, JSON.parseObject("\"A\"", Type.class));
        Assert.assertEquals(Type.A, JSON.parseObject("" + Type.A.ordinal(), Type.class));
        Assert.assertEquals(Type.B, JSON.parseObject("" + Type.B.ordinal(), Type.class));
        Assert.assertEquals(Type.C, JSON.parseObject("" + Type.C.ordinal(), Type.class));
    }

    public void test_enum_2() throws Exception {
        Assert.assertEquals(Type.A, TypeUtils.cast("A", Type.class, null));
        Assert.assertEquals(Type.A, TypeUtils.cast(Type.A.ordinal(), Type.class, 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: 23

                      Assert.assertEquals(Type.C, JSON.parseObject("" + Type.C.ordinal(), Type.class));
    }

    public void test_enum_2() throws Exception {
        Assert.assertEquals(Type.A, TypeUtils.cast("A", Type.class, null));
        Assert.assertEquals(Type.A, TypeUtils.cast(Type.A.ordinal(), Type.class, null));
        Assert.assertEquals(Type.B, TypeUtils.cast(Type.B.ordinal(), Type.class, null));
    }


            

Reported by PMD.

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

Line: 25

              
    public void test_enum_2() throws Exception {
        Assert.assertEquals(Type.A, TypeUtils.cast("A", Type.class, null));
        Assert.assertEquals(Type.A, TypeUtils.cast(Type.A.ordinal(), Type.class, null));
        Assert.assertEquals(Type.B, TypeUtils.cast(Type.B.ordinal(), Type.class, null));
    }

    public void test_error() throws Exception {
        assertNull(TypeUtils.castToEnum("\"A1\"", Type.class, null));

            

Reported by PMD.

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

Line: 26

                  public void test_enum_2() throws Exception {
        Assert.assertEquals(Type.A, TypeUtils.cast("A", Type.class, null));
        Assert.assertEquals(Type.A, TypeUtils.cast(Type.A.ordinal(), Type.class, null));
        Assert.assertEquals(Type.B, TypeUtils.cast(Type.B.ordinal(), Type.class, null));
    }

    public void test_error() throws Exception {
        assertNull(TypeUtils.castToEnum("\"A1\"", Type.class, null));
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_3300/Issue3334.java
30 issues
Do not use the short type
Performance

Line: 50

              
    public static class VO {
        private byte id8;
        private short id16;
        private int id;
        private long id64;
        private Float floatValue;
        private Double doubleValue;


            

Reported by PMD.

Do not use the short type
Performance

Line: 72

                          this.id64 = id64;
        }

        public short getId16() {
            return id16;
        }

        public void setId16(short id16) {
            this.id16 = id16;

            

Reported by PMD.

Do not use the short type
Performance

Line: 76

                          return id16;
        }

        public void setId16(short id16) {
            this.id16 = id16;
        }

        public byte getId8() {
            return id8;

            

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 Issue3334 extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals(0,
                JSON.parseObject("{\"id\":false}", VO.class).id);

        assertEquals(1,
                JSON.parseObject("{\"id\":true}", VO.class).id);

            

Reported by PMD.

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

Line: 7

              import junit.framework.TestCase;

public class Issue3334 extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals(0,
                JSON.parseObject("{\"id\":false}", VO.class).id);

        assertEquals(1,
                JSON.parseObject("{\"id\":true}", VO.class).id);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 8

              
public class Issue3334 extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals(0,
                JSON.parseObject("{\"id\":false}", VO.class).id);

        assertEquals(1,
                JSON.parseObject("{\"id\":true}", VO.class).id);


            

Reported by PMD.

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

Line: 9

              public class Issue3334 extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals(0,
                JSON.parseObject("{\"id\":false}", VO.class).id);

        assertEquals(1,
                JSON.parseObject("{\"id\":true}", VO.class).id);



            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 11

                      assertEquals(0,
                JSON.parseObject("{\"id\":false}", VO.class).id);

        assertEquals(1,
                JSON.parseObject("{\"id\":true}", VO.class).id);


        assertEquals(0,
                JSON.parseObject("{\"id64\":false}", VO.class).id64);

            

Reported by PMD.

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

Line: 12

                              JSON.parseObject("{\"id\":false}", VO.class).id);

        assertEquals(1,
                JSON.parseObject("{\"id\":true}", VO.class).id);


        assertEquals(0,
                JSON.parseObject("{\"id64\":false}", VO.class).id64);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                              JSON.parseObject("{\"id\":true}", VO.class).id);


        assertEquals(0,
                JSON.parseObject("{\"id64\":false}", VO.class).id64);

        assertEquals(1,
                JSON.parseObject("{\"id64\":true}", VO.class).id64);


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/SimplePropertyPreFilterTest.java
30 issues
This class has too many methods, consider refactoring it.
Design

Line: 12

              import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;

public class SimplePropertyPreFilterTest extends TestCase {

    private VO vo;
    
    private A a;
    

            

Reported by PMD.

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

Line: 14

              
public class SimplePropertyPreFilterTest extends TestCase {

    private VO vo;
    
    private A a;
    
    private Map<String, Object> map;


            

Reported by PMD.

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

Line: 16

              
    private VO vo;
    
    private A a;
    
    private Map<String, Object> map;

    protected void setUp() throws Exception {
        vo = new VO();

            

Reported by PMD.

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

Line: 18

                  
    private A a;
    
    private Map<String, Object> map;

    protected void setUp() throws Exception {
        vo = new VO();
        vo.setId(123);
        vo.setName("sandzhangtoo");

            

Reported by PMD.

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

Line: 20

                  
    private Map<String, Object> map;

    protected void setUp() throws Exception {
        vo = new VO();
        vo.setId(123);
        vo.setName("sandzhangtoo");
        
        a = new A();

            

Reported by PMD.

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

Line: 31

                      
        map = new HashMap<String, Object>();
        map.put("id", 123);
        map.put("name", "sandzhangtoo");
        map.put(null, null);
    }

    public void test_name() throws Exception {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");

            

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

                      map.put(null, null);
    }

    public void test_name() throws Exception {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");
        Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
    }
    
    public void test_name_0() throws Exception {

            

Reported by PMD.

The String literal '{\'name\':\'sandzhangtoo\'}' appears 6 times in this file; the first occurrence is on line 37
Error

Line: 37

              
    public void test_name() throws Exception {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");
        Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
    }
    
    public void test_name_0() throws Exception {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter("name");
        Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));

            

Reported by PMD.

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

Line: 40

                      Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
    }
    
    public void test_name_0() throws Exception {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter("name");
        Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
    }
    
    public void test_name_a() 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: 45

                      Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
    }
    
    public void test_name_a() throws Exception {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");
        Assert.assertEquals(VO.class, filter.getClazz());
        Assert.assertEquals(1, filter.getIncludes().size());
        Assert.assertTrue(filter.apply(null, null, null));
        

            

Reported by PMD.

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

Line: 58

                      int len = data.length;

        if ((len & 0x01) != 0) {
            throw new Exception("Odd number of characters.");
        }

        byte[] out = new byte[len >> 1];

        // two characters form the hex value.

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 78

                  protected static int toDigit(char ch, int index) throws Exception {
        int digit = Character.digit(ch, 16);
        if (digit == -1) {
            throw new Exception("Illegal hexadecimal character " + ch + " at index " + index);
        }
        return digit;
    }
}

            

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

              
public class TestUTF8_2 extends TestCase {

    public void test_utf_1() throws Exception {
        String content = new String(decodeHex("F0A4ADA2".toCharArray()), "UTF-8");
        JSONObject json = new JSONObject();
        json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());

            

Reported by PMD.

The String literal 'UTF-8' appears 8 times in this file; the first occurrence is on line 14
Error

Line: 14

              public class TestUTF8_2 extends TestCase {

    public void test_utf_1() throws Exception {
        String content = new String(decodeHex("F0A4ADA2".toCharArray()), "UTF-8");
        JSONObject json = new JSONObject();
        json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());
        Assert.assertEquals(content, obj.get("content"));

            

Reported by PMD.

The String literal 'content' appears 8 times in this file; the first occurrence is on line 16
Error

Line: 16

                  public void test_utf_1() throws Exception {
        String content = new String(decodeHex("F0A4ADA2".toCharArray()), "UTF-8");
        JSONObject json = new JSONObject();
        json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());
        Assert.assertEquals(content, obj.get("content"));
    }


            

Reported by PMD.

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

Line: 17

                      String content = new String(decodeHex("F0A4ADA2".toCharArray()), "UTF-8");
        JSONObject json = new JSONObject();
        json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());
        Assert.assertEquals(content, obj.get("content"));
    }

    public void test_utf_2() throws Exception {

            

Reported by PMD.

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

Line: 18

                      JSONObject json = new JSONObject();
        json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());
        Assert.assertEquals(content, obj.get("content"));
    }

    public void test_utf_2() throws Exception {
        String content = new String(decodeHex("E282AC".toCharArray()), "UTF-8");

            

Reported by PMD.

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

Line: 19

                      json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());
        Assert.assertEquals(content, obj.get("content"));
    }

    public void test_utf_2() throws Exception {
        String content = new String(decodeHex("E282AC".toCharArray()), "UTF-8");
        JSONObject json = new JSONObject();

            

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

                      Assert.assertEquals(content, obj.get("content"));
    }

    public void test_utf_2() throws Exception {
        String content = new String(decodeHex("E282AC".toCharArray()), "UTF-8");
        JSONObject json = new JSONObject();
        json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());

            

Reported by PMD.

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

Line: 26

                      String content = new String(decodeHex("E282AC".toCharArray()), "UTF-8");
        JSONObject json = new JSONObject();
        json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());
        Assert.assertEquals(content, obj.get("content"));
    }

    public void test_utf_3() throws Exception {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/generic/ByteListTest.java
29 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 12

               * Created by wenshao on 20/01/2017.
 */
public class ByteListTest extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"values\":[[1,2,3]]}", Model.class);

        assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 20/01/2017.
 */
public class ByteListTest extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"values\":[[1,2,3]]}", Model.class);

        assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                  public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"values\":[[1,2,3]]}", Model.class);

        assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());
        assertEquals(Byte.class, model.values[0].get(1).getClass());
        assertEquals(Byte.class, model.values[0].get(2).getClass());
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      Model model = JSON.parseObject("{\"values\":[[1,2,3]]}", Model.class);

        assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());
        assertEquals(Byte.class, model.values[0].get(1).getClass());
        assertEquals(Byte.class, model.values[0].get(2).getClass());
    }


            

Reported by PMD.

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

Line: 17

              
        assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());
        assertEquals(Byte.class, model.values[0].get(1).getClass());
        assertEquals(Byte.class, model.values[0].get(2).getClass());
    }

    public void test_for_List() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              
        assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());
        assertEquals(Byte.class, model.values[0].get(1).getClass());
        assertEquals(Byte.class, model.values[0].get(2).getClass());
    }

    public void test_for_List() throws Exception {

            

Reported by PMD.

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

Line: 17

              
        assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());
        assertEquals(Byte.class, model.values[0].get(1).getClass());
        assertEquals(Byte.class, model.values[0].get(2).getClass());
    }

    public void test_for_List() throws Exception {

            

Reported by PMD.

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

Line: 18

                      assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());
        assertEquals(Byte.class, model.values[0].get(1).getClass());
        assertEquals(Byte.class, model.values[0].get(2).getClass());
    }

    public void test_for_List() throws Exception {
        Model2 model = JSON.parseObject("{\"values\":[1,2,3]}", Model2.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());
        assertEquals(Byte.class, model.values[0].get(1).getClass());
        assertEquals(Byte.class, model.values[0].get(2).getClass());
    }

    public void test_for_List() throws Exception {
        Model2 model = JSON.parseObject("{\"values\":[1,2,3]}", Model2.class);

            

Reported by PMD.

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

Line: 18

                      assertNotNull(model.values);
        assertEquals(3, model.values[0].size());
        assertEquals(Byte.class, model.values[0].get(0).getClass());
        assertEquals(Byte.class, model.values[0].get(1).getClass());
        assertEquals(Byte.class, model.values[0].get(2).getClass());
    }

    public void test_for_List() throws Exception {
        Model2 model = JSON.parseObject("{\"values\":[1,2,3]}", Model2.class);

            

Reported by PMD.

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

Line: 13

              
public class Issue2185 extends TestCase {

    public void test_for_issue() throws Exception {
        Exception error = null;
        try {
            JSONObject origin = new JSONObject();
            JSONArray jsonArray = new JSONArray().fluentAdd(origin.getInnerMap());
            jsonArray.getJSONObject(0).put("key", "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: 13

              
public class Issue2185 extends TestCase {

    public void test_for_issue() throws Exception {
        Exception error = null;
        try {
            JSONObject origin = new JSONObject();
            JSONArray jsonArray = new JSONArray().fluentAdd(origin.getInnerMap());
            jsonArray.getJSONObject(0).put("key", "value");

            

Reported by PMD.

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

Line: 18

                      try {
            JSONObject origin = new JSONObject();
            JSONArray jsonArray = new JSONArray().fluentAdd(origin.getInnerMap());
            jsonArray.getJSONObject(0).put("key", "value");
            // now we expect jsonArray is [{"key":"value"}]
            assertEquals(1, jsonArray.getJSONObject(0).size());
            assertTrue(origin.getInnerMap() == jsonArray.getJSONObject(0).getInnerMap());
        } catch (JSONException ex) {
            error = ex;

            

Reported by PMD.

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

Line: 18

                      try {
            JSONObject origin = new JSONObject();
            JSONArray jsonArray = new JSONArray().fluentAdd(origin.getInnerMap());
            jsonArray.getJSONObject(0).put("key", "value");
            // now we expect jsonArray is [{"key":"value"}]
            assertEquals(1, jsonArray.getJSONObject(0).size());
            assertTrue(origin.getInnerMap() == jsonArray.getJSONObject(0).getInnerMap());
        } catch (JSONException ex) {
            error = ex;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                          JSONArray jsonArray = new JSONArray().fluentAdd(origin.getInnerMap());
            jsonArray.getJSONObject(0).put("key", "value");
            // now we expect jsonArray is [{"key":"value"}]
            assertEquals(1, jsonArray.getJSONObject(0).size());
            assertTrue(origin.getInnerMap() == jsonArray.getJSONObject(0).getInnerMap());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNull(error);

            

Reported by PMD.

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

Line: 20

                          JSONArray jsonArray = new JSONArray().fluentAdd(origin.getInnerMap());
            jsonArray.getJSONObject(0).put("key", "value");
            // now we expect jsonArray is [{"key":"value"}]
            assertEquals(1, jsonArray.getJSONObject(0).size());
            assertTrue(origin.getInnerMap() == jsonArray.getJSONObject(0).getInnerMap());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNull(error);

            

Reported by PMD.

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

Line: 21

                          jsonArray.getJSONObject(0).put("key", "value");
            // now we expect jsonArray is [{"key":"value"}]
            assertEquals(1, jsonArray.getJSONObject(0).size());
            assertTrue(origin.getInnerMap() == jsonArray.getJSONObject(0).getInnerMap());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNull(error);
    }

            

Reported by PMD.

Use assertSame(x, y) instead of assertTrue(x==y), or assertNotSame(x,y) vs assertFalse(x==y)
Design

Line: 21

                          jsonArray.getJSONObject(0).put("key", "value");
            // now we expect jsonArray is [{"key":"value"}]
            assertEquals(1, jsonArray.getJSONObject(0).size());
            assertTrue(origin.getInnerMap() == jsonArray.getJSONObject(0).getInnerMap());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNull(error);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                          jsonArray.getJSONObject(0).put("key", "value");
            // now we expect jsonArray is [{"key":"value"}]
            assertEquals(1, jsonArray.getJSONObject(0).size());
            assertTrue(origin.getInnerMap() == jsonArray.getJSONObject(0).getInnerMap());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNull(error);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

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

    /**
     * To prove casting from Map&lt;Object,Object&gt; won't cause exception
     *

            

Reported by PMD.

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

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

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

            

Reported by PMD.

The String literal 'ljw2083' appears 8 times in this file; the first occurrence is on line 18
Error

Line: 18

                      JSONPath path = new JSONPath("$[?(@.name like 'ljw2083')]");

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

        List<Object> result = (List<Object>) path.eval(entities);

            

Reported by PMD.

The String literal 'wenshao' appears 8 times in this file; the first occurrence is on line 19
Error

Line: 19

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

        List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(1, result.size());

            

Reported by PMD.

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

Line: 24

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

        List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(1, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
    }
    
    public void test_list_not_like_extract() throws Exception {
        JSONPath path = new JSONPath("$[?(@.name not like 'ljw2083')]");

            

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(1, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
    }
    
    public void test_list_not_like_extract() throws Exception {
        JSONPath path = new JSONPath("$[?(@.name not like 'ljw2083')]");


            

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.assertSame(entities.get(0), result.get(0));
    }
    
    public void test_list_not_like_extract() throws Exception {
        JSONPath path = new JSONPath("$[?(@.name not like 'ljw2083')]");

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

            

Reported by PMD.

The String literal 'yakolee' appears 7 times in this file; the first occurrence is on line 34
Error

Line: 34

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

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

            

Reported by PMD.

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

Line: 38

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

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

            

Reported by PMD.

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

Line: 39

              
        List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(3, result.size());
        Assert.assertSame(entities.get(1), result.get(0));
        Assert.assertSame(entities.get(2), result.get(1));
        Assert.assertSame(entities.get(3), result.get(2));
    }
    
    public void test_list_like_left_match() throws Exception {

            

Reported by PMD.

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

Line: 40

                      List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(3, result.size());
        Assert.assertSame(entities.get(1), result.get(0));
        Assert.assertSame(entities.get(2), result.get(1));
        Assert.assertSame(entities.get(3), result.get(2));
    }
    
    public void test_list_like_left_match() throws Exception {
        JSONPath path = new JSONPath("$[?(@.name like 'ljw%')]");

            

Reported by PMD.