The following issues were found

src/test/java/com/alibaba/json/bvt/feature/FeaturesTest3.java
3 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

              
public class FeaturesTest3 extends TestCase {

    public void test_0() throws Exception {
        SerializeConfig config = new SerializeConfig();
        config.setAsmEnable(false);
        
        String text = JSON.toJSONString(new Entity(), config);
        Assert.assertEquals("{\"value\":0}", text);

            

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

                      Assert.assertEquals("{\"value\":0}", text);
    }
    
    public void test_1() throws Exception {
        SerializeConfig config = new SerializeConfig();
        config.setAsmEnable(true);
        
        String text = JSON.toJSONString(new Entity(), config);
        Assert.assertEquals("{\"value\":0}", text);

            

Reported by PMD.

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

Line: 31

              
    public static class Entity {

        private Integer value;

        @JSONField(serialzeFeatures = { SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullNumberAsZero })
        public Integer getValue() {
            return value;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/kotlin/Issue1569.java
3 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: 11

              import java.io.InputStream;

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

        String json = "{\"loginName\":\"san\",\"userId\":1}";
        Object head = JSON.parseObject(json, clazz);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              
        String json = "{\"loginName\":\"san\",\"userId\":1}";
        Object head = JSON.parseObject(json, clazz);
        assertEquals(json, JSON.toJSONString(head));
    }

    public static class ExtClassLoader extends ClassLoader {

        public ExtClassLoader() throws IOException {

            

Reported by PMD.

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

Line: 27

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

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

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/feature/FeaturesTest2.java
3 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

              
public class FeaturesTest2 extends TestCase {

    public void test_0() throws Exception {
        SerializeConfig config = new SerializeConfig();
        config.setAsmEnable(false);
        
        String text = JSON.toJSONString(new Entity(), config);
        Assert.assertEquals("{\"value\":0}", text);

            

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

                      Assert.assertEquals("{\"value\":0}", text);
    }
    
    public void test_1() throws Exception {
        SerializeConfig config = new SerializeConfig();
        config.setAsmEnable(true);
        
        String text = JSON.toJSONString(new Entity(), config);
        Assert.assertEquals("{\"value\":0}", text);

            

Reported by PMD.

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

Line: 31

              
    private static class Entity {

        private Integer value;

        @JSONField(serialzeFeatures = { SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullNumberAsZero })
        public Integer getValue() {
            return value;
        }

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 06/08/2017.
 */
public class ClassWithPairMixedTypesTest extends TestCase {
    public void test_user() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        Class clazz = classLoader.loadClass("ClassWithPairMixedTypes");

        String json = "{\"person\":{\"first\":\"wenshao\",\"second\":99}}";
        Object obj = JSON.parseObject(json, clazz);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        String json = "{\"person\":{\"first\":\"wenshao\",\"second\":99}}";
        Object obj = JSON.parseObject(json, clazz);
        assertEquals("{\"person\":{\"first\":\"wenshao\",\"second\":99}}", JSON.toJSONString(obj));
    }

    public static class ExtClassLoader extends ClassLoader {

        public ExtClassLoader() throws IOException {

            

Reported by PMD.

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

Line: 30

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

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

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1500/Issue1503.java
3 issues
System.out.println is used
Design

Line: 18

                      Map<Long, Bean> map = new HashMap<Long, Bean>();
        map.put(null, new Bean());
        Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);
        System.out.println(rmap);
    }

    public static class Bean {

    }

            

Reported by PMD.

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

Line: 12

              import java.util.Map;

public class Issue1503 extends TestCase {
    public void test_for_issue() throws Exception {
        ParserConfig config = new ParserConfig();
        config.setAutoTypeSupport(true);
        Map<Long, Bean> map = new HashMap<Long, Bean>();
        map.put(null, new Bean());
        Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);

            

Reported by PMD.

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

Line: 12

              import java.util.Map;

public class Issue1503 extends TestCase {
    public void test_for_issue() throws Exception {
        ParserConfig config = new ParserConfig();
        config.setAutoTypeSupport(true);
        Map<Long, Bean> map = new HashMap<Long, Bean>();
        map.put(null, new Bean());
        Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1500/Issue1580.java
3 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

              import junit.framework.TestCase;

public class Issue1580 extends TestCase {
    public void test_for_issue() throws Exception {
        SimplePropertyPreFilter classAFilter = new SimplePropertyPreFilter(Model.class, "code");
        SerializeFilter[] filters =new SerializeFilter[]{classAFilter};

        Model model = new Model();
        model.code = 1001;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      model.name = "N1";

        String json = JSON.toJSONString(model, filters, SerializerFeature.BeanToArray );
        assertEquals("[1001,null]", json);
    }

    public static class Model {
        private int code;
        private String name;

            

Reported by PMD.

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

Line: 22

                      assertEquals("[1001,null]", json);
    }

    public static class Model {
        private int code;
        private String name;

        public int getCode() {
            return code;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1500/Issue1580_private.java
3 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

              import junit.framework.TestCase;

public class Issue1580_private extends TestCase {
    public void test_for_issue() throws Exception {
        SimplePropertyPreFilter classAFilter = new SimplePropertyPreFilter(Model.class, "code");
        SerializeFilter[] filters =new SerializeFilter[]{classAFilter};

        Model model = new Model();
        model.code = 1001;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      model.name = "N1";

        String json = JSON.toJSONString(model, filters, SerializerFeature.BeanToArray );
        assertEquals("[1001,null]", json);
    }

    private static class Model {
        private int code;
        private String name;

            

Reported by PMD.

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

Line: 22

                      assertEquals("[1001,null]", json);
    }

    private static class Model {
        private int code;
        private String name;

        public int getCode() {
            return code;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/joda/JodaTest_4_InstantTest.java
3 issues
System.out.println is used
Design

Line: 16

                      vo.setDate(Instant.now());
        
        String text = JSON.toJSONString(vo);
        System.out.println(text);
        
        VO vo1 = JSON.parseObject(text, VO.class);
        
        Assert.assertEquals(vo.getDate(), vo1.getDate());
    }

            

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

    public void test_for_issue() throws Exception {
        VO vo = new VO();
        vo.setDate(Instant.now());
        
        String text = JSON.toJSONString(vo);
        System.out.println(text);

            

Reported by PMD.

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

Line: 20

                      
        VO vo1 = JSON.parseObject(text, VO.class);
        
        Assert.assertEquals(vo.getDate(), vo1.getDate());
    }

    public static class VO {

        private Instant date;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1600/Issue1627.java
3 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 Issue1627 extends TestCase {
    public void test_for_issue() throws Exception {
        String a = "{\"101a0.test-b\":\"tt\"}";
        Object o = JSON.parse(a);
        String s = "101a0.test-b";
        assertTrue(JSONPath.contains(o, "$." + escapeString(s)));
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

                      String a = "{\"101a0.test-b\":\"tt\"}";
        Object o = JSON.parse(a);
        String s = "101a0.test-b";
        assertTrue(JSONPath.contains(o, "$." + escapeString(s)));
    }

    public static String escapeString(String s) {
        StringBuilder buf = new StringBuilder();


            

Reported by PMD.

Avoid concatenating nonliterals in a StringBuffer/StringBuilder constructor or append().
Performance

Line: 21

                      for(int i = 0; i < s.length(); ++i) {
            char c = s.charAt(i);
            if((c < 48 || c > 57) && (c < 65 || c > 90) && (c < 97 || c > 122)) {
                buf.append("\\" + c);
            } else {
                buf.append(c);
            }
        }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/mixins/MixinAPITest.java
3 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 11

              public class MixinAPITest extends TestCase  {

    static class BaseClass {
        public int a;
        public int b;

        public  BaseClass() {

        }

            

Reported by PMD.

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

Line: 12

              
    static class BaseClass {
        public int a;
        public int b;

        public  BaseClass() {

        }


            

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

                  }


    public void test_mixIn_get_methods() throws Exception {
        BaseClass base = new BaseClass(1, 2);

        JSON.addMixInAnnotations(BaseClass.class, MixIn1.class);
        Assert.assertEquals("{\"apple\":1,\"banana\":2}", JSON.toJSONString(base));
        Assert.assertTrue(MixIn1.class == JSON.getMixInAnnotations(BaseClass.class));

            

Reported by PMD.