The following issues were found

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.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/parser/deser/deny/InitJavaBeanDeserializerTest.java
12 issues
System.out.println is used
Design

Line: 36

                      Exception error = null;
        try {
            Object obj = JSON.parseObject(text, Object.class, config);
            System.out.println(obj.getClass());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNotNull(error);


            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 28/01/2017.
 */
public class InitJavaBeanDeserializerTest extends TestCase {
    ParserConfig config = new ParserConfig();

    protected void setUp() throws Exception {
        assertFalse(config.isAutoTypeSupport());

        Properties properties = new Properties();

            

Reported by PMD.

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

Line: 16

              public class InitJavaBeanDeserializerTest extends TestCase {
    ParserConfig config = new ParserConfig();

    protected void setUp() throws Exception {
        assertFalse(config.isAutoTypeSupport());

        Properties properties = new Properties();
        properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
        // config.addAccept("com.alibaba.json.bvt.parser.deser.deny.DenyTest11.Model");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                  ParserConfig config = new ParserConfig();

    protected void setUp() throws Exception {
        assertFalse(config.isAutoTypeSupport());

        Properties properties = new Properties();
        properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
        // config.addAccept("com.alibaba.json.bvt.parser.deser.deny.DenyTest11.Model");
        // -ea -Dfastjson.parser.autoTypeAccept=com.alibaba.json.bvt.parser.deser.deny.DenyTest9

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                      // -ea -Dfastjson.parser.autoTypeAccept=com.alibaba.json.bvt.parser.deser.deny.DenyTest9
        config.configFromPropety(properties);

        assertFalse(config.isAutoTypeSupport());
    }

    public void test_desktop() throws Exception {
        DenyTest11.Model model = new DenyTest11.Model();
        model.a = new DenyTest11.B();

            

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

                      assertFalse(config.isAutoTypeSupport());
    }

    public void test_desktop() throws Exception {
        DenyTest11.Model model = new DenyTest11.Model();
        model.a = new DenyTest11.B();
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.InitJavaBeanDeserializerTest$Model\"}";

        Exception error = null;

            

Reported by PMD.

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

Line: 28

                      assertFalse(config.isAutoTypeSupport());
    }

    public void test_desktop() throws Exception {
        DenyTest11.Model model = new DenyTest11.Model();
        model.a = new DenyTest11.B();
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.InitJavaBeanDeserializerTest$Model\"}";

        Exception error = null;

            

Reported by PMD.

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

Line: 36

                      Exception error = null;
        try {
            Object obj = JSON.parseObject(text, Object.class, config);
            System.out.println(obj.getClass());
        } catch (JSONException ex) {
            error = ex;
        }
        assertNotNull(error);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

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

        config.initJavaBeanDeserializers(Model.class);

        Object obj = JSON.parseObject(text, Object.class, config);
        assertEquals(Model.class, obj.getClass());

            

Reported by PMD.

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

Line: 45

                      config.initJavaBeanDeserializers(Model.class);

        Object obj = JSON.parseObject(text, Object.class, config);
        assertEquals(Model.class, obj.getClass());
    }

    public static class Model {

    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_3600/Issue3693.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: 16

              
public class Issue3693 extends TestCase {

    public void test_for_issue() throws Exception {
        Model<ModelProperties> model = new Model<ModelProperties>("hello 世界", new ModelProperties("红色", 66));
        String json = JSON.toJSONString(model);
        assertEquals("{\"name\":\"hello 世界\",\"properties\":\"{\\\"color\\\":\\\"红色\\\",\\\"size\\\":66}\"}", json);

        Model<ModelProperties> deserializedModel = JSON.parseObject(json, new TypeReference<Model<ModelProperties>>() {

            

Reported by PMD.

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

Line: 16

              
public class Issue3693 extends TestCase {

    public void test_for_issue() throws Exception {
        Model<ModelProperties> model = new Model<ModelProperties>("hello 世界", new ModelProperties("红色", 66));
        String json = JSON.toJSONString(model);
        assertEquals("{\"name\":\"hello 世界\",\"properties\":\"{\\\"color\\\":\\\"红色\\\",\\\"size\\\":66}\"}", json);

        Model<ModelProperties> deserializedModel = JSON.parseObject(json, new TypeReference<Model<ModelProperties>>() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                  public void test_for_issue() throws Exception {
        Model<ModelProperties> model = new Model<ModelProperties>("hello 世界", new ModelProperties("红色", 66));
        String json = JSON.toJSONString(model);
        assertEquals("{\"name\":\"hello 世界\",\"properties\":\"{\\\"color\\\":\\\"红色\\\",\\\"size\\\":66}\"}", json);

        Model<ModelProperties> deserializedModel = JSON.parseObject(json, new TypeReference<Model<ModelProperties>>() {
        });
        assertNotNull(deserializedModel);
        assertEquals("hello 世界", deserializedModel.getName());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

              
        Model<ModelProperties> deserializedModel = JSON.parseObject(json, new TypeReference<Model<ModelProperties>>() {
        });
        assertNotNull(deserializedModel);
        assertEquals("hello 世界", deserializedModel.getName());
        assertNotNull(deserializedModel.getProperties());
        assertEquals("红色", deserializedModel.getProperties().getColor());
        assertEquals(66, deserializedModel.getProperties().getSize());
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                      Model<ModelProperties> deserializedModel = JSON.parseObject(json, new TypeReference<Model<ModelProperties>>() {
        });
        assertNotNull(deserializedModel);
        assertEquals("hello 世界", deserializedModel.getName());
        assertNotNull(deserializedModel.getProperties());
        assertEquals("红色", deserializedModel.getProperties().getColor());
        assertEquals(66, deserializedModel.getProperties().getSize());
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                      });
        assertNotNull(deserializedModel);
        assertEquals("hello 世界", deserializedModel.getName());
        assertNotNull(deserializedModel.getProperties());
        assertEquals("红色", deserializedModel.getProperties().getColor());
        assertEquals(66, deserializedModel.getProperties().getSize());
    }



            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                      assertNotNull(deserializedModel);
        assertEquals("hello 世界", deserializedModel.getName());
        assertNotNull(deserializedModel.getProperties());
        assertEquals("红色", deserializedModel.getProperties().getColor());
        assertEquals(66, deserializedModel.getProperties().getSize());
    }


    static class Model<T> {

            

Reported by PMD.

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

Line: 26

                      assertNotNull(deserializedModel);
        assertEquals("hello 世界", deserializedModel.getName());
        assertNotNull(deserializedModel.getProperties());
        assertEquals("红色", deserializedModel.getProperties().getColor());
        assertEquals(66, deserializedModel.getProperties().getSize());
    }


    static class Model<T> {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

                      assertEquals("hello 世界", deserializedModel.getName());
        assertNotNull(deserializedModel.getProperties());
        assertEquals("红色", deserializedModel.getProperties().getColor());
        assertEquals(66, deserializedModel.getProperties().getSize());
    }


    static class Model<T> {
        private String name;

            

Reported by PMD.

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

Line: 27

                      assertEquals("hello 世界", deserializedModel.getName());
        assertNotNull(deserializedModel.getProperties());
        assertEquals("红色", deserializedModel.getProperties().getColor());
        assertEquals(66, deserializedModel.getProperties().getSize());
    }


    static class Model<T> {
        private String name;

            

Reported by PMD.

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

Line: 26

                      
        String text = JSON.toJSONString(entity);
        
        System.out.println(text);
        
        Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());

            

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

    public void test_0() throws Exception {
        Entity entity = new Entity();
        
        entity.setId(11);
        entity.setName("xx");
        

            

Reported by PMD.

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

Line: 22

                      Queue q = new Queue();
        q.setId(55);
        
        entity.getQueue().put(q.getId(), q);
        
        String text = JSON.toJSONString(entity);
        
        System.out.println(text);
        

            

Reported by PMD.

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

Line: 30

                      
        Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

            

Reported by PMD.

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

Line: 31

                      Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 31

                      Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 32

                      
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

        private int                 id;

            

Reported by PMD.

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

Line: 32

                      
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

        private int                 id;

            

Reported by PMD.

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

Line: 32

                      
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

        private int                 id;

            

Reported by PMD.

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

Line: 32

                      
        Assert.assertNotNull(entity2.getQueue());
        Assert.assertEquals(1, entity2.getQueue().size());
        Assert.assertEquals(true, entity2.getQueue().values().iterator().next() instanceof Queue);
    }

    public static class Entity {

        private int                 id;

            

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/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/TestExternal4.java
12 issues
System.out.println is used
Design

Line: 37

              
        {
            String text = JSON.toJSONString(obj);
            System.out.println(text);
        }

        String text = JSON.toJSONString(obj, SerializerFeature.WriteClassName);
        System.out.println(text);
        JSON.parseObject(text, clazz, confg);

            

Reported by PMD.

System.out.println is used
Design

Line: 41

                      }

        String text = JSON.toJSONString(obj, SerializerFeature.WriteClassName);
        System.out.println(text);
        JSON.parseObject(text, clazz, confg);
        String clazzName = JSON.parse(text, confg).getClass().getName();
        Assert.assertEquals(clazz.getName(), clazzName);
    }


            

Reported by PMD.

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

Line: 20

              import com.alibaba.fastjson.serializer.SerializerFeature;

public class TestExternal4 extends TestCase {
    ParserConfig confg = ParserConfig.global;
    protected void setUp() throws Exception {
        confg.addAccept("external.VO2");
    }

    public void test_0() throws Exception {

            

Reported by PMD.

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

Line: 21

              
public class TestExternal4 extends TestCase {
    ParserConfig confg = ParserConfig.global;
    protected void setUp() throws Exception {
        confg.addAccept("external.VO2");
    }

    public void test_0() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();

            

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

                      confg.addAccept("external.VO2");
    }

    public void test_0() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        Class<?> clazz = classLoader.loadClass("external.VO2");
        Method method = clazz.getMethod("setName", new Class[] { String.class });
        Method methodSetValue = clazz.getMethod("setValue", new Class[] { Serializable.class });


            

Reported by PMD.

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

Line: 31

                      Method method = clazz.getMethod("setName", new Class[] { String.class });
        Method methodSetValue = clazz.getMethod("setValue", new Class[] { Serializable.class });

        Object obj = clazz.newInstance();
        method.invoke(obj, "jobs");
        methodSetValue.invoke(obj, obj);

        {
            String text = JSON.toJSONString(obj);

            

Reported by PMD.

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

Line: 43

                      String text = JSON.toJSONString(obj, SerializerFeature.WriteClassName);
        System.out.println(text);
        JSON.parseObject(text, clazz, confg);
        String clazzName = JSON.parse(text, confg).getClass().getName();
        Assert.assertEquals(clazz.getName(), clazzName);
    }

    public static class ExtClassLoader extends ClassLoader {


            

Reported by PMD.

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

Line: 43

                      String text = JSON.toJSONString(obj, SerializerFeature.WriteClassName);
        System.out.println(text);
        JSON.parseObject(text, clazz, confg);
        String clazzName = JSON.parse(text, confg).getClass().getName();
        Assert.assertEquals(clazz.getName(), clazzName);
    }

    public static class ExtClassLoader extends ClassLoader {


            

Reported by PMD.

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

Line: 44

                      System.out.println(text);
        JSON.parseObject(text, clazz, confg);
        String clazzName = JSON.parse(text, confg).getClass().getName();
        Assert.assertEquals(clazz.getName(), clazzName);
    }

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

              
            {
                byte[] bytes;
                InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("external/VO2.clazz");
                bytes = IOUtils.toByteArray(is);
                is.close();
                
                super.defineClass("external.VO2", bytes, 0, bytes.length);
            }

            

Reported by PMD.

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

Line: 13

              import static com.alibaba.fastjson.serializer.SerializerFeature.BrowserCompatible;

public class Issue1764_bean_biginteger extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L), BrowserCompatible));

        assertEquals("{\"value\":\"-9007199254741992\"}"

            

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

              import static com.alibaba.fastjson.serializer.SerializerFeature.BrowserCompatible;

public class Issue1764_bean_biginteger extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L), BrowserCompatible));

        assertEquals("{\"value\":\"-9007199254741992\"}"

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

              
public class Issue1764_bean_biginteger extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L), BrowserCompatible));

        assertEquals("{\"value\":\"-9007199254741992\"}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                              , JSON.toJSONString(
                        new Model(9007199254741992L), BrowserCompatible));

        assertEquals("{\"value\":\"-9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(-9007199254741992L), BrowserCompatible));

        assertEquals("{\"value\":9007199254740990}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                              , JSON.toJSONString(
                        new Model(-9007199254741992L), BrowserCompatible));

        assertEquals("{\"value\":9007199254740990}"
                , JSON.toJSONString(
                        new Model(9007199254740990L), BrowserCompatible));

        assertEquals("{\"value\":-9007199254740990}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                              , JSON.toJSONString(
                        new Model(9007199254740990L), BrowserCompatible));

        assertEquals("{\"value\":-9007199254740990}"
                , JSON.toJSONString(
                        new Model(-9007199254740990L), BrowserCompatible));

        assertEquals("{\"value\":100}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 30

                              , JSON.toJSONString(
                        new Model(-9007199254740990L), BrowserCompatible));

        assertEquals("{\"value\":100}"
                , JSON.toJSONString(
                        new Model(100), BrowserCompatible));

        assertEquals("{\"value\":-100}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

                              , JSON.toJSONString(
                        new Model(100), BrowserCompatible));

        assertEquals("{\"value\":-100}"
                , JSON.toJSONString(
                        new Model(-100), BrowserCompatible));
    }



            

Reported by PMD.

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

Line: 43

              

    public static class Model {
        public BigInteger value;

        public Model() {

        }


            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.annotation.JSONField'
Design

Line: 4

              package com.alibaba.json.bvt.issue_1700;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.math.BigInteger;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_colon.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: 17

               */
public class JSONScannerTest_colon extends TestCase {

    public void test_0() throws Exception {
        JSONScanner lexer = new JSONScanner(":true");
        lexer.nextTokenWithColon();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_1() throws Exception {
        JSONScanner lexer = new JSONScanner(" : true");
        lexer.nextTokenWithColon();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_2() throws Exception {
        JSONScanner lexer = new JSONScanner("\n:\ntrue");
        lexer.nextTokenWithColon();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

Reported by PMD.

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

Line: 35

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_3() throws Exception {
        JSONScanner lexer = new JSONScanner("\r:\rtrue");
        lexer.nextTokenWithColon();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_4() throws Exception {
        JSONScanner lexer = new JSONScanner("\t:\ttrue");
        lexer.nextTokenWithColon();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_5() throws Exception {
        JSONScanner lexer = new JSONScanner("\t:\ftrue");
        lexer.nextTokenWithColon();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_6() throws Exception {
        JSONScanner lexer = new JSONScanner("\b:\btrue");
        lexer.nextTokenWithColon();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_f() throws Exception {
        JSONScanner lexer = new JSONScanner("\f:\btrue");
        lexer.nextTokenWithColon();
        Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }


            

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

                      Assert.assertEquals(JSONToken.TRUE, lexer.token());
    }

    public void test_7() throws Exception {
        JSONException error = null;
        try {
            JSONScanner lexer = new JSONScanner("true");
            lexer.nextTokenWithColon();
        } catch (JSONException e) {

            

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

                      Assert.assertNotNull(error);
    }

    public void test_8() throws Exception {
        JSONScanner lexer = new JSONScanner("\b:\btrue");
        lexer.nextToken();
        Assert.assertEquals(JSONToken.COLON, lexer.token());
    }
}

            

Reported by PMD.