The following issues were found

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

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

        JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        

            

Reported by PMD.

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

Line: 23

                      JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        
        Assert.assertEquals(3, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
    }

    public void test_null() throws Exception {

            

Reported by PMD.

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

Line: 24

                      Model model = reader.readObject(Model.class);
        
        Assert.assertEquals(3, model.values.size());
        Assert.assertTrue(model.values.contains("a"));
        Assert.assertTrue(model.values.contains("b"));
    }

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

            

Reported by PMD.

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

Line: 25

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

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

            

Reported by PMD.

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

Line: 28

                      Assert.assertTrue(model.values.contains("b"));
    }

    public void test_null() throws Exception {
        String text = "{\"values\":null}";
        JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertNull(model.values);
    }

            

Reported by PMD.

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

Line: 35

                      Assert.assertNull(model.values);
    }

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

            

Reported by PMD.

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

Line: 39

                      String text = "{\"values\":[]}";
        JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertEquals(0, model.values.size());
    }

    public void test_map_empty() throws Exception {
        String text = "{\"model\":{\"values\":[]}}";
        JSONReader reader = new JSONReader(new StringReader(text));

            

Reported by PMD.

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

Line: 42

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

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

            

Reported by PMD.

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

Line: 48

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

    public void test_notMatch() throws Exception {
        String text = "{\"value\":[]}";
        JSONReader reader = new JSONReader(new StringReader(text));

            

Reported by PMD.

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

Line: 51

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

    public void test_notMatch() throws Exception {
        String text = "{\"value\":[]}";
        JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertNull(model.values);
    }

            

Reported by PMD.

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

Line: 10

              import java.util.List;

public class Issue1570 extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }


            

Reported by PMD.

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

Line: 10

              import java.util.List;

public class Issue1570 extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

              public class Issue1570 extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }

    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

                  public void test_for_issue() throws Exception {
        Model model = new Model();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }

    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));

            

Reported by PMD.

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

Line: 16

                      assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }

    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }


            

Reported by PMD.

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

Line: 16

                      assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }

    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }

    public void test_for_issue_long() throws Exception {
        ModelLong model = new ModelLong();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                  public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }

    public void test_for_issue_long() throws Exception {
        ModelLong model = new ModelLong();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));

            

Reported by PMD.

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

Line: 22

                      assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }

    public void test_for_issue_long() throws Exception {
        ModelLong model = new ModelLong();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }


            

Reported by PMD.

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

Line: 22

                      assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }

    public void test_for_issue_long() throws Exception {
        ModelLong model = new ModelLong();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }


            

Reported by PMD.

src/main/java/com/alibaba/fastjson/support/jaxrs/FastJsonProvider.java
20 issues
The class 'FastJsonProvider' is suspected to be a Data Class (WOC=31.579%, NOPA=2, NOAM=10, WMC=44)
Design

Line: 36

              @Provider
