The following issues were found

src/test/java/com/alibaba/fastjson/validate/JSONValidateTest_file.java
26 issues
Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 20

                          long start = System.currentTimeMillis();

            File file = new File("/Users/wenshao/Downloads/000002_0.json");
            FileInputStream is = new FileInputStream(file);
            JSONValidator validator = JSONValidator.fromUtf8(is);
            assertTrue(validator.validate());
            validator.close();

            // 642 335 796

            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 54

                          long start = System.currentTimeMillis();

            File file = new File("/Users/wenshao/Downloads/000002_0.json");
            Reader is = new InputStreamReader(new FileInputStream(file), "UTF8");
            JSONValidator validator = JSONValidator.from(is);
            assertTrue(validator.validate());
            validator.close();

            // 642 335 796

            

Reported by PMD.

System.out.println is used
Design

Line: 26

                          validator.close();

            // 642 335 796
            System.out.println("millis " + (System.currentTimeMillis() - start));
        }
    }

    public void test_for_file2() throws Exception {
        File file = new File("/Users/wenshao/Downloads/000002_0.json");

            

Reported by PMD.

System.out.println is used
Design

Line: 44

                          validator.close();

            // 642 335 796
            System.out.println("millis " + (System.currentTimeMillis() - start));
        }
    }


    public void test_for_fileReader() throws Exception {

            

Reported by PMD.

System.out.println is used
Design

Line: 60

                          validator.close();

            // 642 335 796
            System.out.println("millis " + (System.currentTimeMillis() - start));
        }
    }
}

            

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 JSONValidateTest_file extends TestCase
{
    public void test_for_file() throws Exception {
        for (int i = 0; i < 10; ++i) {
            long start = System.currentTimeMillis();

            File file = new File("/Users/wenshao/Downloads/000002_0.json");
            FileInputStream is = new FileInputStream(file);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 19

                      for (int i = 0; i < 10; ++i) {
            long start = System.currentTimeMillis();

            File file = new File("/Users/wenshao/Downloads/000002_0.json");
            FileInputStream is = new FileInputStream(file);
            JSONValidator validator = JSONValidator.fromUtf8(is);
            assertTrue(validator.validate());
            validator.close();


            

Reported by PMD.

Ensure that resources like this FileInputStream object are closed after use
Error

Line: 20

                          long start = System.currentTimeMillis();

            File file = new File("/Users/wenshao/Downloads/000002_0.json");
            FileInputStream is = new FileInputStream(file);
            JSONValidator validator = JSONValidator.fromUtf8(is);
            assertTrue(validator.validate());
            validator.close();

            // 642 335 796

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 20

                          long start = System.currentTimeMillis();

            File file = new File("/Users/wenshao/Downloads/000002_0.json");
            FileInputStream is = new FileInputStream(file);
            JSONValidator validator = JSONValidator.fromUtf8(is);
            assertTrue(validator.validate());
            validator.close();

            // 642 335 796

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                          File file = new File("/Users/wenshao/Downloads/000002_0.json");
            FileInputStream is = new FileInputStream(file);
            JSONValidator validator = JSONValidator.fromUtf8(is);
            assertTrue(validator.validate());
            validator.close();

            // 642 335 796
            System.out.println("millis " + (System.currentTimeMillis() - start));
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/support/jaxrs/mock/testcase/FastJsonProviderTest.java
26 issues
System.out.println is used
Design

Line: 77

              		
		Response response = client.path("/fastjson/test1").accept("application/json").type("application/json; charset=UTF-8").post(json.toJSONString());
		
		System.out.println(response.readEntity(String.class));
	}
	
	@Test
	public void test1() throws Exception {
		

            

Reported by PMD.

System.out.println is used
Design

Line: 93

              		
		Response response = client.path("/fastjson/test1").replaceQuery("pretty").accept("application/json").type("application/json; charset=UTF-8").post(json.toJSONString());
		
		System.out.println(response.readEntity(String.class));
	}
	
	@Test
	public void test2() throws Exception {
		

            

Reported by PMD.

System.out.println is used
Design

Line: 105

              		
		Response response = client.path("/fastjson/test2").accept("application/json").type("application/json; charset=UTF-8").post(jsonStr);
		
		System.out.println(response.readEntity(String.class));
	}
}

            

Reported by PMD.

This final field could be made static
Design

Line: 40

              @ContextConfiguration(classes = Application.class)
public class FastJsonProviderTest {

	public final String REST_SERVICE_URL = "http://localhost:8088/rest";

	static {

		Server server = new Server(8088);


            

Reported by PMD.

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

Line: 40

              @ContextConfiguration(classes = Application.class)
public class FastJsonProviderTest {

	public final String REST_SERVICE_URL = "http://localhost:8088/rest";

	static {

		Server server = new Server(8088);


            

Reported by PMD.

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

Line: 59

              		try {
			server.start();
//			server.join();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test

            

Reported by PMD.

Avoid printStackTrace(); use a logger call instead.
Design

Line: 60

              			server.start();
//			server.join();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void test0() throws Exception {

            

Reported by PMD.

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

Line: 65

              	}
	
	@Test
	public void test0() throws Exception {
		
		JSONObject json = new JSONObject();
		
		json.put("id", 123);
		

            

Reported by PMD.

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

Line: 75

              		
		WebClient client = WebClient.create(REST_SERVICE_URL);
		
		Response response = client.path("/fastjson/test1").accept("application/json").type("application/json; charset=UTF-8").post(json.toJSONString());
		
		System.out.println(response.readEntity(String.class));
	}
	
	@Test

            

Reported by PMD.

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

Line: 75

              		
		WebClient client = WebClient.create(REST_SERVICE_URL);
		
		Response response = client.path("/fastjson/test1").accept("application/json").type("application/json; charset=UTF-8").post(json.toJSONString());
		
		System.out.println(response.readEntity(String.class));
	}
	
	@Test

            

Reported by PMD.

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

    public void test_for_wangran() throws Exception {
        String resource = "json/yannywang.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(is);

        VirtualTopic topic = JSON.parseObject(text, VirtualTopic.class);

            

Reported by PMD.

Ensure that resources like this InputStream object are closed after use
Error

Line: 19

              
    public void test_for_wangran() throws Exception {
        String resource = "json/yannywang.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(is);

        VirtualTopic topic = JSON.parseObject(text, VirtualTopic.class);

        {

            

Reported by PMD.

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

Line: 19

              
    public void test_for_wangran() throws Exception {
        String resource = "json/yannywang.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(is);

        VirtualTopic topic = JSON.parseObject(text, VirtualTopic.class);

        {

            

Reported by PMD.

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

Line: 19

              
    public void test_for_wangran() throws Exception {
        String resource = "json/yannywang.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(is);

        VirtualTopic topic = JSON.parseObject(text, VirtualTopic.class);

        {

            

Reported by PMD.

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

Line: 25

                      VirtualTopic topic = JSON.parseObject(text, VirtualTopic.class);

        {
            QueueEntity qe = topic.getQueueMap().get(12109);

            Assert.assertNotNull(qe);
            Assert.assertNotNull(qe.getPhysicalQueueMap());
            Assert.assertEquals(1, qe.getPhysicalQueueMap().size());


            

Reported by PMD.

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

Line: 28

                          QueueEntity qe = topic.getQueueMap().get(12109);

            Assert.assertNotNull(qe);
            Assert.assertNotNull(qe.getPhysicalQueueMap());
            Assert.assertEquals(1, qe.getPhysicalQueueMap().size());

            for (PhysicalQueue q : qe.getPhysicalQueueMap().values()) {
                q.getInRate();
                Assert.assertEquals(qe, q.getQueue());

            

Reported by PMD.

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

Line: 29

              
            Assert.assertNotNull(qe);
            Assert.assertNotNull(qe.getPhysicalQueueMap());
            Assert.assertEquals(1, qe.getPhysicalQueueMap().size());

            for (PhysicalQueue q : qe.getPhysicalQueueMap().values()) {
                q.getInRate();
                Assert.assertEquals(qe, q.getQueue());
            }

            

Reported by PMD.

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

Line: 29

              
            Assert.assertNotNull(qe);
            Assert.assertNotNull(qe.getPhysicalQueueMap());
            Assert.assertEquals(1, qe.getPhysicalQueueMap().size());

            for (PhysicalQueue q : qe.getPhysicalQueueMap().values()) {
                q.getInRate();
                Assert.assertEquals(qe, q.getQueue());
            }

            

Reported by PMD.

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

Line: 31

                          Assert.assertNotNull(qe.getPhysicalQueueMap());
            Assert.assertEquals(1, qe.getPhysicalQueueMap().size());

            for (PhysicalQueue q : qe.getPhysicalQueueMap().values()) {
                q.getInRate();
                Assert.assertEquals(qe, q.getQueue());
            }

            Assert.assertEquals(qe.getPhysicalQueueMap(), qe.getPqMap());

            

Reported by PMD.

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

Line: 31

                          Assert.assertNotNull(qe.getPhysicalQueueMap());
            Assert.assertEquals(1, qe.getPhysicalQueueMap().size());

            for (PhysicalQueue q : qe.getPhysicalQueueMap().values()) {
                q.getInRate();
                Assert.assertEquals(qe, q.getQueue());
            }

            Assert.assertEquals(qe.getPhysicalQueueMap(), qe.getPqMap());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/list/ListStringFieldTest_dom_hashSet.java
26 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

              
public class ListStringFieldTest_dom_hashSet extends TestCase {

    public void test_list() throws Exception {
        String text = "{\"values\":[\"a\",null,\"b\",\"ab\\\\c\"]}";

        Model model = JSON.parseObject(text, Model.class);

        Assert.assertEquals(4, model.values.size());

            

Reported by PMD.

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

Line: 24

              
        Model model = JSON.parseObject(text, Model.class);

        Assert.assertEquals(4, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains(null));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }

            

Reported by PMD.

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

Line: 25

                      Model model = JSON.parseObject(text, Model.class);

        Assert.assertEquals(4, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains(null));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }


            

Reported by PMD.

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

Line: 26

              
        Assert.assertEquals(4, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains(null));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }

    public void test_null() throws Exception {

            

Reported by PMD.

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

Line: 27

                      Assert.assertEquals(4, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains(null));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }

    public void test_null() throws Exception {
        String text = "{\"values\":null}";

            

Reported by PMD.

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

Line: 28

                      Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains(null));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }

    public void test_null() throws Exception {
        String text = "{\"values\":null}";
        Model model = JSON.parseObject(text, Model.class);

            

Reported by PMD.

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

Line: 31

                      Assert.assertTrue(model.values.contains("ab\\c"));
    }

    public void test_null() throws Exception {
        String text = "{\"values\":null}";
        Model model = JSON.parseObject(text, Model.class);
        Assert.assertNull(model.values);
    }


            

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

                      Assert.assertNull(model.values);
    }

    public void test_empty() throws Exception {
        String text = "{\"values\":[]}";
        Model model = JSON.parseObject(text, Model.class);
        Assert.assertEquals(0, model.values.size());
    }


            

Reported by PMD.

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

Line: 40

                  public void test_empty() throws Exception {
        String text = "{\"values\":[]}";
        Model model = JSON.parseObject(text, Model.class);
        Assert.assertEquals(0, model.values.size());
    }

    public void test_map_empty() throws Exception {
        String text = "{\"model\":{\"values\":[]}}";
        Map<String, Model> map = JSON.parseObject(text, new TypeReference<Map<String, Model>>() {

            

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

                      Assert.assertEquals(0, model.values.size());
    }

    public void test_map_empty() throws Exception {
        String text = "{\"model\":{\"values\":[]}}";
        Map<String, Model> map = JSON.parseObject(text, new TypeReference<Map<String, Model>>() {
        });
        Model model = (Model) map.get("model");
        Assert.assertEquals(0, model.values.size());

            

Reported by PMD.

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

    public void test_list() throws Exception {
        String text = "{\"values\":[\"a\",\"b\",\"ab\\\\c\"]}";

        Model model = JSON.parseObject(text, Model.class);

        Assert.assertEquals(3, model.values.size());

            

Reported by PMD.

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

Line: 21

              
        Model model = JSON.parseObject(text, Model.class);

        Assert.assertEquals(3, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }


            

Reported by PMD.

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

Line: 22

                      Model model = JSON.parseObject(text, Model.class);

        Assert.assertEquals(3, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }

    public void test_null() throws Exception {

            

Reported by PMD.

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

Line: 23

              
        Assert.assertEquals(3, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }

    public void test_null() throws Exception {
        String text = "{\"values\":null}";

            

Reported by PMD.

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

Line: 24

                      Assert.assertEquals(3, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
        Assert.assertTrue(model.values.contains("ab\\c"));
    }

    public void test_null() throws Exception {
        String text = "{\"values\":null}";
        Model model = JSON.parseObject(text, Model.class);

            

Reported by PMD.

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

Line: 27

                      Assert.assertTrue(model.values.contains("ab\\c"));
    }

    public void test_null() throws Exception {
        String text = "{\"values\":null}";
        Model model = JSON.parseObject(text, Model.class);
        Assert.assertNull(model.values);
    }


            

Reported by PMD.

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

Line: 33

                      Assert.assertNull(model.values);
    }

    public void test_empty() throws Exception {
        String text = "{\"values\":[]}";
        Model model = JSON.parseObject(text, Model.class);
        Assert.assertEquals(0, model.values.size());
    }


            

Reported by PMD.

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

Line: 36

                  public void test_empty() throws Exception {
        String text = "{\"values\":[]}";
        Model model = JSON.parseObject(text, Model.class);
        Assert.assertEquals(0, model.values.size());
    }

    public void test_map_empty() throws Exception {
        String text = "{\"model\":{\"values\":[]}}";
        Map<String, Model> map = JSON.parseObject(text, new TypeReference<Map<String, Model>>() {

            

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

                      Assert.assertEquals(0, model.values.size());
    }

    public void test_map_empty() throws Exception {
        String text = "{\"model\":{\"values\":[]}}";
        Map<String, Model> map = JSON.parseObject(text, new TypeReference<Map<String, Model>>() {
        });
        Model model = (Model) map.get("model");
        Assert.assertEquals(0, model.values.size());

            

Reported by PMD.

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

Line: 44

                      Map<String, Model> map = JSON.parseObject(text, new TypeReference<Map<String, Model>>() {
        });
        Model model = (Model) map.get("model");
        Assert.assertEquals(0, model.values.size());
    }

    public void test_notMatch() throws Exception {
        String text = "{\"value\":[]}";
        Model model = JSON.parseObject(text, Model.class);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1500/Issue1584.java
26 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 16

              import java.util.Map;

public class Issue1584 extends TestCase {
    public void test_for_issue() throws Exception {
        ParserConfig config = new ParserConfig();

        String json = "{\"k\":1,\"v\":\"A\"}";

        {

            

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

              import java.util.Map;

public class Issue1584 extends TestCase {
    public void test_for_issue() throws Exception {
        ParserConfig config = new ParserConfig();

        String json = "{\"k\":1,\"v\":\"A\"}";

        {

            

Reported by PMD.

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

Line: 23

              
        {
            Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
            Object key = entry.getKey();
            Object value = entry.getValue();
            assertTrue(key.equals("v") || key.equals("k"));
            if (key.equals("v")) {
                assertEquals("A", value);
            } else {

            

Reported by PMD.

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

Line: 24

                      {
            Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
            Object key = entry.getKey();
            Object value = entry.getValue();
            assertTrue(key.equals("v") || key.equals("k"));
            if (key.equals("v")) {
                assertEquals("A", value);
            } else {
                assertEquals(1, value);

            

Reported by PMD.

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

Line: 25

                          Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
            Object key = entry.getKey();
            Object value = entry.getValue();
            assertTrue(key.equals("v") || key.equals("k"));
            if (key.equals("v")) {
                assertEquals("A", value);
            } else {
                assertEquals(1, value);
            }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                          Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
            Object key = entry.getKey();
            Object value = entry.getValue();
            assertTrue(key.equals("v") || key.equals("k"));
            if (key.equals("v")) {
                assertEquals("A", value);
            } else {
                assertEquals(1, value);
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 25

                          Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
            Object key = entry.getKey();
            Object value = entry.getValue();
            assertTrue(key.equals("v") || key.equals("k"));
            if (key.equals("v")) {
                assertEquals("A", value);
            } else {
                assertEquals(1, value);
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 25

                          Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
            Object key = entry.getKey();
            Object value = entry.getValue();
            assertTrue(key.equals("v") || key.equals("k"));
            if (key.equals("v")) {
                assertEquals("A", value);
            } else {
                assertEquals(1, value);
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 25

                          Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
            Object key = entry.getKey();
            Object value = entry.getValue();
            assertTrue(key.equals("v") || key.equals("k"));
            if (key.equals("v")) {
                assertEquals("A", value);
            } else {
                assertEquals(1, value);
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 25

                          Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
            Object key = entry.getKey();
            Object value = entry.getValue();
            assertTrue(key.equals("v") || key.equals("k"));
            if (key.equals("v")) {
                assertEquals("A", value);
            } else {
                assertEquals(1, value);
            }

            

Reported by PMD.

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

    public void test_deserializeUsing() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

            

Reported by PMD.

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

Line: 18

               */
public class DeserializeUsingTest extends TestCase {

    public void test_deserializeUsing() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                  public void test_deserializeUsing() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

    public void test_deserializeUsing2() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";

            

Reported by PMD.

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

Line: 21

                  public void test_deserializeUsing() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

    public void test_deserializeUsing2() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";

            

Reported by PMD.

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

Line: 21

                  public void test_deserializeUsing() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

    public void test_deserializeUsing2() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";

            

Reported by PMD.

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

Line: 21

                  public void test_deserializeUsing() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

    public void test_deserializeUsing2() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";

            

Reported by PMD.

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

Line: 21

                  public void test_deserializeUsing() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

    public void test_deserializeUsing2() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";

            

Reported by PMD.

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

Line: 22

                      String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

    public void test_deserializeUsing2() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

    public void test_deserializeUsing2() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";


            

Reported by PMD.

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

Line: 22

                      String jsonStr = "{'subjectList':['CHINESE','MATH']}";
        Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
        assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
        assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
    }

    public void test_deserializeUsing2() throws Exception {
        String jsonStr = "{'subjectList':['CHINESE','MATH']}";


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/autoType/AutoTypeTest3_deny.java
26 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: 8

              import junit.framework.TestCase;

public class AutoTypeTest3_deny extends TestCase {
    public void test_for_x() throws Exception {
        Exception error = null;
        try {
            String json = "{\"@type\":\"java.util.logging.FileHandler\",\"pattern\":\"xxx.txt\"}";
            Object obj = JSON.parse(json, Feature.SupportAutoType);
        } catch (Exception ex) {

            

Reported by PMD.

Avoid unused local variables such as 'obj'.
Design

Line: 12

                      Exception error = null;
        try {
            String json = "{\"@type\":\"java.util.logging.FileHandler\",\"pattern\":\"xxx.txt\"}";
            Object obj = JSON.parse(json, Feature.SupportAutoType);
        } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }

            

Reported by PMD.

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

Line: 13

                      try {
            String json = "{\"@type\":\"java.util.logging.FileHandler\",\"pattern\":\"xxx.txt\"}";
            Object obj = JSON.parse(json, Feature.SupportAutoType);
        } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }

    public void test_for_jar() throws Exception {
        Exception error = null;
        try {

            

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

                      assertNotNull(error);
    }

    public void test_for_jar() throws Exception {
        Exception error = null;
        try {
            String json = "{\"@type\":\"java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}";
            Object obj = JSON.parse(json, Feature.SupportAutoType);
        } catch (Exception ex) {

            

Reported by PMD.

Avoid unused local variables such as 'obj'.
Design

Line: 23

                      Exception error = null;
        try {
            String json = "{\"@type\":\"java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}";
            Object obj = JSON.parse(json, Feature.SupportAutoType);
        } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }

            

Reported by PMD.

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

Line: 24

                      try {
            String json = "{\"@type\":\"java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}";
            Object obj = JSON.parse(json, Feature.SupportAutoType);
        } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

                      } catch (Exception ex) {
            error = ex;
        }
        assertNotNull(error);
    }

    public void test_for_array() throws Exception {
        Exception error = null;
        try {

            

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

                      assertNotNull(error);
    }

    public void test_for_array() throws Exception {
        Exception error = null;
        try {
            String json = "{\"@type\":\"[java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}";
            Object obj = JSON.parse(json, Feature.SupportAutoType);
        } catch (Exception ex) {

            

Reported by PMD.

Avoid unused local variables such as 'obj'.
Design

Line: 34

                      Exception error = null;
        try {
            String json = "{\"@type\":\"[java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}";
            Object obj = JSON.parse(json, Feature.SupportAutoType);
        } catch (Exception ex) {
            ex.printStackTrace();
            error = ex;
        }
        assertNotNull(error);

            

Reported by PMD.

src/test/java/com/alibaba/json/test/Bug_0_Test.java
26 issues
System.out.println is used
Design

Line: 56

                          com.alibaba.fastjson.JSON.parse(text);
        }
        long nano = System.nanoTime() - startNano;
        System.out.println(NumberFormat.getInstance().format(nano));
    }

    private void f_jackson() throws Exception {
        long startNano = System.nanoTime();
        for (int i = 0; i < COUNT; ++i) {

            

Reported by PMD.

System.out.println is used
Design

Line: 68

                          JsonNode body = node.get(1);
        }
        long nano = System.nanoTime() - startNano;
        System.out.println(NumberFormat.getInstance().format(nano));
    }

}

            

Reported by PMD.

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

Line: 31

              
public class Bug_0_Test extends TestCase {

    private String text;
    private int    COUNT = 1000;

    protected void setUp() throws Exception {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
        text = IOUtils.toString(is);

            

Reported by PMD.

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

Line: 32

              public class Bug_0_Test extends TestCase {

    private String text;
    private int    COUNT = 1000;

    protected void setUp() throws Exception {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
        text = IOUtils.toString(is);
        is.close();

            

Reported by PMD.

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

Line: 32

              public class Bug_0_Test extends TestCase {

    private String text;
    private int    COUNT = 1000;

    protected void setUp() throws Exception {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
        text = IOUtils.toString(is);
        is.close();

            

Reported by PMD.

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

Line: 34

                  private String text;
    private int    COUNT = 1000;

    protected void setUp() throws Exception {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
        text = IOUtils.toString(is);
        is.close();

        // text =

            

Reported by PMD.

Ensure that resources like this InputStream object are closed after use
Error

Line: 35

                  private int    COUNT = 1000;

    protected void setUp() throws Exception {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
        text = IOUtils.toString(is);
        is.close();

        // text =
        // "[{\"S\":321061,\"T\":\"GetAttributeResp\"},{\"ERROR\":null,\"TS\":0,\"VAL\":{\"SqlList\":[{\"BatchSizeMax\":0,\"BatchSizeTotal\":0,\"ConcurrentMax\":1,\"DataSource\":\"jdbc:wrap-jdbc:filters=default,encoding:name=ds-offer:jdbc:mysql://172.29.61.63:8066/amoeba\",\"EffectedRowCount\":0,\"ErrorCount\":0,\"ExecuteCount\":5,\"FetchRowCount\":5,\"File\":null,\"ID\":2001,\"LastError\":null,\"LastTime\":1292742908178,\"MaxTimespan\":16,\"MaxTimespanOccurTime\":1292742668191,\"Name\":null,\"RunningCount\":0,\"SQL\":\"SELECT @@SQL_MODE\",\"TotalTime\":83}]}}]";

            

Reported by PMD.

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

Line: 35

                  private int    COUNT = 1000;

    protected void setUp() throws Exception {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
        text = IOUtils.toString(is);
        is.close();

        // text =
        // "[{\"S\":321061,\"T\":\"GetAttributeResp\"},{\"ERROR\":null,\"TS\":0,\"VAL\":{\"SqlList\":[{\"BatchSizeMax\":0,\"BatchSizeTotal\":0,\"ConcurrentMax\":1,\"DataSource\":\"jdbc:wrap-jdbc:filters=default,encoding:name=ds-offer:jdbc:mysql://172.29.61.63:8066/amoeba\",\"EffectedRowCount\":0,\"ErrorCount\":0,\"ExecuteCount\":5,\"FetchRowCount\":5,\"File\":null,\"ID\":2001,\"LastError\":null,\"LastTime\":1292742908178,\"MaxTimespan\":16,\"MaxTimespanOccurTime\":1292742668191,\"Name\":null,\"RunningCount\":0,\"SQL\":\"SELECT @@SQL_MODE\",\"TotalTime\":83}]}}]";

            

Reported by PMD.

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

Line: 35

                  private int    COUNT = 1000;

    protected void setUp() throws Exception {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
        text = IOUtils.toString(is);
        is.close();

        // text =
        // "[{\"S\":321061,\"T\":\"GetAttributeResp\"},{\"ERROR\":null,\"TS\":0,\"VAL\":{\"SqlList\":[{\"BatchSizeMax\":0,\"BatchSizeTotal\":0,\"ConcurrentMax\":1,\"DataSource\":\"jdbc:wrap-jdbc:filters=default,encoding:name=ds-offer:jdbc:mysql://172.29.61.63:8066/amoeba\",\"EffectedRowCount\":0,\"ErrorCount\":0,\"ExecuteCount\":5,\"FetchRowCount\":5,\"File\":null,\"ID\":2001,\"LastError\":null,\"LastTime\":1292742908178,\"MaxTimespan\":16,\"MaxTimespanOccurTime\":1292742668191,\"Name\":null,\"RunningCount\":0,\"SQL\":\"SELECT @@SQL_MODE\",\"TotalTime\":83}]}}]";

            

Reported by PMD.

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

Line: 37

                  protected void setUp() throws Exception {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
        text = IOUtils.toString(is);
        is.close();

        // text =
        // "[{\"S\":321061,\"T\":\"GetAttributeResp\"},{\"ERROR\":null,\"TS\":0,\"VAL\":{\"SqlList\":[{\"BatchSizeMax\":0,\"BatchSizeTotal\":0,\"ConcurrentMax\":1,\"DataSource\":\"jdbc:wrap-jdbc:filters=default,encoding:name=ds-offer:jdbc:mysql://172.29.61.63:8066/amoeba\",\"EffectedRowCount\":0,\"ErrorCount\":0,\"ExecuteCount\":5,\"FetchRowCount\":5,\"File\":null,\"ID\":2001,\"LastError\":null,\"LastTime\":1292742908178,\"MaxTimespan\":16,\"MaxTimespanOccurTime\":1292742668191,\"Name\":null,\"RunningCount\":0,\"SQL\":\"SELECT @@SQL_MODE\",\"TotalTime\":83}]}}]";
    }


            

Reported by PMD.

src/test/java/cn/com/tx/domain/pagination/Pagination.java
26 issues
The class 'Pagination' has a Standard Cyclomatic Complexity of 2 (Highest = 10).
Design

Line: 7

              import java.util.ArrayList;
import java.util.List;

public class Pagination<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5038839734218582220L;

            

Reported by PMD.

The class 'Pagination' has a Modified Cyclomatic Complexity of 2 (Highest = 10).
Design

Line: 7

              import java.util.ArrayList;
import java.util.List;

public class Pagination<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5038839734218582220L;

            

Reported by PMD.

The class 'Pagination' is suspected to be a Data Class (WOC=15.789%, NOPA=0, NOAM=14, WMC=32)
Design

Line: 7

              import java.util.ArrayList;
import java.util.List;

public class Pagination<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5038839734218582220L;

            

Reported by PMD.

Avoid using redundant field initializer for 'totalResult'
Performance

Line: 14

              	 */
	private static final long serialVersionUID = 5038839734218582220L;

	private int totalResult = 0;

	private int totalPage = 1;

	private int pageIndex = 1;


            

Reported by PMD.

Avoid using redundant field initializer for 'fromIndex'
Performance

Line: 22

              
	private int maxLength = 5;

	private int fromIndex = 0;

	private int toIndex = 0;

	private List<T> list = new ArrayList<T>();
	

            

Reported by PMD.

Avoid using redundant field initializer for 'toIndex'
Performance

Line: 24

              
	private int fromIndex = 0;

	private int toIndex = 0;

	private List<T> list = new ArrayList<T>();
	
	public Pagination(){
		

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 87

              	}

	public int getPrevPage() {
		if (this.pageIndex > 1) {
			return this.pageIndex - 1;
		}
		return this.pageIndex;
	}


            

Reported by PMD.

The constructor 'Pagination(int, int, int)' has a cyclomatic complexity of 10.
Design

Line: 134

              	 * @param pageIndex
	 * @param maxLength
	 */
	public Pagination(int totalResult, int pageIndex, int maxLength) {
		if (maxLength > 0) {
			this.maxLength = maxLength;
		}
		if (totalResult > 0) {
			this.totalResult = totalResult;

            

Reported by PMD.

The constructor 'Pagination' has a Standard Cyclomatic Complexity of 10.
Design

Line: 134

              	 * @param pageIndex
	 * @param maxLength
	 */
	public Pagination(int totalResult, int pageIndex, int maxLength) {
		if (maxLength > 0) {
			this.maxLength = maxLength;
		}
		if (totalResult > 0) {
			this.totalResult = totalResult;

            

Reported by PMD.

The constructor 'Pagination' has a Modified Cyclomatic Complexity of 10.
Design

Line: 134

              	 * @param pageIndex
	 * @param maxLength
	 */
	public Pagination(int totalResult, int pageIndex, int maxLength) {
		if (maxLength > 0) {
			this.maxLength = maxLength;
		}
		if (totalResult > 0) {
			this.totalResult = totalResult;

            

Reported by PMD.