The following issues were found

src/test/java/com/alibaba/json/bvt/issue_1700/Issue1733_jsonpath.java
31 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

              import java.util.List;

public class Issue1733_jsonpath extends TestCase {
    public void test_for_issue() throws Exception {
        Order order = new Order();
        order.books.add(new Book(10, "动漫"));
        order.books.add(new Book(50, "科幻"));
        order.books.add(new Book(60, "历史"));


            

Reported by PMD.

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

Line: 12

              import java.util.List;

public class Issue1733_jsonpath extends TestCase {
    public void test_for_issue() throws Exception {
        Order order = new Order();
        order.books.add(new Book(10, "动漫"));
        order.books.add(new Book(50, "科幻"));
        order.books.add(new Book(60, "历史"));


            

Reported by PMD.

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

Line: 20

              
        String path = "$.books[price>20 && category = '科幻']";
        List result = (List) JSONPath.eval(order, path);
        assertSame(1, result.size());
        assertSame(order.books.get(1), result.get(0));
    }

    public void test_for_issue_or() throws Exception {
        Order order = new Order();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        String path = "$.books[price>20 && category = '科幻']";
        List result = (List) JSONPath.eval(order, path);
        assertSame(1, result.size());
        assertSame(order.books.get(1), result.get(0));
    }

    public void test_for_issue_or() throws Exception {
        Order order = new Order();

            

Reported by PMD.

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

Line: 21

                      String path = "$.books[price>20 && category = '科幻']";
        List result = (List) JSONPath.eval(order, path);
        assertSame(1, result.size());
        assertSame(order.books.get(1), result.get(0));
    }

    public void test_for_issue_or() throws Exception {
        Order order = new Order();
        order.books.add(new Book(10, "动漫"));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      String path = "$.books[price>20 && category = '科幻']";
        List result = (List) JSONPath.eval(order, path);
        assertSame(1, result.size());
        assertSame(order.books.get(1), result.get(0));
    }

    public void test_for_issue_or() throws Exception {
        Order order = new Order();
        order.books.add(new Book(10, "动漫"));

            

Reported by PMD.

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

Line: 21

                      String path = "$.books[price>20 && category = '科幻']";
        List result = (List) JSONPath.eval(order, path);
        assertSame(1, result.size());
        assertSame(order.books.get(1), result.get(0));
    }

    public void test_for_issue_or() throws Exception {
        Order order = new Order();
        order.books.add(new Book(10, "动漫"));

            

Reported by PMD.

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

Line: 24

                      assertSame(order.books.get(1), result.get(0));
    }

    public void test_for_issue_or() throws Exception {
        Order order = new Order();
        order.books.add(new Book(10, "动漫"));
        order.books.add(new Book(50, "科幻"));
        order.books.add(new Book(60, "历史"));


            

Reported by PMD.

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

Line: 24

                      assertSame(order.books.get(1), result.get(0));
    }

    public void test_for_issue_or() throws Exception {
        Order order = new Order();
        order.books.add(new Book(10, "动漫"));
        order.books.add(new Book(50, "科幻"));
        order.books.add(new Book(60, "历史"));


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 32

              
        String path = "$.books[price>20||category = '科幻']";
        List result = (List) JSONPath.eval(order, path);
        assertEquals(2, result.size());
        assertSame(order.books.get(1), result.get(0));
        assertSame(order.books.get(2), result.get(1));
    }

    public void test_for_issue_or_1() throws Exception {

            

Reported by PMD.

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

    public void test_list_eq() throws Exception {
        JSONPath path = new JSONPath("[name = '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 = '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_eq_x() throws Exception {
        JSONPath path = new JSONPath("[name = '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_eq_x() throws Exception {
        JSONPath path = new JSONPath("[name = '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_eq_x() throws Exception {
        JSONPath path = new JSONPath("[name = 'ljw2083']");
        
        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: 38

                      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_eq_null() throws Exception {
        JSONPath path = new JSONPath("$[name = null]");

            

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(1, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
    }
    
    public void test_list_eq_null() throws Exception {
        JSONPath path = new JSONPath("$[name = 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: 42

                      Assert.assertSame(entities.get(0), result.get(0));
    }
    
    public void test_list_eq_null() throws Exception {
        JSONPath path = new JSONPath("$[name = null]");

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

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

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

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/support/spring/mock/testcase/FastJsonHttpMessageConverterTest.java
31 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 43

              public class FastJsonHttpMessageConverterTest {

    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @Before
    public void setup() {

            

Reported by PMD.

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

Line: 45

                  @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @Before
    public void setup() {
        this.mockMvc = webAppContextSetup(this.wac).build();
    }

            

Reported by PMD.

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

Line: 49

              
    @Before
    public void setup() {
        this.mockMvc = webAppContextSetup(this.wac).build();
    }

    @Test
    public void test1() throws Exception {


            

Reported by PMD.

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

Line: 53

                  }

    @Test
    public void test1() throws Exception {

        JSONObject json = new JSONObject();

        json.put("id", 123);


            

Reported by PMD.

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

Line: 61

              
        json.put("name", "哈哈哈");

        mockMvc.perform(
                (post("/fastjson/test1").characterEncoding("UTF-8").content(
                        json.toJSONString())
                        .contentType(MediaType.APPLICATION_JSON)))
                // .andExpect(status().isOk())
                .andDo(print());

            

Reported by PMD.

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

Line: 62

                      json.put("name", "哈哈哈");

        mockMvc.perform(
                (post("/fastjson/test1").characterEncoding("UTF-8").content(
                        json.toJSONString())
                        .contentType(MediaType.APPLICATION_JSON)))
                // .andExpect(status().isOk())
                .andDo(print());
    }

            

Reported by PMD.

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

Line: 62

                      json.put("name", "哈哈哈");

        mockMvc.perform(
                (post("/fastjson/test1").characterEncoding("UTF-8").content(
                        json.toJSONString())
                        .contentType(MediaType.APPLICATION_JSON)))
                // .andExpect(status().isOk())
                .andDo(print());
    }

            

Reported by PMD.

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

Line: 62

                      json.put("name", "哈哈哈");

        mockMvc.perform(
                (post("/fastjson/test1").characterEncoding("UTF-8").content(
                        json.toJSONString())
                        .contentType(MediaType.APPLICATION_JSON)))
                // .andExpect(status().isOk())
                .andDo(print());
    }

            

Reported by PMD.

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

Line: 62

                      json.put("name", "哈哈哈");

        mockMvc.perform(
                (post("/fastjson/test1").characterEncoding("UTF-8").content(
                        json.toJSONString())
                        .contentType(MediaType.APPLICATION_JSON)))
                // .andExpect(status().isOk())
                .andDo(print());
    }

            

Reported by PMD.

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

Line: 70

                  }

    @Test
    public void test2() throws Exception {

        String jsonStr = "[{\"name\":\"p1\",\"sonList\":[{\"name\":\"s1\"}]},{\"name\":\"p2\",\"sonList\":[{\"name\":\"s2\"},{\"name\":\"s3\"}]}]";

        mockMvc.perform(
                (post("/fastjson/test2").characterEncoding("UTF-8").content(

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/date/DateParseTest9.java
31 issues
Private field 'original' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 19

              public class DateParseTest9 extends TestCase {

    private static Random random = new Random();
    private TimeZone original = TimeZone.getDefault();
    private String[] zoneIds = TimeZone.getAvailableIDs();

    @Override
    public void setUp() {
        int index = random.nextInt(zoneIds.length);

            

Reported by PMD.

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

Line: 19

              public class DateParseTest9 extends TestCase {

    private static Random random = new Random();
    private TimeZone original = TimeZone.getDefault();
    private String[] zoneIds = TimeZone.getAvailableIDs();

    @Override
    public void setUp() {
        int index = random.nextInt(zoneIds.length);

            

Reported by PMD.

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

Line: 20

              
    private static Random random = new Random();
    private TimeZone original = TimeZone.getDefault();
    private String[] zoneIds = TimeZone.getAvailableIDs();

    @Override
    public void setUp() {
        int index = random.nextInt(zoneIds.length);
        TimeZone timeZone = TimeZone.getTimeZone(zoneIds[index]);

            

Reported by PMD.

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

Line: 20

              
    private static Random random = new Random();
    private TimeZone original = TimeZone.getDefault();
    private String[] zoneIds = TimeZone.getAvailableIDs();

    @Override
    public void setUp() {
        int index = random.nextInt(zoneIds.length);
        TimeZone timeZone = TimeZone.getTimeZone(zoneIds[index]);

            

Reported by PMD.

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

Line: 22

                  private TimeZone original = TimeZone.getDefault();
    private String[] zoneIds = TimeZone.getAvailableIDs();

    @Override
    public void setUp() {
        int index = random.nextInt(zoneIds.length);
        TimeZone timeZone = TimeZone.getTimeZone(zoneIds[index]);
        TimeZone.setDefault(timeZone);
        JSON.defaultTimeZone = timeZone;

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 30

                      JSON.defaultTimeZone = timeZone;
    }

    @Override
    public void tearDown () {
        TimeZone.setDefault(original);
        JSON.defaultTimeZone = original;
    }


            

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

                      JSON.defaultTimeZone = original;
    }

    public void test_date() throws Exception {
        String text = "\"/Date(1242357713797+0800)/\"";
        Date date = JSON.parseObject(text, Date.class);
        assertEquals(date.getTime(), 1242357713797L);
        
        assertEquals(JSONToken.LITERAL_INT, CalendarCodec.instance.getFastMatchToken());

            

Reported by PMD.

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

Line: 36

                      JSON.defaultTimeZone = original;
    }

    public void test_date() throws Exception {
        String text = "\"/Date(1242357713797+0800)/\"";
        Date date = JSON.parseObject(text, Date.class);
        assertEquals(date.getTime(), 1242357713797L);
        
        assertEquals(JSONToken.LITERAL_INT, CalendarCodec.instance.getFastMatchToken());

            

Reported by PMD.

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

Line: 39

                  public void test_date() throws Exception {
        String text = "\"/Date(1242357713797+0800)/\"";
        Date date = JSON.parseObject(text, Date.class);
        assertEquals(date.getTime(), 1242357713797L);
        
        assertEquals(JSONToken.LITERAL_INT, CalendarCodec.instance.getFastMatchToken());

        text = "\"/Date(1242357713797+0545)/\"";
        date = JSON.parseObject(text, Date.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  public void test_date() throws Exception {
        String text = "\"/Date(1242357713797+0800)/\"";
        Date date = JSON.parseObject(text, Date.class);
        assertEquals(date.getTime(), 1242357713797L);
        
        assertEquals(JSONToken.LITERAL_INT, CalendarCodec.instance.getFastMatchToken());

        text = "\"/Date(1242357713797+0545)/\"";
        date = JSON.parseObject(text, Date.class);

            

Reported by PMD.

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

    public void test_valuefilter() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 22

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 22

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

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

Line: 23

              
            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }


            

Reported by PMD.

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

Line: 33

              
        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getValueFilters().add(filter);

        A a = new A();
        serializer.write(a);

        String text = 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: 42

                      Assert.assertEquals("{\"id\":\"AAA\"}", text);
    }
    
    public void test_toJSONString() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 46

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 46

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return 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: 58

                      Assert.assertEquals("{\"id\":\"AAA\"}", JSON.toJSONString(new A(), filter));
    }

    public void test_valuefilter_1() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "AAA";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 62

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

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

    public void test_valuefilter() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 21

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 21

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

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

Line: 22

              
            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }


            

Reported by PMD.

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

Line: 32

              
        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getValueFilters().add(filter);

        Bean a = new Bean();
        serializer.write(a);

        String text = 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("{\"id\":\"AAA\"}", text);
    }
    
    public void test_toJSONString() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 45

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 45

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return 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: 57

                      Assert.assertEquals("{\"id\":\"AAA\"}", JSON.toJSONString(new Bean(), filter));
    }

    public void test_valuefilter_1() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "AAA";

            

Reported by PMD.

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

Line: 61

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

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

    public void test_valuefilter() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 21

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 21

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

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

Line: 22

              
            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }


            

Reported by PMD.

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

Line: 32

              
        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getValueFilters().add(filter);

        Bean a = new Bean();
        serializer.write(a);

        String text = 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("{\"id\":\"AAA\"}", text);
    }
    
    public void test_toJSONString() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 45

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 45

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    return "AAA";
                }

                return 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: 57

                      Assert.assertEquals("{\"id\":\"AAA\"}", JSON.toJSONString(new Bean(), filter));
    }

    public void test_valuefilter_1() throws Exception {
        ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "AAA";

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 61

                      ValueFilter filter = new ValueFilter() {

            public Object process(Object source, String name, Object value) {
                if (name.equals("name")) {
                    return "AAA";
                }

                return value;
            }

            

Reported by PMD.

src/test/java/data/media/writeAsArray/MediaSerializer.java
31 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 18

                      Media media = (Media) object;

        SerializeWriter out = serializer.getWriter();
        out.write('[');
        
        out.writeInt(media.getBitrate());
        out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');

            

Reported by PMD.

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

Line: 20

                      SerializeWriter out = serializer.getWriter();
        out.write('[');
        
        out.writeInt(media.getBitrate());
        out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');

            

Reported by PMD.

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

Line: 20

                      SerializeWriter out = serializer.getWriter();
        out.write('[');
        
        out.writeInt(media.getBitrate());
        out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');

            

Reported by PMD.

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

Line: 21

                      out.write('[');
        
        out.writeInt(media.getBitrate());
        out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');
        out.writeString(media.getCopyright(), ',');

            

Reported by PMD.

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

Line: 22

                      
        out.writeInt(media.getBitrate());
        out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');
        out.writeString(media.getCopyright(), ',');
        out.writeLong(media.getDuration());

            

Reported by PMD.

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

Line: 22

                      
        out.writeInt(media.getBitrate());
        out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');
        out.writeString(media.getCopyright(), ',');
        out.writeLong(media.getDuration());

            

Reported by PMD.

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

Line: 23

                      out.writeInt(media.getBitrate());
        out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');
        out.writeString(media.getCopyright(), ',');
        out.writeLong(media.getDuration());
        out.write(',');

            

Reported by PMD.

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

Line: 24

                      out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');
        out.writeString(media.getCopyright(), ',');
        out.writeLong(media.getDuration());
        out.write(',');
        out.writeString(media.getFormat(), ',');

            

Reported by PMD.

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

Line: 24

                      out.write(',');
        out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');
        out.writeString(media.getCopyright(), ',');
        out.writeLong(media.getDuration());
        out.write(',');
        out.writeString(media.getFormat(), ',');

            

Reported by PMD.

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

Line: 25

                      out.writeInt(media.getHeight());
        out.write(',');
        out.writeInt(media.getWidth());
        out.write(',');
        out.writeString(media.getCopyright(), ',');
        out.writeLong(media.getDuration());
        out.write(',');
        out.writeString(media.getFormat(), ',');
        out.write('[');

            

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/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.