The following issues were found

src/test/java/com/alibaba/json/bvt/bug/Issue1005.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: 12

               * Created by wenshao on 18/01/2017.
 */
public class Issue1005 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.

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

Line: 12

               * Created by wenshao on 18/01/2017.
 */
public class Issue1005 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.

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

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

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/parser/TypeUtilsTest_castToBigDecimal.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: 15

              	/**
	 * NaN和正负无穷大的时候转BigDecimal都会报转换异常,修改为返回null
	 */
	public void test_FloatNanInfinite() throws Exception {
		// 正无穷大
		assertNull(TypeUtils.castToBigDecimal(1.0f / 0.0f));
		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0f / 0.0f));
		// NaN

            

Reported by PMD.

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

Line: 15

              	/**
	 * NaN和正负无穷大的时候转BigDecimal都会报转换异常,修改为返回null
	 */
	public void test_FloatNanInfinite() throws Exception {
		// 正无穷大
		assertNull(TypeUtils.castToBigDecimal(1.0f / 0.0f));
		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0f / 0.0f));
		// NaN

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              	 */
	public void test_FloatNanInfinite() throws Exception {
		// 正无穷大
		assertNull(TypeUtils.castToBigDecimal(1.0f / 0.0f));
		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0f / 0.0f));
		// NaN
		assertNull(TypeUtils.castToBigDecimal(0.0f / 0.0f));
	}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

              		// 正无穷大
		assertNull(TypeUtils.castToBigDecimal(1.0f / 0.0f));
		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0f / 0.0f));
		// NaN
		assertNull(TypeUtils.castToBigDecimal(0.0f / 0.0f));
	}
	
	/**

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

              		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0f / 0.0f));
		// NaN
		assertNull(TypeUtils.castToBigDecimal(0.0f / 0.0f));
	}
	
	/**
	 * NaN和正负无穷大的时候转BigDecimal都会报转换异常,修改为返回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: 27

              	/**
	 * NaN和正负无穷大的时候转BigDecimal都会报转换异常,修改为返回null
	 */
	public void test_DoubleNanInfinite() throws Exception {
		// 正无穷大
		assertNull(TypeUtils.castToBigDecimal(1.0d / 0.0d));
		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0d / 0.0d));
		// NaN

            

Reported by PMD.

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

Line: 27

              	/**
	 * NaN和正负无穷大的时候转BigDecimal都会报转换异常,修改为返回null
	 */
	public void test_DoubleNanInfinite() throws Exception {
		// 正无穷大
		assertNull(TypeUtils.castToBigDecimal(1.0d / 0.0d));
		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0d / 0.0d));
		// NaN

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

              	 */
	public void test_DoubleNanInfinite() throws Exception {
		// 正无穷大
		assertNull(TypeUtils.castToBigDecimal(1.0d / 0.0d));
		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0d / 0.0d));
		// NaN
		assertNull(TypeUtils.castToBigDecimal(0.0d / 0.0d));
	}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 31

              		// 正无穷大
		assertNull(TypeUtils.castToBigDecimal(1.0d / 0.0d));
		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0d / 0.0d));
		// NaN
		assertNull(TypeUtils.castToBigDecimal(0.0d / 0.0d));
	}

	/**

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

              		// 负无穷大
		assertNull(TypeUtils.castToBigDecimal(-1.0d / 0.0d));
		// NaN
		assertNull(TypeUtils.castToBigDecimal(0.0d / 0.0d));
	}

	/**
	 * NaN和正负无穷大的时候转BigDecimal都会报转换异常,修改为返回null
	 */

            

Reported by PMD.

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

Line: 13

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

public class StringSerializerTest extends TestCase {

	public void test_0() throws Exception {
		Assert.assertEquals("{\"value\":null}", JSON.toJSONString(
				new TestEntity(null), SerializerFeature.WriteMapNullValue));


            

Reported by PMD.

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

Line: 15

              
public class StringSerializerTest extends TestCase {

	public void test_0() throws Exception {
		Assert.assertEquals("{\"value\":null}", JSON.toJSONString(
				new TestEntity(null), SerializerFeature.WriteMapNullValue));

		SerializeWriter out = new SerializeWriter();


            

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.assertEquals("\"123\"\"456\"", out.toString());
	}

	public void test_2() throws Exception {
		StringWriter out = new StringWriter();

		JSONSerializer.write(out, new TestEntity(null));
		Assert.assertEquals("{}", out.toString());
	}

            

Reported by PMD.

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

Line: 35

              		Assert.assertEquals("{}", out.toString());
	}

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

		JSONSerializer.write(out, new TestEntity(null));
		Assert.assertEquals("{}", out.toString());
	}

            

Reported by PMD.

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

Line: 42