@Consumes({MediaType.WILDCARD})
@Produces({MediaType.WILDCARD})
public class FastJsonProvider //
        implements MessageBodyReader<Object>, MessageBodyWriter<Object> {

    /**
     * These are classes that we never use for reading
     * (never try to deserialize instances of these types).

            

Reported by PMD.

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

Line: 75

                   * serialization.
     */
    @Context
    protected Providers providers;

    /**
     * with fastJson config
     */
    private FastJsonConfig fastJsonConfig = new FastJsonConfig();

            

Reported by PMD.

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

Line: 85

                  /**
     * allow serialize/deserialize types in clazzes
     */
    private Class<?>[] clazzes = null;

    /**
     * whether set PrettyFormat while exec WriteTo()
     */
    private boolean pretty;

            

Reported by PMD.

Avoid using redundant field initializer for 'clazzes'
Performance

Line: 85

                  /**
     * allow serialize/deserialize types in clazzes
     */
    private Class<?>[] clazzes = null;

    /**
     * whether set PrettyFormat while exec WriteTo()
     */
    private boolean pretty;

            

Reported by PMD.

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

Line: 90

                  /**
     * whether set PrettyFormat while exec WriteTo()
     */
    private boolean pretty;


    /**
     * @return the fastJsonConfig.
     * @since 1.2.11

            

Reported by PMD.

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

Line: 119

                  /**
     * Only serialize/deserialize all types in clazzes.
     */
    public FastJsonProvider(Class<?>[] clazzes) {
        this.clazzes = clazzes;
    }

    /**
     * Set pretty format

            

Reported by PMD.

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

Line: 296

                          String subtype = mediaType.getSubtype();

            return (("json".equalsIgnoreCase(subtype)) //
                    || (subtype.endsWith("+json")) //
                    || ("javascript".equals(subtype)) //
                    || ("x-javascript".equals(subtype)) //
                    || ("x-json".equals(subtype)) //
                    || ("x-www-form-urlencoded".equalsIgnoreCase(subtype)) //
                    || (subtype.endsWith("x-www-form-urlencoded")));

            

Reported by PMD.

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

Line: 301

                                  || ("x-javascript".equals(subtype)) //
                    || ("x-json".equals(subtype)) //
                    || ("x-www-form-urlencoded".equalsIgnoreCase(subtype)) //
                    || (subtype.endsWith("x-www-form-urlencoded")));
        }
        return true;
    }

    /**

            

Reported by PMD.

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

Line: 350

              
        FastJsonConfig fastJsonConfig = locateConfigProvider(type, mediaType);

        SerializerFeature[] serializerFeatures = fastJsonConfig.getSerializerFeatures();

        if (pretty) {
            if (serializerFeatures == null)
                serializerFeatures = new SerializerFeature[]{SerializerFeature.PrettyFormat};
            else {

            

Reported by PMD.

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

Line: 414

                          FastJsonConfig fastJsonConfig = locateConfigProvider(type, mediaType);

            return JSON.parseObject(entityStream,
                    fastJsonConfig.getCharset(),
                    genericType,
                    fastJsonConfig.getParserConfig(),
                    fastJsonConfig.getParseProcess(),
                    JSON.DEFAULT_PARSER_FEATURE,
                    fastJsonConfig.getFeatures());

            

Reported by PMD.

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

Line: 10

              import java.util.List;

public class Issue1570_private extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }


            

Reported by PMD.

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

Line: 10

              import java.util.List;

public class Issue1570_private extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

              public class Issue1570_private extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }

    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

                  public void test_for_issue() throws Exception {
        Model model = new Model();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }

    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));

            

Reported by PMD.

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

Line: 16

                      assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }

    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }


            

Reported by PMD.

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

Line: 16

                      assertEquals("{\"value\":\"\"}", JSON.toJSONString(model, SerializerFeature.WriteNullStringAsEmpty));
    }

    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
    public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }

    public void test_for_issue_long() throws Exception {
        ModelLong model = new ModelLong();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                  public void test_for_issue_int() throws Exception {
        ModelInt model = new ModelInt();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }

    public void test_for_issue_long() throws Exception {
        ModelLong model = new ModelLong();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));

            

Reported by PMD.

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

Line: 22

                      assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }

    public void test_for_issue_long() throws Exception {
        ModelLong model = new ModelLong();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }


            

Reported by PMD.

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

Line: 22

                      assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }

    public void test_for_issue_long() throws Exception {
        ModelLong model = new ModelLong();
        assertEquals("{}", JSON.toJSONString(model, SerializerFeature.WriteNullBooleanAsFalse));
        assertEquals("{\"value\":0}", JSON.toJSONString(model, SerializerFeature.WriteNullNumberAsZero));
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/test/codec/Jackson2Codec.java
20 issues
Avoid throwing raw exception types.
Design

Line: 28

                      try {
            return mapper.readValue(text, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    

    public <T> T decodeObject(byte[] input, Class<T> clazz) throws Exception {

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 37

                      try {
            return mapper.readValue(input, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception {
        try {

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 46

                          return (Collection<T>) mapper.readValue(text, new TypeReference<T>() {
            });
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public final Object decodeObject(String text) {
        try {

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 54

                      try {
            return (ObjectNode) mapper.readTree(text);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public Object decode(String text) {
        try {

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 62

                      try {
            return mapper.readTree(text);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public String encode(Object object) throws Exception {
        return mapper.writeValueAsString(object);

            

Reported by PMD.

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

Line: 18

              
public class Jackson2Codec implements Codec {

    private ObjectMapper mapper = new ObjectMapper();

    public String getName() {
        return "jackson2";
    }


            

Reported by PMD.

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

Line: 18

              
public class Jackson2Codec implements Codec {

    private ObjectMapper mapper = new ObjectMapper();

    public String getName() {
        return "jackson2";
    }


            

Reported by PMD.

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

Line: 27

                  public final <T> T decodeObject(String text, Class<T> clazz) {
        try {
            return mapper.readValue(text, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    


            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 33

                  }
    

    public <T> T decodeObject(byte[] input, Class<T> clazz) throws Exception {
        try {
            return mapper.readValue(input, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }

            

Reported by PMD.

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

Line: 36

                  public <T> T decodeObject(byte[] input, Class<T> clazz) throws Exception {
        try {
            return mapper.readValue(input, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception {

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 16/01/2017.
 */
public class Issue998_private extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"items\":[{\"id\":123}]}", Model.class);
        assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 16/01/2017.
 */
