The following issues were found

src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_scanFieldString.java
11 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: 10

              
public class JSONScannerTest_scanFieldString extends TestCase {

    public void test_0() throws Exception {
        String text = "{\"value\":1}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("1", obj.getValue());
    }


            

Reported by PMD.

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

Line: 13

                  public void test_0() throws Exception {
        String text = "{\"value\":1}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("1", obj.getValue());
    }

    public void test_1() throws Exception {
        String text = "{\"value\":\"1\"}";
        VO obj = JSON.parseObject(text, VO.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: 16

                      Assert.assertEquals("1", obj.getValue());
    }

    public void test_1() throws Exception {
        String text = "{\"value\":\"1\"}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("1", obj.getValue());
    }


            

Reported by PMD.

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

Line: 19

                  public void test_1() throws Exception {
        String text = "{\"value\":\"1\"}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("1", obj.getValue());
    }

    public void test_2() throws Exception {
        String text = "{\"value\":\"1\\t\"}";
        VO obj = JSON.parseObject(text, VO.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: 22

                      Assert.assertEquals("1", obj.getValue());
    }

    public void test_2() throws Exception {
        String text = "{\"value\":\"1\\t\"}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("1\t", obj.getValue());
    }


            

Reported by PMD.

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

Line: 25

                  public void test_2() throws Exception {
        String text = "{\"value\":\"1\\t\"}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("1\t", obj.getValue());
    }

    public void test_3() throws Exception {
        String text = "{\"value\":\"1\\n\"}";
        VO obj = JSON.parseObject(text, VO.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: 28

                      Assert.assertEquals("1\t", obj.getValue());
    }

    public void test_3() throws Exception {
        String text = "{\"value\":\"1\\n\"}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("1\n", obj.getValue());
    }


            

Reported by PMD.

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

Line: 31

                  public void test_3() throws Exception {
        String text = "{\"value\":\"1\\n\"}";
        VO obj = JSON.parseObject(text, VO.class);
        Assert.assertEquals("1\n", obj.getValue());
    }

    public void test_error_0() {
        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: 34

                      Assert.assertEquals("1\n", obj.getValue());
    }

    public void test_error_0() {
        Exception error = null;
        try {
            String text = "{\"value\":\"1\\n\"";
            JSON.parseObject(text, VO.class);
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 39

                      try {
            String text = "{\"value\":\"1\\n\"";
            JSON.parseObject(text, VO.class);
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/ref/RefTest7.java
11 issues
System.out.println is used
Design

Line: 21

                      VO[] root = new VO[] { vo };

        String text = JSON.toJSONString(root);
        System.out.println(text);

        VO[] array2 = JSON.parseObject(text, VO[].class);
        Assert.assertEquals(1, array2.length);
        Assert.assertNotNull(array2[0].getA());
        Assert.assertNotNull(array2[0].getB());

            

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

              
public class RefTest7 extends TestCase {

    public void test_bug_for_juqkai() throws Exception {

        VO vo = new VO();
        C c = new C();
        vo.setA(new A(c));
        vo.setB(new B(c));

            

Reported by PMD.

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

Line: 27

                      Assert.assertEquals(1, array2.length);
        Assert.assertNotNull(array2[0].getA());
        Assert.assertNotNull(array2[0].getB());
        Assert.assertNotNull(array2[0].getA().getC());
        Assert.assertNotNull(array2[0].getB().getC());
        Assert.assertSame(array2[0].getA().getC(), array2[0].getB().getC());
    }

    public static class VO {

            

Reported by PMD.

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

Line: 27

                      Assert.assertEquals(1, array2.length);
        Assert.assertNotNull(array2[0].getA());
        Assert.assertNotNull(array2[0].getB());
        Assert.assertNotNull(array2[0].getA().getC());
        Assert.assertNotNull(array2[0].getB().getC());
        Assert.assertSame(array2[0].getA().getC(), array2[0].getB().getC());
    }

    public static class VO {

            

Reported by PMD.

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

Line: 28

                      Assert.assertNotNull(array2[0].getA());
        Assert.assertNotNull(array2[0].getB());
        Assert.assertNotNull(array2[0].getA().getC());
        Assert.assertNotNull(array2[0].getB().getC());
        Assert.assertSame(array2[0].getA().getC(), array2[0].getB().getC());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 28

                      Assert.assertNotNull(array2[0].getA());
        Assert.assertNotNull(array2[0].getB());
        Assert.assertNotNull(array2[0].getA().getC());
        Assert.assertNotNull(array2[0].getB().getC());
        Assert.assertSame(array2[0].getA().getC(), array2[0].getB().getC());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 29

                      Assert.assertNotNull(array2[0].getB());
        Assert.assertNotNull(array2[0].getA().getC());
        Assert.assertNotNull(array2[0].getB().getC());
        Assert.assertSame(array2[0].getA().getC(), array2[0].getB().getC());
    }

    public static class VO {

        private A a;

            

Reported by PMD.

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

Line: 29

                      Assert.assertNotNull(array2[0].getB());
        Assert.assertNotNull(array2[0].getA().getC());
        Assert.assertNotNull(array2[0].getB().getC());
        Assert.assertSame(array2[0].getA().getC(), array2[0].getB().getC());
    }

    public static class VO {

        private A a;

            

Reported by PMD.

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

Line: 29

                      Assert.assertNotNull(array2[0].getB());
        Assert.assertNotNull(array2[0].getA().getC());
        Assert.assertNotNull(array2[0].getB().getC());
        Assert.assertSame(array2[0].getA().getC(), array2[0].getB().getC());
    }

    public static class VO {

        private A a;

            

Reported by PMD.

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

Line: 29

                      Assert.assertNotNull(array2[0].getB());
        Assert.assertNotNull(array2[0].getA().getC());
        Assert.assertNotNull(array2[0].getB().getC());
        Assert.assertSame(array2[0].getA().getC(), array2[0].getB().getC());
    }

    public static class VO {

        private A a;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1700/Issue1766.java
11 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 10

              import java.util.Date;

public class Issue1766 extends TestCase {
    public void test_for_issue() throws Exception {
// succ
        String json = "{\"name\":\"张三\"\n, \"birthday\":\"2017-01-01 01:01:01\"}";
        User user = JSON.parseObject(json, User.class);
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());

            

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

              import java.util.Date;

public class Issue1766 extends TestCase {
    public void test_for_issue() throws Exception {
// succ
        String json = "{\"name\":\"张三\"\n, \"birthday\":\"2017-01-01 01:01:01\"}";
        User user = JSON.parseObject(json, User.class);
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

              // succ
        String json = "{\"name\":\"张三\"\n, \"birthday\":\"2017-01-01 01:01:01\"}";
        User user = JSON.parseObject(json, User.class);
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());

        // failed
        json = "{\"name\":\"张三\", \"birthday\":\"2017-01-01 01:01:02\"\n}";
        user = JSON.parseObject(json, User.class);// will exception

            

Reported by PMD.

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

Line: 14

              // succ
        String json = "{\"name\":\"张三\"\n, \"birthday\":\"2017-01-01 01:01:01\"}";
        User user = JSON.parseObject(json, User.class);
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());

        // failed
        json = "{\"name\":\"张三\", \"birthday\":\"2017-01-01 01:01:02\"\n}";
        user = JSON.parseObject(json, User.class);// will exception

            

Reported by PMD.

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

Line: 15

                      String json = "{\"name\":\"张三\"\n, \"birthday\":\"2017-01-01 01:01:01\"}";
        User user = JSON.parseObject(json, User.class);
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());

        // failed
        json = "{\"name\":\"张三\", \"birthday\":\"2017-01-01 01:01:02\"\n}";
        user = JSON.parseObject(json, User.class);// will exception
        assertEquals("张三", user.getName());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                      String json = "{\"name\":\"张三\"\n, \"birthday\":\"2017-01-01 01:01:01\"}";
        User user = JSON.parseObject(json, User.class);
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());

        // failed
        json = "{\"name\":\"张三\", \"birthday\":\"2017-01-01 01:01:02\"\n}";
        user = JSON.parseObject(json, User.class);// will exception
        assertEquals("张三", user.getName());

            

Reported by PMD.

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

Line: 20

                      // failed
        json = "{\"name\":\"张三\", \"birthday\":\"2017-01-01 01:01:02\"\n}";
        user = JSON.parseObject(json, User.class);// will exception
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());
    }

    public static class User
    {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      // failed
        json = "{\"name\":\"张三\", \"birthday\":\"2017-01-01 01:01:02\"\n}";
        user = JSON.parseObject(json, User.class);// will exception
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());
    }

    public static class User
    {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      json = "{\"name\":\"张三\", \"birthday\":\"2017-01-01 01:01:02\"\n}";
        user = JSON.parseObject(json, User.class);// will exception
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());
    }

    public static class User
    {
        private String name;

            

Reported by PMD.

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

Line: 21

                      json = "{\"name\":\"张三\", \"birthday\":\"2017-01-01 01:01:02\"\n}";
        user = JSON.parseObject(json, User.class);// will exception
        assertEquals("张三", user.getName());
        assertNotNull(user.getBirthday());
    }

    public static class User
    {
        private String name;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/ref/RefTest14.java
11 issues
System.out.println is used
Design

Line: 37

                      SerializeConfig serializeConfig = new SerializeConfig();
        serializeConfig.setAsmEnable(false);
        String text = JSON.toJSONString(admin, serializeConfig, SerializerFeature.PrettyFormat);
        System.out.println(text);
        
        ParserConfig config = new ParserConfig();
        config.setAsmEnable(false);
        
        JSON.parseObject(text, Group.class, config, 0);

            

Reported by PMD.

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

Line: 15

              
public class RefTest14 extends TestCase {

    public void test_0() throws Exception {
        Group admin = new Group("admin");

        User jobs = new User("jobs");
        User sager = new User("sager");
        User sdh5724 = new User("sdh5724");

            

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 RefTest14 extends TestCase {

    public void test_0() throws Exception {
        Group admin = new Group("admin");

        User jobs = new User("jobs");
        User sager = new User("sager");
        User sdh5724 = new User("sdh5724");

            

Reported by PMD.

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

Line: 22

                      User sager = new User("sager");
        User sdh5724 = new User("sdh5724");

        admin.getMembers().add(jobs);
        jobs.getGroups().add(admin);

        admin.getMembers().add(sager);
        sager.getGroups().add(admin);


            

Reported by PMD.

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

Line: 23

                      User sdh5724 = new User("sdh5724");

        admin.getMembers().add(jobs);
        jobs.getGroups().add(admin);

        admin.getMembers().add(sager);
        sager.getGroups().add(admin);

        admin.getMembers().add(sdh5724);

            

Reported by PMD.

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

Line: 25

                      admin.getMembers().add(jobs);
        jobs.getGroups().add(admin);

        admin.getMembers().add(sager);
        sager.getGroups().add(admin);

        admin.getMembers().add(sdh5724);
        sdh5724.getGroups().add(admin);
        

            

Reported by PMD.

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

Line: 26

                      jobs.getGroups().add(admin);

        admin.getMembers().add(sager);
        sager.getGroups().add(admin);

        admin.getMembers().add(sdh5724);
        sdh5724.getGroups().add(admin);
        
        sager.setReportTo(sdh5724);

            

Reported by PMD.

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

Line: 28

                      admin.getMembers().add(sager);
        sager.getGroups().add(admin);

        admin.getMembers().add(sdh5724);
        sdh5724.getGroups().add(admin);
        
        sager.setReportTo(sdh5724);
        jobs.setReportTo(sdh5724);


            

Reported by PMD.

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

Line: 29

                      sager.getGroups().add(admin);

        admin.getMembers().add(sdh5724);
        sdh5724.getGroups().add(admin);
        
        sager.setReportTo(sdh5724);
        jobs.setReportTo(sdh5724);

        SerializeConfig serializeConfig = new SerializeConfig();

            

Reported by PMD.

The class 'Group' is suspected to be a Data Class (WOC=14.286%, NOPA=0, NOAM=4, WMC=7)
Design

Line: 45

                      JSON.parseObject(text, Group.class, config, 0);
    }

    public static class Group {

        private String     name;

        private List<User> members = new ArrayList<User>();


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_3300/Issue3376.java
11 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 11

               * @Date :Created in 01:25 2020/8/2
 */
public class Issue3376 extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model(1, 1);
        String modelString = JSON.toJSONString(model);
        assertEquals("{}", modelString);

        Model2 model2 = new Model2(1, 1);

            

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

               * @Date :Created in 01:25 2020/8/2
 */
public class Issue3376 extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model(1, 1);
        String modelString = JSON.toJSONString(model);
        assertEquals("{}", modelString);

        Model2 model2 = new Model2(1, 1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

                  public void test_for_issue() throws Exception {
        Model model = new Model(1, 1);
        String modelString = JSON.toJSONString(model);
        assertEquals("{}", modelString);

        Model2 model2 = new Model2(1, 1);
        String model2String = JSON.toJSONString(model2);
        assertEquals("{\"offset\":1,\"timestamp\":1}", model2String);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
        Model2 model2 = new Model2(1, 1);
        String model2String = JSON.toJSONString(model2);
        assertEquals("{\"offset\":1,\"timestamp\":1}", model2String);

        Model3 model3 = new Model3(1, 1);
        String model3String = JSON.toJSONString(model3);
        assertEquals("{\"off\":1,\"timeStamp\":true,\"timestamp\":1}", model3String);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

              
        Model3 model3 = new Model3(1, 1);
        String model3String = JSON.toJSONString(model3);
        assertEquals("{\"off\":1,\"timeStamp\":true,\"timestamp\":1}", model3String);
    }

    public static class Model {
        private final long offset;
        private final long timestamp;

            

Reported by PMD.

Field offset has the same name as a method
Error

Line: 26

                  }

    public static class Model {
        private final long offset;
        private final long timestamp;

        public Model(long offset, long timestamp) {
            this.offset = offset;
            this.timestamp = timestamp;

            

Reported by PMD.

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

Line: 26

                  }

    public static class Model {
        private final long offset;
        private final long timestamp;

        public Model(long offset, long timestamp) {
            this.offset = offset;
            this.timestamp = timestamp;

            

Reported by PMD.

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

Line: 27

              
    public static class Model {
        private final long offset;
        private final long timestamp;

        public Model(long offset, long timestamp) {
            this.offset = offset;
            this.timestamp = timestamp;
        }

            

Reported by PMD.

Field timestamp has the same name as a method
Error

Line: 27

              
    public static class Model {
        private final long offset;
        private final long timestamp;

        public Model(long offset, long timestamp) {
            this.offset = offset;
            this.timestamp = timestamp;
        }

            

Reported by PMD.

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

Line: 65

                  }

    public static class Model3 {
        private final long offset;
        public final long timestamp;

        public Model3(long offset, long timestamp) {
            this.offset = offset;
            this.timestamp = timestamp;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/filters/PropertyPathTest3.java
11 issues
System.out.println is used
Design

Line: 68

              		public boolean apply(JSONSerializer serializer, Object source, String name) {
			SerialContext nowContext = new SerialContext(serializer.getContext(), source, name, 0, 0);
			String nowPath = getLinkedPath(nowContext);
			System.out.println("path->" + nowPath);
			//只输出children.id
			return containInclude(onlyProperties, nowPath);
		}

	}

            

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

              public class PropertyPathTest3 extends TestCase {

	/** 测试只输出子集合中的特定属性 */
	public void test_path() throws Exception {
		Person p1 = new Person();
		p1.setId(100);

		Person c1 = new Person();
		c1.setId(1000);

            

Reported by PMD.

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

Line: 28

              		Person c2 = new Person();
		c2.setId(2000);

		p1.getChildren().add(c1);
		p1.getChildren().add(c2);
		//只输出children.id以及根上的id
		String s = JSON.toJSONString(p1, new MyPropertyPreFilter(new String[] {"children.id", "id"}));

		Assert.assertEquals("{\"children\":[{\"id\":1000},{\"id\":2000}],\"id\":100}", s);

            

Reported by PMD.

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

Line: 29

              		c2.setId(2000);

		p1.getChildren().add(c1);
		p1.getChildren().add(c2);
		//只输出children.id以及根上的id
		String s = JSON.toJSONString(p1, new MyPropertyPreFilter(new String[] {"children.id", "id"}));

		Assert.assertEquals("{\"children\":[{\"id\":1000},{\"id\":2000}],\"id\":100}", s);
	}

            

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

              	}

	/** 测试只输出子字段map中的特定属性 */
	public void test_path2() throws Exception {
		Person2 p1 = new Person2();
		p1.setId(1);
		Map<String, String> infoMap = new HashMap<String, String>();
		infoMap.put("name", "李三");
		infoMap.put("height", "168");

            

Reported by PMD.

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

Line: 50

              	}

	public static class MyPropertyPreFilter implements PropertyPreFilter {
		String[] onlyProperties;

		public MyPropertyPreFilter(String[] onlyProperties) {
			this.onlyProperties = onlyProperties;
		}


            

Reported by PMD.

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

Line: 52

              	public static class MyPropertyPreFilter implements PropertyPreFilter {
		String[] onlyProperties;

		public MyPropertyPreFilter(String[] onlyProperties) {
			this.onlyProperties = onlyProperties;
		}

		private static boolean containInclude(String[] ss, String s) {
			if(ss == null || ss.length == 0 || s == null)

            

Reported by PMD.

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

Line: 86

              		if(isCollection || isFieldNameNull)
			return parentLinkedPath;
		return
			parentLinkedPath.length() == 0 ? String.valueOf(serialContext.fieldName) :
				parentLinkedPath + "." + serialContext.fieldName;
	}

	public static class Person {


            

Reported by PMD.

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

Line: 90

              				parentLinkedPath + "." + serialContext.fieldName;
	}

	public static class Person {

		private int id;
		private int id2;

		private List<Person> children = new ArrayList<Person>();

            

Reported by PMD.

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

Line: 123

              
	}

	public static class Person2 {
		private int id;
		private Map<String, String> infoMap;

		public int getId() {
			return id;

            

Reported by PMD.

src/test/java/com/alibaba/json/test/Issue1488.java
11 issues
System.out.println is used
Design

Line: 23

                      final int THREAD_NUMBER = 10;
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(THREAD_NUMBER);
        for (int i = 0; i < 10; ++i) {
            System.out.println("start....");
            threadPool.scheduleAtFixedRate(new Runnable() {
                public void run() {
                    Map map = new HashMap();
                    map.put("run_id", "aeca30e");
                    map.put("port", 1002);

            

Reported by PMD.

System.out.println is used
Design

Line: 30

                                  map.put("run_id", "aeca30e");
                    map.put("port", 1002);
                    map.put("processId", 3001);
                    System.out.println(JSON.toJSONString(JSON.parseObject(JSON.toJSONString(map), clazz)));
                }
            }, 1, 1, TimeUnit.SECONDS);
        }

        Thread.sleep(1000 * 1000);

            

Reported by PMD.

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

Line: 16

              import java.util.concurrent.TimeUnit;

public class Issue1488 extends TestCase {
    public void test_user() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        final Class clazz = classLoader.loadClass("Issue1488_Server");

        final int THREAD_NUMBER = 10;
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(THREAD_NUMBER);

            

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.concurrent.TimeUnit;

public class Issue1488 extends TestCase {
    public void test_user() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        final Class clazz = classLoader.loadClass("Issue1488_Server");

        final int THREAD_NUMBER = 10;
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(THREAD_NUMBER);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 24

                      ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(THREAD_NUMBER);
        for (int i = 0; i < 10; ++i) {
            System.out.println("start....");
            threadPool.scheduleAtFixedRate(new Runnable() {
                public void run() {
                    Map map = new HashMap();
                    map.put("run_id", "aeca30e");
                    map.put("port", 1002);
                    map.put("processId", 3001);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 26

                          System.out.println("start....");
            threadPool.scheduleAtFixedRate(new Runnable() {
                public void run() {
                    Map map = new HashMap();
                    map.put("run_id", "aeca30e");
                    map.put("port", 1002);
                    map.put("processId", 3001);
                    System.out.println(JSON.toJSONString(JSON.parseObject(JSON.toJSONString(map), clazz)));
                }

            

Reported by PMD.

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

Line: 49

              
            {
                byte[] bytes;
                InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/Issue1488_Server.clazz");
                bytes = IOUtils.toByteArray(is);
                is.close();

                super.defineClass("Issue1488_Server", bytes, 0, bytes.length);
            }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'clazz' (lines '18'-'40').
Error

Line: 18

              public class Issue1488 extends TestCase {
    public void test_user() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        final Class clazz = classLoader.loadClass("Issue1488_Server");

        final int THREAD_NUMBER = 10;
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(THREAD_NUMBER);
        for (int i = 0; i < 10; ++i) {
            System.out.println("start....");

            

Reported by PMD.

Found 'DU'-anomaly for variable 'clazz' (lines '18'-'40').
Error

Line: 18

              public class Issue1488 extends TestCase {
    public void test_user() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        final Class clazz = classLoader.loadClass("Issue1488_Server");

        final int THREAD_NUMBER = 10;
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(THREAD_NUMBER);
        for (int i = 0; i < 10; ++i) {
            System.out.println("start....");

            

Reported by PMD.

Found 'DU'-anomaly for variable 'threadPool' (lines '21'-'40').
Error

Line: 21

                      final Class clazz = classLoader.loadClass("Issue1488_Server");

        final int THREAD_NUMBER = 10;
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(THREAD_NUMBER);
        for (int i = 0; i < 10; ++i) {
            System.out.println("start....");
            threadPool.scheduleAtFixedRate(new Runnable() {
                public void run() {
                    Map map = new HashMap();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1700/Issue1763.java
11 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 12

              import java.util.Map;

public class Issue1763 extends TestCase {
    public void test_for_issue() throws Exception {
        String s = "{\"result\":{\"modelList\":[{\"sourceId\":\"81900002\"},{\"sourceId\":\"81900002\"},{\"sourceId\":\"81892012\"},{\"sourceId\":\"2062014\"},{\"sourceId\":\"2082007\"},{\"sourceId\":\"2082007\"},{\"sourceId\":\"2082007\"}]}}";


        Method method = ProcurementOrderInteractiveServiceForCloud.class.getMethod("queryOrderMateriel", Map.class);
        Type type = method.getGenericReturnType();

            

Reported by PMD.

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

Line: 12

              import java.util.Map;

public class Issue1763 extends TestCase {
    public void test_for_issue() throws Exception {
        String s = "{\"result\":{\"modelList\":[{\"sourceId\":\"81900002\"},{\"sourceId\":\"81900002\"},{\"sourceId\":\"81892012\"},{\"sourceId\":\"2062014\"},{\"sourceId\":\"2082007\"},{\"sourceId\":\"2082007\"},{\"sourceId\":\"2082007\"}]}}";


        Method method = ProcurementOrderInteractiveServiceForCloud.class.getMethod("queryOrderMateriel", Map.class);
        Type type = method.getGenericReturnType();

            

Reported by PMD.

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

Line: 17

              

        Method method = ProcurementOrderInteractiveServiceForCloud.class.getMethod("queryOrderMateriel", Map.class);
        Type type = method.getGenericReturnType();

        BaseResult<InteractiveOrderMaterielQueryResult> baseResult = JSON.parseObject(s, type);
        InteractiveOrderMaterielQueryResult result = baseResult.getResult();

        assertEquals(7, result.getModelList().size());

            

Reported by PMD.

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

Line: 20

                      Type type = method.getGenericReturnType();

        BaseResult<InteractiveOrderMaterielQueryResult> baseResult = JSON.parseObject(s, type);
        InteractiveOrderMaterielQueryResult result = baseResult.getResult();

        assertEquals(7, result.getModelList().size());
        assertEquals(InteractiveOrderMaterielModel.class, result.getModelList().get(0).getClass());
    }


            

Reported by PMD.

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

Line: 22

                      BaseResult<InteractiveOrderMaterielQueryResult> baseResult = JSON.parseObject(s, type);
        InteractiveOrderMaterielQueryResult result = baseResult.getResult();

        assertEquals(7, result.getModelList().size());
        assertEquals(InteractiveOrderMaterielModel.class, result.getModelList().get(0).getClass());
    }

    public static class BaseResult<T> {
        private T result;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      BaseResult<InteractiveOrderMaterielQueryResult> baseResult = JSON.parseObject(s, type);
        InteractiveOrderMaterielQueryResult result = baseResult.getResult();

        assertEquals(7, result.getModelList().size());
        assertEquals(InteractiveOrderMaterielModel.class, result.getModelList().get(0).getClass());
    }

    public static class BaseResult<T> {
        private T result;

            

Reported by PMD.

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

Line: 22

                      BaseResult<InteractiveOrderMaterielQueryResult> baseResult = JSON.parseObject(s, type);
        InteractiveOrderMaterielQueryResult result = baseResult.getResult();

        assertEquals(7, result.getModelList().size());
        assertEquals(InteractiveOrderMaterielModel.class, result.getModelList().get(0).getClass());
    }

    public static class BaseResult<T> {
        private T result;

            

Reported by PMD.

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

Line: 23

                      InteractiveOrderMaterielQueryResult result = baseResult.getResult();

        assertEquals(7, result.getModelList().size());
        assertEquals(InteractiveOrderMaterielModel.class, result.getModelList().get(0).getClass());
    }

    public static class BaseResult<T> {
        private T result;


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                      InteractiveOrderMaterielQueryResult result = baseResult.getResult();

        assertEquals(7, result.getModelList().size());
        assertEquals(InteractiveOrderMaterielModel.class, result.getModelList().get(0).getClass());
    }

    public static class BaseResult<T> {
        private T result;


            

Reported by PMD.

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

Line: 23

                      InteractiveOrderMaterielQueryResult result = baseResult.getResult();

        assertEquals(7, result.getModelList().size());
        assertEquals(InteractiveOrderMaterielModel.class, result.getModelList().get(0).getClass());
    }

    public static class BaseResult<T> {
        private T result;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/path/JSONPath_paths_test3.java
11 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: 13

              import junit.framework.TestCase;

public class JSONPath_paths_test3 extends TestCase {
    public void test_map() throws Exception {
        Model model = new Model();
        model.id = 1001;
        model.name = "wenshao";
        model.attributes.put("type", "employee");
        

            

Reported by PMD.

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

Line: 17

                      Model model = new Model();
        model.id = 1001;
        model.name = "wenshao";
        model.attributes.put("type", "employee");
        
        Map<String, Object> paths = JSONPath.paths(model);
        
        Assert.assertEquals(5, paths.size());
        Assert.assertSame(model, paths.get("/"));

            

Reported by PMD.

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

Line: 21

                      
        Map<String, Object> paths = JSONPath.paths(model);
        
        Assert.assertEquals(5, paths.size());
        Assert.assertSame(model, paths.get("/"));
        Assert.assertEquals(1001, paths.get("/id"));
        Assert.assertEquals("wenshao", paths.get("/name"));
        Assert.assertSame(model.attributes, paths.get("/attributes"));
        Assert.assertEquals("employee", paths.get("/attributes/type"));

            

Reported by PMD.

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

Line: 22

                      Map<String, Object> paths = JSONPath.paths(model);
        
        Assert.assertEquals(5, paths.size());
        Assert.assertSame(model, paths.get("/"));
        Assert.assertEquals(1001, paths.get("/id"));
        Assert.assertEquals("wenshao", paths.get("/name"));
        Assert.assertSame(model.attributes, paths.get("/attributes"));
        Assert.assertEquals("employee", paths.get("/attributes/type"));
    }

            

Reported by PMD.

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

Line: 23

                      
        Assert.assertEquals(5, paths.size());
        Assert.assertSame(model, paths.get("/"));
        Assert.assertEquals(1001, paths.get("/id"));
        Assert.assertEquals("wenshao", paths.get("/name"));
        Assert.assertSame(model.attributes, paths.get("/attributes"));
        Assert.assertEquals("employee", paths.get("/attributes/type"));
    }
    

            

Reported by PMD.

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

Line: 24

                      Assert.assertEquals(5, paths.size());
        Assert.assertSame(model, paths.get("/"));
        Assert.assertEquals(1001, paths.get("/id"));
        Assert.assertEquals("wenshao", paths.get("/name"));
        Assert.assertSame(model.attributes, paths.get("/attributes"));
        Assert.assertEquals("employee", paths.get("/attributes/type"));
    }
    
    public static class Model {

            

Reported by PMD.

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

Line: 25

                      Assert.assertSame(model, paths.get("/"));
        Assert.assertEquals(1001, paths.get("/id"));
        Assert.assertEquals("wenshao", paths.get("/name"));
        Assert.assertSame(model.attributes, paths.get("/attributes"));
        Assert.assertEquals("employee", paths.get("/attributes/type"));
    }
    
    public static class Model {
        public int id;

            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals(1001, paths.get("/id"));
        Assert.assertEquals("wenshao", paths.get("/name"));
        Assert.assertSame(model.attributes, paths.get("/attributes"));
        Assert.assertEquals("employee", paths.get("/attributes/type"));
    }
    
    public static class Model {
        public int id;
        public String name;

            

Reported by PMD.

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

Line: 30

                  }
    
    public static class Model {
        public int id;
        public String name;
        
        public Map<String, Object> attributes = new HashMap<String, Object>();
    }
}

            

Reported by PMD.

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

Line: 31

                  
    public static class Model {
        public int id;
        public String name;
        
        public Map<String, Object> attributes = new HashMap<String, Object>();
    }
}

            

Reported by PMD.

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

    public void test_set() throws Exception {
        Entity entity = new Entity();

        JSONPath.set(entity, "$.name", "abc");

        Assert.assertEquals("abc", entity.getName());

            

Reported by PMD.

The String literal 'abc' appears 9 times in this file; the first occurrence is on line 21
Error

Line: 21

                  public void test_set() throws Exception {
        Entity entity = new Entity();

        JSONPath.set(entity, "$.name", "abc");

        Assert.assertEquals("abc", entity.getName());
    }

    public void test_set_array() throws Exception {

            

Reported by PMD.

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

Line: 26

                      Assert.assertEquals("abc", entity.getName());
    }

    public void test_set_array() throws Exception {
        Object[] array = new Object[1];

        JSONPath.set(array, "[0]", "abc");

        Assert.assertEquals("abc", array[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: 34

                      Assert.assertEquals("abc", array[0]);
    }

    public void test_set_list() throws Exception {
        List array = new ArrayList();
        array.add(null);
        array.add(null);

        JSONPath.set(array, "[0]", "abc");

            

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

                      Assert.assertEquals("abc", array.get(0));
    }

    public void test_root_null() throws Exception {
        Assert.assertFalse(JSONPath.set(null, "[0]", "abc"));
    }
    
    public void test_object_not_exits() throws Exception {
        Map<String, Object> root = new HashMap<String, Object>();

            

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

                      Assert.assertFalse(JSONPath.set(null, "[0]", "abc"));
    }
    
    public void test_object_not_exits() throws Exception {
        Map<String, Object> root = new HashMap<String, Object>();
        root.put("values", null);
        Assert.assertTrue(JSONPath.set(root, "$.values[0]", "abc"));
    }


            

Reported by PMD.

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

Line: 54

                      Assert.assertTrue(JSONPath.set(root, "$.values[0]", "abc"));
    }

    public void test_error() throws Exception {
        Map<String, Object> root = new HashMap<String, Object>();
        root.put("values", null);
        JSONPath.set(root, "$.values[0]", "abc");
    }


            

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

                      Assert.assertTrue(JSONPath.set(root, "$.values[0]", "abc"));
    }

    public void test_error() throws Exception {
        Map<String, Object> root = new HashMap<String, Object>();
        root.put("values", null);
        JSONPath.set(root, "$.values[0]", "abc");
    }


            

Reported by PMD.

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

Line: 60

                      JSONPath.set(root, "$.values[0]", "abc");
    }

    static class Entity {

        private Integer id;
        private String  name;

        public Integer getId() {

            

Reported by PMD.

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

Line: 4

              package com.alibaba.json.bvt.path;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assert;

            

Reported by PMD.