              		Assert.assertEquals("{}", out.toString());
	}

	public void test_3() throws Exception {
		SerializeWriter out = new SerializeWriter();
		JSONSerializer serializer = new JSONSerializer(out);
		serializer.config(SerializerFeature.UseSingleQuotes, true);

		serializer.write(new TestEntity("张三"));

            

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

              		Assert.assertEquals("{'value':'张三'}", out.toString());
	}

	public void test_4() throws Exception {
		StringWriter out = new StringWriter();

		JSONSerializer.write(out, new TestEntity("张三"));
		Assert.assertEquals("{\"value\":\"张三\"}", 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: 58

              		Assert.assertEquals("{\"value\":\"张三\"}", out.toString());
	}

	public void test_5() throws Exception {
		SerializeWriter out = new SerializeWriter();
		out.config(SerializerFeature.UseSingleQuotes, true);

		out.writeString((String) null);
		Assert.assertEquals("null", out.toString());

            

Reported by PMD.

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

Line: 63

              		out.config(SerializerFeature.UseSingleQuotes, true);

		out.writeString((String) null);
		Assert.assertEquals("null", out.toString());
	}

	public void test_5_d() throws Exception {
		SerializeWriter out = new SerializeWriter();
		out.config(SerializerFeature.UseSingleQuotes, true);

            

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

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

	public void test_5_d() throws Exception {
		SerializeWriter out = new SerializeWriter();
		out.config(SerializerFeature.UseSingleQuotes, true);

		out.writeString((String) null);
		Assert.assertEquals("null", out.toString());

            

Reported by PMD.

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

Line: 74

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

	public void test_6() throws Exception {
		SerializeWriter out = new SerializeWriter(1);
		out.config(SerializerFeature.UseSingleQuotes, true);

		out.writeString((String) null);
		Assert.assertEquals("null", out.toString());

            

Reported by PMD.

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

    public void test_list_like_extract() throws Exception {
        JSONPath path = new JSONPath("$[name rlike '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 rlike '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 rlike 'wenshao']");

            

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 rlike 'wenshao']");


            

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 rlike 'wenshao']");

        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(2, result.size());
        Assert.assertSame(entities.get(0), 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(2, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
        Assert.assertSame(entities.get(2), result.get(1));
    }
    
    public void test_list_like_left_match() throws Exception {

            

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

            

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


            

Reported by PMD.

src/test/java/com/alibaba/json/demo/Forguard.java
28 issues
Return an empty array rather than null.
Error

Line: 26

                      return new String(value_chars);
    }

    public static char[] get(char[] json, int json_len, char[] key, int key_len) {
        if (json_len == 0) {
            return new char[0];
        }

        Parser parser = new Parser();

            

Reported by PMD.

System.out.println is used
Design

Line: 14

                      String json = "{\"id\":\"a123\", \"name\":\"wxf\"}";

        String value = javaGet(json, "id");
        System.out.println(value);
    }

    public static String javaGet(String json, String key) {
        char[] json_chars = json.toCharArray();
        char[] key_chars = key.toCharArray();

            

Reported by PMD.

Avoid using a branching statement as the last in a loop.
Error

Line: 146

                              parser.token = Token.EOF;
                return;
            }
            break;
        }

        switch (parser.ch) {
            case '{':
                parser.token = Token.LBRACE;

            

Reported by PMD.

The class 'Forguard' has a Modified Cyclomatic Complexity of 5 (Highest = 13).
Design

Line: 8

              /**
 * Created by wenshao on 10/03/2017.
 */
public class Forguard extends TestCase {

    public void test_0() throws Exception {
        String json = "{\"id\":\"a123\", \"name\":\"wxf\"}";

        String value = javaGet(json, "id");

            

Reported by PMD.

The class 'Forguard' has a Standard Cyclomatic Complexity of 6 (Highest = 13).
Design

Line: 8

              /**
 * Created by wenshao on 10/03/2017.
 */
public class Forguard extends TestCase {

    public void test_0() throws Exception {
        String json = "{\"id\":\"a123\", \"name\":\"wxf\"}";

        String value = javaGet(json, "id");

            

Reported by PMD.

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

Line: 10

               */
public class Forguard extends TestCase {

    public void test_0() throws Exception {
        String json = "{\"id\":\"a123\", \"name\":\"wxf\"}";

        String value = javaGet(json, "id");
        System.out.println(value);
    }

            

Reported by PMD.

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

Line: 10

               */
public class Forguard extends TestCase {

    public void test_0() throws Exception {
        String json = "{\"id\":\"a123\", \"name\":\"wxf\"}";

        String value = javaGet(json, "id");
        System.out.println(value);
    }

            

Reported by PMD.

The method 'get(char, int, char, int)' has an NPath complexity of 900, current threshold is 200
Design

Line: 26

                      return new String(value_chars);
    }

    public static char[] get(char[] json, int json_len, char[] key, int key_len) {
        if (json_len == 0) {
            return new char[0];
        }

        Parser parser = new Parser();

            

Reported by PMD.

The method 'get' has a Standard Cyclomatic Complexity of 13.
Design

Line: 26

                      return new String(value_chars);
    }

    public static char[] get(char[] json, int json_len, char[] key, int key_len) {
        if (json_len == 0) {
            return new char[0];
        }

        Parser parser = new Parser();

            

Reported by PMD.

The method 'get' has a Modified Cyclomatic Complexity of 13.
Design

Line: 26

                      return new String(value_chars);
    }

    public static char[] get(char[] json, int json_len, char[] key, int key_len) {
        if (json_len == 0) {
            return new char[0];
        }

        Parser parser = new Parser();

            

Reported by PMD.

src/test/java/com/alibaba/fastjson/JSONPathTest.java
28 issues
No need to import a type that lives in the same package
Error

Line: 20

              
package com.alibaba.fastjson;

import com.alibaba.fastjson.JSONPath;
import com.diffblue.deeptestutils.Reflector;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

            

Reported by PMD.

The String literal 'java.lang.Object' appears 4 times in this file; the first occurrence is on line 54
Error

Line: 54

                  Object b = null;
    // Act
    Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath");
    Method m = c.getDeclaredMethod("eq", Reflector.forName("java.lang.Object"), Reflector.forName("java.lang.Object"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, a, b);
    // Assert result
    Assert.assertEquals(false, retval);
  }

            

Reported by PMD.

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

Line: 54

                  Object b = null;
    // Act
    Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath");
    Method m = c.getDeclaredMethod("eq", Reflector.forName("java.lang.Object"), Reflector.forName("java.lang.Object"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, a, b);
    // Assert result
    Assert.assertEquals(false, retval);
  }

            

Reported by PMD.

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

Line: 55

                  // Act
    Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath");
    Method m = c.getDeclaredMethod("eq", Reflector.forName("java.lang.Object"), Reflector.forName("java.lang.Object"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, a, b);
    // Assert result
    Assert.assertEquals(false, retval);
  }


            

Reported by PMD.

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

Line: 56

                  Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath");
    Method m = c.getDeclaredMethod("eq", Reflector.forName("java.lang.Object"), Reflector.forName("java.lang.Object"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, a, b);
    // Assert result
    Assert.assertEquals(false, retval);
  }

  /*

            

Reported by PMD.

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

Line: 73

                  Object b = null;
    // Act
    Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath");
    Method m = c.getDeclaredMethod("eq", Reflector.forName("java.lang.Object"), Reflector.forName("java.lang.Object"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, a, b);
    // Assert result
    Assert.assertEquals(true, retval);
  }

            

Reported by PMD.

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

Line: 74

                  // Act
    Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath");
    Method m = c.getDeclaredMethod("eq", Reflector.forName("java.lang.Object"), Reflector.forName("java.lang.Object"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, a, b);
    // Assert result
    Assert.assertEquals(true, retval);
  }


            

Reported by PMD.

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

Line: 75

                  Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath");
    Method m = c.getDeclaredMethod("eq", Reflector.forName("java.lang.Object"), Reflector.forName("java.lang.Object"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, a, b);
    // Assert result
    Assert.assertEquals(true, retval);
  }

  /*

            

Reported by PMD.

The String literal 'com.alibaba.fastjson.JSONPath$JSONPathParser' appears 7 times in this file; the first occurrence is on line 90
Error

Line: 90

                  // Arrange
    char ch = '2';
    // Act
    Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath$JSONPathParser");
    Method m = c.getDeclaredMethod("isDigitFirst", Reflector.forName("char"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, ch);
    // Assert result
    Assert.assertEquals(true, retval);

            

Reported by PMD.

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

Line: 91

                  char ch = '2';
    // Act
    Class<?> c = Reflector.forName("com.alibaba.fastjson.JSONPath$JSONPathParser");
    Method m = c.getDeclaredMethod("isDigitFirst", Reflector.forName("char"));
    m.setAccessible(true);
    boolean retval = (Boolean)m.invoke(null, ch);
    // Assert result
    Assert.assertEquals(true, retval);
  }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue124.java
28 issues
System.out.println is used
Design

Line: 38

                                  try {
                        if (r % 2 == 0) {
                            // System.out.println(mapper.writeValueAsString(info));
                            System.out.println(JSON.toJSONString(new SuccessReturn(info),
                                                                 SerializerFeature.WriteDateUseDateFormat));
                        } else {
                            // System.out.println(mapper.writeValueAsString(vo));
                            System.out.println(JSON.toJSONString(new SuccessReturn(vo),
                                                                 SerializerFeature.WriteDateUseDateFormat));

            

Reported by PMD.

System.out.println is used
Design

Line: 42

                                                                               SerializerFeature.WriteDateUseDateFormat));
                        } else {
                            // System.out.println(mapper.writeValueAsString(vo));
                            System.out.println(JSON.toJSONString(new SuccessReturn(vo),
                                                                 SerializerFeature.WriteDateUseDateFormat));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(0);

            

Reported by PMD.

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

Line: 14

              
public class Issue124 extends TestCase {

    public void test_for_issue() throws Exception {
        // final ObjectMapper mapper = new ObjectMapper();
        // mapper.setSerializationInclusion(Include.NON_NULL);
        final Random random = new Random();
        final int threadCount = 1000;
        final CountDownLatch latch = new CountDownLatch(threadCount);

            

Reported by PMD.

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

Line: 14

              
public class Issue124 extends TestCase {

    public void test_for_issue() throws Exception {
        // final ObjectMapper mapper = new ObjectMapper();
        // mapper.setSerializationInclusion(Include.NON_NULL);
        final Random random = new Random();
        final int threadCount = 1000;
        final CountDownLatch latch = new CountDownLatch(threadCount);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 28

              //                              SerializerFeature.WriteDateUseDateFormat);
//        }
        for (int i = 0; i < threadCount; i++) {
            new Thread() {

                @Override
                public void run() {
                    UserInfo info = new UserInfo();
                    CheckInfoVo vo = new CheckInfoVo(100);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 32

              
                @Override
                public void run() {
                    UserInfo info = new UserInfo();
                    CheckInfoVo vo = new CheckInfoVo(100);
                    int r = random.nextInt();
                    try {
                        if (r % 2 == 0) {
                            // System.out.println(mapper.writeValueAsString(info));

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 33

                              @Override
                public void run() {
                    UserInfo info = new UserInfo();
                    CheckInfoVo vo = new CheckInfoVo(100);
                    int r = random.nextInt();
                    try {
                        if (r % 2 == 0) {
                            // System.out.println(mapper.writeValueAsString(info));
                            System.out.println(JSON.toJSONString(new SuccessReturn(info),

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 38

                                  try {
                        if (r % 2 == 0) {
                            // System.out.println(mapper.writeValueAsString(info));
                            System.out.println(JSON.toJSONString(new SuccessReturn(info),
                                                                 SerializerFeature.WriteDateUseDateFormat));
                        } else {
                            // System.out.println(mapper.writeValueAsString(vo));
                            System.out.println(JSON.toJSONString(new SuccessReturn(vo),
                                                                 SerializerFeature.WriteDateUseDateFormat));

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 42

                                                                               SerializerFeature.WriteDateUseDateFormat));
                        } else {
                            // System.out.println(mapper.writeValueAsString(vo));
                            System.out.println(JSON.toJSONString(new SuccessReturn(vo),
                                                                 SerializerFeature.WriteDateUseDateFormat));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(0);

            

Reported by PMD.

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

Line: 45

                                          System.out.println(JSON.toJSONString(new SuccessReturn(vo),
                                                                 SerializerFeature.WriteDateUseDateFormat));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(0);
                    } finally {
                        latch.countDown();
                    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Bug_for_luogongwu.java
28 issues
System.out.println is used
Design

Line: 39

                      foo.thumbnails = imageList;

        String jsonString = JSON.toJSONString(foo);
        System.out.println(jsonString);

        Foo foo1 = JSON.parseObject(jsonString, Foo.class);

        assertEquals(1, foo1.thumbnails.size());
        assertNotNull(foo1.thumbnails.get(0));

            

Reported by PMD.

System.out.println is used
Design

Line: 54

                      fooNotAsm.thumbnails = imageList;

        jsonString = JSON.toJSONString(foo);
        System.out.println(jsonString);

        FooNotAsm fooNotAsm1 = JSON.parseObject(jsonString, FooNotAsm.class);

        assertEquals(1, fooNotAsm1.thumbnails.size());
        assertNotNull(fooNotAsm1.thumbnails.get(0));

            

Reported by PMD.

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

Line: 19

               */
public class Bug_for_luogongwu extends TestCase {

    public void test_for_issue() throws Exception {
        List<IflowItemImage> imageList = new ArrayList<IflowItemImage>();
        IflowItemImage image = new IflowItemImage();
        image.id = "72c7275c6b";
        imageList.add(image);


            

Reported by PMD.

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

Line: 19

               */
public class Bug_for_luogongwu extends TestCase {

    public void test_for_issue() throws Exception {
        List<IflowItemImage> imageList = new ArrayList<IflowItemImage>();
        IflowItemImage image = new IflowItemImage();
        image.id = "72c7275c6b";
        imageList.add(image);


            

Reported by PMD.

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

Line: 31

                      imageList.add(image);

        // force ASM
        boolean asm = SerializeConfig.globalInstance.isAsmEnable();
        SerializeConfig.globalInstance.setAsmEnable(true);

        // Test ASM
        Foo foo = new Foo();
        foo.thumbnails = imageList;

            

Reported by PMD.

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

Line: 32

              
        // force ASM
        boolean asm = SerializeConfig.globalInstance.isAsmEnable();
        SerializeConfig.globalInstance.setAsmEnable(true);

        // Test ASM
        Foo foo = new Foo();
        foo.thumbnails = imageList;


            

Reported by PMD.

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

Line: 43

              
        Foo foo1 = JSON.parseObject(jsonString, Foo.class);

        assertEquals(1, foo1.thumbnails.size());
        assertNotNull(foo1.thumbnails.get(0));
        assertSame(foo1.getThumbnail(), foo1.thumbnails.get(0));


        // test Not ASM

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 43

              
        Foo foo1 = JSON.parseObject(jsonString, Foo.class);

        assertEquals(1, foo1.thumbnails.size());
        assertNotNull(foo1.thumbnails.get(0));
        assertSame(foo1.getThumbnail(), foo1.thumbnails.get(0));


        // test Not ASM

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 44

                      Foo foo1 = JSON.parseObject(jsonString, Foo.class);

        assertEquals(1, foo1.thumbnails.size());
        assertNotNull(foo1.thumbnails.get(0));
        assertSame(foo1.getThumbnail(), foo1.thumbnails.get(0));


        // test Not ASM
        SerializeConfig.globalInstance.setAsmEnable(false);

            

Reported by PMD.

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

Line: 44

                      Foo foo1 = JSON.parseObject(jsonString, Foo.class);

        assertEquals(1, foo1.thumbnails.size());
        assertNotNull(foo1.thumbnails.get(0));
        assertSame(foo1.getThumbnail(), foo1.thumbnails.get(0));


        // test Not ASM
        SerializeConfig.globalInstance.setAsmEnable(false);

            

Reported by PMD.