public class Issue998_private extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"items\":[{\"id\":123}]}", Model.class);
        assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

              public class Issue998_private extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"items\":[{\"id\":123}]}", Model.class);
        assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

        String json = JSON.toJSONString(model, SerializerFeature.NotWriteRootClassName, SerializerFeature.WriteClassName);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                  public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"items\":[{\"id\":123}]}", Model.class);
        assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

        String json = JSON.toJSONString(model, SerializerFeature.NotWriteRootClassName, SerializerFeature.WriteClassName);
        assertEquals("{\"items\":[{\"id\":123}]}", json);

            

Reported by PMD.

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

Line: 18

                      Model model = JSON.parseObject("{\"items\":[{\"id\":123}]}", Model.class);
        assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

        String json = JSON.toJSONString(model, SerializerFeature.NotWriteRootClassName, SerializerFeature.WriteClassName);
        assertEquals("{\"items\":[{\"id\":123}]}", json);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      Model model = JSON.parseObject("{\"items\":[{\"id\":123}]}", Model.class);
        assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

        String json = JSON.toJSONString(model, SerializerFeature.NotWriteRootClassName, SerializerFeature.WriteClassName);
        assertEquals("{\"items\":[{\"id\":123}]}", json);
    }

            

Reported by PMD.

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

Line: 19

                      assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

        String json = JSON.toJSONString(model, SerializerFeature.NotWriteRootClassName, SerializerFeature.WriteClassName);
        assertEquals("{\"items\":[{\"id\":123}]}", json);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

        String json = JSON.toJSONString(model, SerializerFeature.NotWriteRootClassName, SerializerFeature.WriteClassName);
        assertEquals("{\"items\":[{\"id\":123}]}", json);
    }


            

Reported by PMD.

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

Line: 19

                      assertNotNull(model);
        assertNotNull(model.items);
        assertEquals(1, model.items.size());
        assertEquals(123, model.items.get(0).getId());

        String json = JSON.toJSONString(model, SerializerFeature.NotWriteRootClassName, SerializerFeature.WriteClassName);
        assertEquals("{\"items\":[{\"id\":123}]}", json);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      assertEquals(123, model.items.get(0).getId());

        String json = JSON.toJSONString(model, SerializerFeature.NotWriteRootClassName, SerializerFeature.WriteClassName);
        assertEquals("{\"items\":[{\"id\":123}]}", json);
    }

    public void test_for_issue_1() throws Exception {
        Field field = Model.class.getField("items");
        List<Item> items = (List<Item> ) JSON.parseObject("[{\"id\":123}]", field.getGenericType());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/SerializeWriterTest_8.java
20 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 SerializeWriterTest_8 extends TestCase {

    public void test_BrowserCompatible() throws Exception {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < 1024; ++i) {
            buf.append('a');
        }
        buf.append("中国");

            

Reported by PMD.

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

Line: 15

              
public class SerializeWriterTest_8 extends TestCase {

    public void test_BrowserCompatible() throws Exception {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < 1024; ++i) {
            buf.append('a');
        }
        buf.append("中国");

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 20

                      for (int i = 0; i < 1024; ++i) {
            buf.append('a');
        }
        buf.append("中国");
        buf.append("\0");
        JSON.toJSONString(buf.toString(), SerializerFeature.BrowserCompatible);
    }

    public void test_writer() throws Exception {

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called 2 consecutive times with literals. Use a single append with a single combined String.
Performance

Line: 20

                      for (int i = 0; i < 1024; ++i) {
            buf.append('a');
        }
        buf.append("中国");
        buf.append("\0");
        JSON.toJSONString(buf.toString(), SerializerFeature.BrowserCompatible);
    }

    public void test_writer() throws Exception {

            

Reported by PMD.

Avoid appending characters as strings in StringBuffer.append.
Performance

Line: 21

                          buf.append('a');
        }
        buf.append("中国");
        buf.append("\0");
        JSON.toJSONString(buf.toString(), SerializerFeature.BrowserCompatible);
    }

    public void test_writer() throws Exception {
        StringBuilder buf = new StringBuilder();

            

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

                      JSON.toJSONString(buf.toString(), SerializerFeature.BrowserCompatible);
    }

    public void test_writer() throws Exception {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < 1024; ++i) {
            buf.append('a');
        }
        buf.append("中国");

            

Reported by PMD.

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

Line: 25

                      JSON.toJSONString(buf.toString(), SerializerFeature.BrowserCompatible);
    }

    public void test_writer() throws Exception {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < 1024; ++i) {
            buf.append('a');
        }
        buf.append("中国");

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called 2 consecutive times with literals. Use a single append with a single combined String.
Performance

