The following issues were found

src/test/java/com/alibaba/json/bvt/bug/Issue912.java
12 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 14

               * Created by wenshao on 06/12/2016.
 */
public class Issue912 extends TestCase {
    public void test_for_issue() throws Exception {
        String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 06/12/2016.
 */
public class Issue912 extends TestCase {
    public void test_for_issue() throws Exception {
        String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {

            

Reported by PMD.

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

Line: 18

                      String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {

            

Reported by PMD.

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

Line: 18

                      String allMethods = "{\"mList\":[{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayInt\",\"parameterSize\":1,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[I\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"},{\"className\":\"com.qa.scftemplate.contract.ISCFServiceForDyjAction\",\"methodName\":\"getArrayPrimative\",\"parameterSize\":7,\"parameters\":[{\"clazz\":\"[I\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[F\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[S\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[D\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[J\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[B\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"},{\"clazz\":\"[C\",\"clsList\":null,\"isGenericity\":false,\"value\":\"\"}],\"returnType\":\"[Ljava.lang.String;\",\"url\":\"tcp://SCFServiceForDyj/SCFServiceForDyjActionService\"}]}";
        JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {

            

Reported by PMD.

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

Line: 19

                      JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {
        T jd = (T) JSON.parseObject(json, clazz,

            

Reported by PMD.

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

Line: 19

                      JsonBean jsonBean = getJsonData(allMethods, JsonBean.class);

        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {
        T jd = (T) JSON.parseObject(json, clazz,

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        assertEquals(2, jsonBean.getmList().size());
        SCFMethod m1 = jsonBean.getmList().get(0);
        assertNotNull(m1);
    }

    public static <T> T getJsonData(String json, Class<T> clazz) {
        T jd = (T) JSON.parseObject(json, clazz,
                Feature.IgnoreNotMatch,

            

Reported by PMD.

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

Line: 32

                  }

    public static class JsonBean {
        private List<SCFMethod> mList;

        public List<SCFMethod> getmList() {
            return mList;
        }


            

Reported by PMD.

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

Line: 43

                      }
    }

    public static class SCFMethod {
        public String className;
        public String url;
        public String methodName;
        public int parameterSize;
        public List<SCFMethodParameter> parameters = new LinkedList<SCFMethodParameter>();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1200/Issue1233.java
12 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

               * Created by wenshao on 30/05/2017.
 */
public class Issue1233 extends TestCase {
    public void test_for_issue() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(Area.class, new ObjectDeserializer() {
            public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
                JSONObject jsonObject = (JSONObject) parser.parse();
                String areaType;


            

Reported by PMD.

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

Line: 17

               * Created by wenshao on 30/05/2017.
 */
public class Issue1233 extends TestCase {
    public void test_for_issue() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(Area.class, new ObjectDeserializer() {
            public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
                JSONObject jsonObject = (JSONObject) parser.parse();
                String areaType;


            

Reported by PMD.

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

Line: 23

                              JSONObject jsonObject = (JSONObject) parser.parse();
                String areaType;

                if (jsonObject.get("type") instanceof String) {
                    areaType = (String) jsonObject.get("type");
                } else {
                    return null;
                }
                if (Area.TYPE_SECTION.equals(areaType)) {

            

Reported by PMD.

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

Line: 28

                              } else {
                    return null;
                }
                if (Area.TYPE_SECTION.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, Section.class);
                } else if (Area.TYPE_FLOORV1.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, FloorV1.class);
                } else if (Area.TYPE_FLOORV2.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, FloorV2.class);

            

Reported by PMD.

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

Line: 30

                              }
                if (Area.TYPE_SECTION.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, Section.class);
                } else if (Area.TYPE_FLOORV1.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, FloorV1.class);
                } else if (Area.TYPE_FLOORV2.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, FloorV2.class);
                }
                return null;

            

Reported by PMD.

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

Line: 32

                                  return (T) JSON.toJavaObject(jsonObject, Section.class);
                } else if (Area.TYPE_FLOORV1.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, FloorV1.class);
                } else if (Area.TYPE_FLOORV2.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, FloorV2.class);
                }
                return null;
            }


            

Reported by PMD.

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

Line: 45

              
        JSONObject jsonObject = JSON.parseObject("{\"type\":\"floorV2\",\"templateId\":\"x123\"}");

        FloorV2 floorV2 = (FloorV2) jsonObject.toJavaObject(Area.class);
        assertNotNull(floorV2);
        assertEquals("x123", floorV2.templateId);
    }

    public interface Area {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

                      JSONObject jsonObject = JSON.parseObject("{\"type\":\"floorV2\",\"templateId\":\"x123\"}");

        FloorV2 floorV2 = (FloorV2) jsonObject.toJavaObject(Area.class);
        assertNotNull(floorV2);
        assertEquals("x123", floorV2.templateId);
    }

    public interface Area {
        public static final String TYPE_SECTION = "section";

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 47

              
        FloorV2 floorV2 = (FloorV2) jsonObject.toJavaObject(Area.class);
        assertNotNull(floorV2);
        assertEquals("x123", floorV2.templateId);
    }

    public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";

            

Reported by PMD.

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

Line: 63

              
        public String type;

        public String templateId;

        public String getName() {
            return templateId;
        }
    }

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 30/05/2017.
 */
public class Issue1235_noasm extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 30/05/2017.
 */
public class Issue1235_noasm extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              
        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }

    @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 27

              
    @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 28

                  @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")
    private static class FloorV2 implements Area {

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 29

                  public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")
    private static class FloorV2 implements Area {
        public String type;

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 30/05/2017.
 */
public class Issue1235 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 30/05/2017.
 */
public class Issue1235 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      String json = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";

        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              
        FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      FloorV2 floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
        assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      assertNotNull(floorV2);
        assertNotNull(floorV2.templateId);
        assertEquals("x123", floorV2.templateId);
        assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      assertEquals("floorV2", floorV2.type);

        String json2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
        assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);
    }

    @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 27

              
    @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 28

                  @JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
    public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")
    public static class FloorV2 implements Area {

            

Reported by PMD.

Avoid constants in interfaces. Interfaces define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
Design

Line: 29

                  public interface Area {
        public static final String TYPE_SECTION = "section";
        public static final String TYPE_FLOORV1 = "floorV1";
        public static final String TYPE_FLOORV2 = "floorV2";
    }

    @JSONType(typeName = "floorV2")
    public static class FloorV2 implements Area {
        public String type;

            

Reported by PMD.

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

Line: 15

              
public class NameFilterTest_long_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 19

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);
                    return "ID";
                }

                return name;

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 19

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);
                    return "ID";
                }

                return name;

            

Reported by PMD.

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

Line: 31

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

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

        String text = out.toString();

            

Reported by PMD.

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

Line: 40

                      Assert.assertEquals("{\"ID\":0}", text);
    }