Line: 30

                      for (int i = 0; i < 1024; ++i) {
            buf.append('a');
        }
        buf.append("中国");
        buf.append("\0");

        StringWriter out = new StringWriter();
        JSON.writeJSONStringTo(buf.toString(), out, SerializerFeature.BrowserCompatible);
    }

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 30

                      for (int i = 0; i < 1024; ++i) {
            buf.append('a');
        }
        buf.append("中国");
        buf.append("\0");

        StringWriter out = new StringWriter();
        JSON.writeJSONStringTo(buf.toString(), out, SerializerFeature.BrowserCompatible);
    }

            

Reported by PMD.

Avoid appending characters as strings in StringBuffer.append.
Performance

Line: 31

                          buf.append('a');
        }
        buf.append("中国");
        buf.append("\0");

        StringWriter out = new StringWriter();
        JSON.writeJSONStringTo(buf.toString(), out, SerializerFeature.BrowserCompatible);
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/NotWriteDefaultValueTest_NoneASM.java
20 issues
Do not use the short type
Performance

Line: 80

              
    private static class VO_Short {

        private short f0;
        private short f1;

        public short getF0() {
            return f0;
        }

            

Reported by PMD.

Do not use the short type
Performance

Line: 81

                  private static class VO_Short {

        private short f0;
        private short f1;

        public short getF0() {
            return f0;
        }


            

Reported by PMD.

Do not use the short type
Performance

Line: 83

                      private short f0;
        private short f1;

        public short getF0() {
            return f0;
        }

        public void setF0(short f0) {
            this.f0 = f0;

            

Reported by PMD.

Do not use the short type
Performance

Line: 87

                          return f0;
        }

        public void setF0(short f0) {
            this.f0 = f0;
        }

        public short getF1() {
            return f1;

            

Reported by PMD.

Do not use the short type
Performance

Line: 91

                          this.f0 = f0;
        }

        public short getF1() {
            return f1;
        }

        public void setF1(short f1) {
            this.f1 = f1;

            

Reported by PMD.

Do not use the short type
Performance

Line: 95

                          return f1;
        }

        public void setF1(short f1) {
            this.f1 = f1;
        }

    }


            

Reported by PMD.

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

Line: 12

              
public class NotWriteDefaultValueTest_NoneASM extends TestCase {

    public void test_for_byte() throws Exception {
        VO_Byte vo = new VO_Byte();
        String text = JSON.toJSONString(vo, SerializerFeature.NotWriteDefaultValue);
        Assert.assertEquals("{}", text);
    }


            

Reported by PMD.

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

Line: 18

                      Assert.assertEquals("{}", text);
    }

    public void test_for_short() throws Exception {
        VO_Short vo = new VO_Short();
        String text = JSON.toJSONString(vo, SerializerFeature.NotWriteDefaultValue);
        Assert.assertEquals("{}", text);
    }


            

Reported by PMD.

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

Line: 24

                      Assert.assertEquals("{}", text);
    }

    public void test_for_int() throws Exception {
        VO_Int vo = new VO_Int();
        String text = JSON.toJSONString(vo, SerializerFeature.NotWriteDefaultValue);
        Assert.assertEquals("{}", text);
    }


            

Reported by PMD.

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