    public void test_namefilter_1() throws Exception {
        NameFilter filter = new NameFilter() {

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

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 44

                      NameFilter filter = new NameFilter() {

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

                return name;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 44

                      NameFilter filter = new NameFilter() {

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

                return name;
            }

            

Reported by PMD.

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

Line: 55

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

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", 0);
        serializer.write(map);


            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '16'-'38').
Error

Line: 16

              public class NameFilterTest_long_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);
                    return "ID";

            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '16'-'38').
Error

Line: 16

              public class NameFilterTest_long_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Long);
                    return "ID";

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1200/Issue1246.java
12 issues
System.out.println is used
Design

Line: 19

                      b.setX("xx");

        String test = JSON.toJSONString( b );
        System.out.println(test);
        assertEquals("{}", test);

        C c = new C();
        c.ab = b ;


            

Reported by PMD.

System.out.println is used
Design

Line: 26

                      c.ab = b ;

        String testC = JSON.toJSONString( c );
        System.out.println(testC);
        assertEquals("{\"ab\":{}}",testC);

        D d = new D();
        d.setAb( b );


            

Reported by PMD.

System.out.println is used
Design

Line: 33

                      d.setAb( b );

        String testD = JSON.toJSONString( d );
        System.out.println(testD);
        assertEquals("{\"ab\":{}}",testD);
    }

    public static class C{
        public A ab;

            

Reported by PMD.

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

Line: 14

               * Created by kimmking on 06/06/2017.
 */
public class Issue1246 extends TestCase {
    public void test_for_issue() throws Exception {
        B b = new B();
        b.setX("xx");

        String test = JSON.toJSONString( b );
        System.out.println(test);

            

Reported by PMD.

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

Line: 14

               * Created by kimmking on 06/06/2017.
 */
public class Issue1246 extends TestCase {
    public void test_for_issue() throws Exception {
        B b = new B();
        b.setX("xx");

        String test = JSON.toJSONString( b );
        System.out.println(test);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        String test = JSON.toJSONString( b );
        System.out.println(test);
        assertEquals("{}", test);

        C c = new C();
        c.ab = b ;

        String testC = JSON.toJSONString( c );

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

              
        String testC = JSON.toJSONString( c );
        System.out.println(testC);
        assertEquals("{\"ab\":{}}",testC);

        D d = new D();
        d.setAb( b );

        String testD = JSON.toJSONString( d );

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

              
        String testD = JSON.toJSONString( d );
        System.out.println(testD);
        assertEquals("{\"ab\":{}}",testD);
    }

    public static class C{
        public A ab;
    }

            

Reported by PMD.

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

Line: 38

                  }

    public static class C{
        public A ab;
    }

    public static class D{
        private A ab;


            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.parser.ParserConfig'
Design

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;
import org.springframework.util.LinkedMultiValueMap;

/**

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/BigDecimalCodec.java
12 issues
The method 'write(JSONSerializer, Object, Object, Type, int)' has a cyclomatic complexity of 13.
Design

Line: 38

              
    public final static BigDecimalCodec instance = new BigDecimalCodec();

    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.out;

        if (object == null) {
            out.writeNull(SerializerFeature.WriteNullNumberAsZero);
        } else {

            

Reported by PMD.

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

Line: 45

                          out.writeNull(SerializerFeature.WriteNullNumberAsZero);
        } else {
            BigDecimal val = (BigDecimal) object;
            int scale = val.scale();

            String outText;
            if (SerializerFeature.isEnabled(features, out.features, SerializerFeature.WriteBigDecimalAsPlain)
                    && scale >= -100 && scale < 100) {
                outText = val.toPlainString();

            

Reported by PMD.

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

Line: 50

                          String outText;
            if (SerializerFeature.isEnabled(features, out.features, SerializerFeature.WriteBigDecimalAsPlain)
                    && scale >= -100 && scale < 100) {
                outText = val.toPlainString();
            } else {
                outText = val.toString();
            }

            if (scale == 0) {

            

Reported by PMD.

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

Line: 52

                                  && scale >= -100 && scale < 100) {
                outText = val.toPlainString();
            } else {
                outText = val.toString();
            }

            if (scale == 0) {
                if (outText.length() >= 16
                        && SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)

            

Reported by PMD.

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

Line: 56

                          }

            if (scale == 0) {
                if (outText.length() >= 16
                        && SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)
                        && (val.compareTo(LOW) < 0
                        || val.compareTo(HIGH) > 0))
                {
                    out.writeString(outText);

            

Reported by PMD.

These nested if statements could be combined
Design

Line: 56

                          }

            if (scale == 0) {
                if (outText.length() >= 16
                        && SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)
                        && (val.compareTo(LOW) < 0
                        || val.compareTo(HIGH) > 0))
                {
                    out.writeString(outText);

            

Reported by PMD.

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

Line: 58

                          if (scale == 0) {
                if (outText.length() >= 16
                        && SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)
                        && (val.compareTo(LOW) < 0
                        || val.compareTo(HIGH) > 0))
                {
                    out.writeString(outText);
                    return;
                }

            

Reported by PMD.

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

Line: 59

                              if (outText.length() >= 16
                        && SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)
                        && (val.compareTo(LOW) < 0
                        || val.compareTo(HIGH) > 0))
                {
                    out.writeString(outText);
                    return;
                }
            }

            

Reported by PMD.

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

Line: 68

              
            out.write(outText);

            if (out.isEnabled(SerializerFeature.WriteClassName) && fieldType != BigDecimal.class && val.scale() == 0) {
                out.write('.');
            }
        }
    }


            

Reported by PMD.

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

Line: 78

                  public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
        try {
            return (T) deserialze(parser);
        } catch (Exception ex) {
            throw new JSONException("parseDecimal error, field : " + fieldName, ex);
        }
    }

    @SuppressWarnings("unchecked")

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue72.java
12 issues
Avoid throwing raw exception types.
Design

Line: 27

                              } else if (fileBatchBytes == null) {
                    fileBatchBytes = reader.readObject(byte[].class);
                } else {
                    throw new Exception("archive data json parse failed!");
                }

            }
            reader.endArray();
        } finally {

            

Reported by PMD.

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

Line: 13

              
public class Issue72 extends TestCase {

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
        JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;

            

Reported by PMD.

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

Line: 13

              
public class Issue72 extends TestCase {

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
        JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;

            

Reported by PMD.

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

Line: 14

              public class Issue72 extends TestCase {

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
        JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;
            reader = new JSONReader(new InputStreamReader(is));

            

Reported by PMD.

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

Line: 14

              public class Issue72 extends TestCase {

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
        JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;
            reader = new JSONReader(new InputStreamReader(is));

            

Reported by PMD.

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

Line: 14

              public class Issue72 extends TestCase {

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
        JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;
            reader = new JSONReader(new InputStreamReader(is));

            

Reported by PMD.

In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
Error

Line: 14

              public class Issue72 extends TestCase {

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
        JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;
            reader = new JSONReader(new InputStreamReader(is));

            

Reported by PMD.

Found 'DD'-anomaly for variable 'reader' (lines '15'-'19').
Error

Line: 15

              
    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
        JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;
            reader = new JSONReader(new InputStreamReader(is));
            reader.startArray();

            

Reported by PMD.

Found 'DU'-anomaly for variable 'rowBatchBytes' (lines '17'-'35').
Error

Line: 17

                      InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
        JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;
            reader = new JSONReader(new InputStreamReader(is));
            reader.startArray();
            while (reader.hasNext()) {
                if (rowBatchBytes == null) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'fileBatchBytes' (lines '18'-'35').
Error

Line: 18

                      JSONReader reader = null;
        try {
            byte[] rowBatchBytes = null;
            byte[] fileBatchBytes = null;
            reader = new JSONReader(new InputStreamReader(is));
            reader.startArray();
            while (reader.hasNext()) {
                if (rowBatchBytes == null) {
                    rowBatchBytes = reader.readObject(byte[].class);

            

Reported by PMD.

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

Line: 7

              import junit.framework.TestCase;

public class Issue3343 extends TestCase {
    public void test_for_issue() throws Exception {
        assertFalse(
                JSONValidator.from("{\"name\":\"999}")
                        .validate());

        assertTrue(

            

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

              import junit.framework.TestCase;

public class Issue3343 extends TestCase {
    public void test_for_issue() throws Exception {
        assertFalse(
                JSONValidator.from("{\"name\":\"999}")
                        .validate());

        assertTrue(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 8

              
public class Issue3343 extends TestCase {
    public void test_for_issue() throws Exception {
        assertFalse(
                JSONValidator.from("{\"name\":\"999}")
                        .validate());

        assertTrue(
                JSONValidator.from("false")

            

Reported by PMD.

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

Line: 9

              public class Issue3343 extends TestCase {
    public void test_for_issue() throws Exception {
        assertFalse(
                JSONValidator.from("{\"name\":\"999}")
                        .validate());

        assertTrue(
                JSONValidator.from("false")
                        .validate());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

                              JSONValidator.from("{\"name\":\"999}")
                        .validate());

        assertTrue(
                JSONValidator.from("false")
                        .validate());
        assertEquals(JSONValidator.Type.Value,
                JSONValidator.from("false")
                        .getType());

            

Reported by PMD.

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

Line: 13

                                      .validate());

        assertTrue(
                JSONValidator.from("false")
                        .validate());
        assertEquals(JSONValidator.Type.Value,
                JSONValidator.from("false")
                        .getType());


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                      assertTrue(
                JSONValidator.from("false")
                        .validate());
        assertEquals(JSONValidator.Type.Value,
                JSONValidator.from("false")
                        .getType());

        assertTrue(
                JSONValidator.from("999").validate());

            

Reported by PMD.

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

Line: 16

                              JSONValidator.from("false")
                        .validate());
        assertEquals(JSONValidator.Type.Value,
                JSONValidator.from("false")
                        .getType());

        assertTrue(
                JSONValidator.from("999").validate());
        assertEquals(JSONValidator.Type.Value,

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                              JSONValidator.from("false")
                        .getType());

        assertTrue(
                JSONValidator.from("999").validate());
        assertEquals(JSONValidator.Type.Value,
                JSONValidator.from("999")
                        .getType());
    }

            

Reported by PMD.

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

Line: 20

                                      .getType());

        assertTrue(
                JSONValidator.from("999").validate());
        assertEquals(JSONValidator.Type.Value,
                JSONValidator.from("999")
                        .getType());
    }
}

            

Reported by PMD.

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

Line: 15

              
public class NameFilterTest_int_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 19

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);
                    return "ID";
                }

                return name;

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 19

                      NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);
                    return "ID";
                }

                return name;

            

Reported by PMD.

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

Line: 31

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

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

        String text = out.toString();

            

Reported by PMD.

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

Line: 40

                      Assert.assertEquals("{\"ID\":0}", text);
    }

    public void test_namefilter_1() throws Exception {
        NameFilter filter = new NameFilter() {

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

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 44

                      NameFilter filter = new NameFilter() {

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

                return name;
            }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 44

                      NameFilter filter = new NameFilter() {

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

                return name;
            }

            

Reported by PMD.

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

Line: 55

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

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", 0);
        serializer.write(map);


            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '16'-'38').
Error

Line: 16

              public class NameFilterTest_int_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);
                    return "ID";

            

Reported by PMD.

Found 'DU'-anomaly for variable 'filter' (lines '16'-'38').
Error

Line: 16

              public class NameFilterTest_int_field extends TestCase {

    public void test_namefilter() throws Exception {
        NameFilter filter = new NameFilter() {

            public String process(Object source, String name, Object value) {
                if (name.equals("id")) {
                    Assert.assertTrue(value instanceof Integer);
                    return "ID";

            

Reported by PMD.