Line: 30

                      Assert.assertEquals("{}", text);
    }

    public void test_for_long() throws Exception {
        VO_Long vo = new VO_Long();
        String text = JSON.toJSONString(vo, SerializerFeature.NotWriteDefaultValue);
        Assert.assertEquals("{}", text);
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/DefaultJSONParserTest2.java
20 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 15

              
public class DefaultJSONParserTest2 extends TestCase {

    public void test_empty() throws Exception {
        String text = "";
        assertNull(JSON.parse(text));
        assertNull(JSON.parseObject(text));
        assertNull(JSON.parseObject(text, Object.class));
        assertNull(JSON.parseObject(text, Map.class));

            

Reported by PMD.

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

Line: 15

              
public class DefaultJSONParserTest2 extends TestCase {

    public void test_empty() throws Exception {
        String text = "";
        assertNull(JSON.parse(text));
        assertNull(JSON.parseObject(text));
        assertNull(JSON.parseObject(text, Object.class));
        assertNull(JSON.parseObject(text, Map.class));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              
    public void test_empty() throws Exception {
        String text = "";
        assertNull(JSON.parse(text));
        assertNull(JSON.parseObject(text));
        assertNull(JSON.parseObject(text, Object.class));
        assertNull(JSON.parseObject(text, Map.class));
        assertNull(JSON.parseObject(text, Entity.class));
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                  public void test_empty() throws Exception {
        String text = "";
        assertNull(JSON.parse(text));
        assertNull(JSON.parseObject(text));
        assertNull(JSON.parseObject(text, Object.class));
        assertNull(JSON.parseObject(text, Map.class));
        assertNull(JSON.parseObject(text, Entity.class));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      String text = "";
        assertNull(JSON.parse(text));
        assertNull(JSON.parseObject(text));
        assertNull(JSON.parseObject(text, Object.class));
        assertNull(JSON.parseObject(text, Map.class));
        assertNull(JSON.parseObject(text, Entity.class));
    }

    public static class Entity {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      assertNull(JSON.parse(text));
        assertNull(JSON.parseObject(text));
        assertNull(JSON.parseObject(text, Object.class));
        assertNull(JSON.parseObject(text, Map.class));
        assertNull(JSON.parseObject(text, Entity.class));
    }

    public static class Entity {


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      assertNull(JSON.parseObject(text));
        assertNull(JSON.parseObject(text, Object.class));
        assertNull(JSON.parseObject(text, Map.class));
        assertNull(JSON.parseObject(text, Entity.class));
    }

    public static class Entity {

    }

            

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

              
    }

    public void test_0() throws Exception {
        String text = "{}";
        Map map = (Map) JSON.parse(text);
        Assert.assertEquals(0, map.size());
    }


            

Reported by PMD.

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

Line: 31

                  public void test_0() throws Exception {
        String text = "{}";
        Map map = (Map) JSON.parse(text);
        Assert.assertEquals(0, map.size());
    }

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

            

Reported by PMD.

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

Line: 34

                      Assert.assertEquals(0, map.size());
    }

    public void test_1() throws Exception {
        JSONException error = null;
        try {
            String text = "{}a";
            Map map = (Map) JSON.parse(text);
            Assert.assertEquals(0, map.size());

            

Reported by PMD.

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

Line: 15

              
public class JSONReaderTest_object_int_unquote extends TestCase {

    String text = "{f0:0,f1:1,f2:2,f3:3,f4:4, " + //
                  "f5:5,f6:6,f7:7,f8:8,f9:9}";

    public void test_read() throws Exception {

        JSONReader reader = new JSONReader(new StringReader(text));

            

Reported by PMD.

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

Line: 18

                  String text = "{f0:0,f1:1,f2:2,f3:3,f4:4, " + //
                  "f5:5,f6:6,f7:7,f8:8,f9:9}";

    public void test_read() throws Exception {

        JSONReader reader = new JSONReader(new StringReader(text));
        reader.startObject();

        int count = 0;

            

Reported by PMD.

Avoid unused local variables such as 'key'.
Design

Line: 25

              
        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            Integer value = reader.readInteger();
            count++;
        }
        Assert.assertEquals(10, count);


            

Reported by PMD.

Avoid unused local variables such as 'value'.
Design

Line: 26

                      int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            Integer value = reader.readInteger();
            count++;
        }
        Assert.assertEquals(10, count);

        reader.endObject();

            

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

                      reader.close();
    }

    public void test_read_1() throws Exception {
        JSONReader reader = new JSONReader(new JSONScanner(text));
        reader.startObject();

        int count = 0;
        while (reader.hasNext()) {

            

Reported by PMD.

Avoid unused local variables such as 'key'.
Design

Line: 41

              
        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            Integer value = reader.readInteger();
            count++;
        }
        Assert.assertEquals(10, count);


            

Reported by PMD.

Avoid unused local variables such as 'value'.
Design

Line: 42

                      int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            Integer value = reader.readInteger();
            count++;
        }
        Assert.assertEquals(10, count);

        reader.endObject();

            

Reported by PMD.

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

Line: 10

              import org.junit.Assert;

import com.alibaba.fastjson.JSONReader;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.JSONScanner;

public class JSONReaderTest_object_int_unquote extends TestCase {

    String text = "{f0:0,f1:1,f2:2,f3:3,f4:4, " + //

            

Reported by PMD.

Found 'DD'-anomaly for variable 'count' (lines '23'-'27').
Error

Line: 23

                      JSONReader reader = new JSONReader(new StringReader(text));
        reader.startObject();

        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            Integer value = reader.readInteger();
            count++;
        }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'key' (lines '25'-'33').
Error

Line: 25

              
        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            Integer value = reader.readInteger();
            count++;
        }
        Assert.assertEquals(10, count);


            

Reported by PMD.