The following issues were found

src/main/java/com/alibaba/fastjson/JSONArray.java
15 issues
Do not use the short type
Performance

Line: 329

                      return castToShort(value);
    }

    public short getShortValue(int index) {
        Object value = get(index);

        Short shortVal = castToShort(value);
        if (shortVal == null) {
            return 0;

            

Reported by PMD.

Object clone() should be implemented with super.clone()
Error

Line: 461

                  }

    @Override
    public Object clone() {
        return new JSONArray(new ArrayList<Object>(list));
    }

    public boolean equals(Object obj) {
        return this.list.equals(obj);

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 16

               * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.fastjson;

import static com.alibaba.fastjson.util.TypeUtils.castToBigDecimal;
import static com.alibaba.fastjson.util.TypeUtils.castToBigInteger;
import static com.alibaba.fastjson.util.TypeUtils.castToBoolean;
import static com.alibaba.fastjson.util.TypeUtils.castToByte;

            

Reported by PMD.

The class 'JSONArray' has a total cyclomatic complexity of 94 (highest 7).
Design

Line: 46

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAccess, Serializable {

    private static final long  serialVersionUID = 1L;
    private final List<Object> list;
    protected transient Object relatedArray;
    protected transient Type   componentType;

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 46

              /**
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAccess, Serializable {

    private static final long  serialVersionUID = 1L;
    private final List<Object> list;
    protected transient Object relatedArray;
    protected transient Type   componentType;

            

Reported by PMD.

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

Line: 49

              public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAccess, Serializable {

    private static final long  serialVersionUID = 1L;
    private final List<Object> list;
    protected transient Object relatedArray;
    protected transient Type   componentType;

    public JSONArray(){
        this.list = new ArrayList<Object>();

            

Reported by PMD.

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

Line: 303

                          return false;
        }

        return castToBoolean(value).booleanValue();
    }

    public Byte getByte(int index) {
        Object value = get(index);


            

Reported by PMD.

The return type of the clone() method must be the class name when implements Cloneable
Error

Line: 461

                  }

    @Override
    public Object clone() {
        return new JSONArray(new ArrayList<Object>(list));
    }

    public boolean equals(Object obj) {
        return this.list.equals(obj);

            

Reported by PMD.

clone() method should throw CloneNotSupportedException
Error

Line: 461

                  }

    @Override
    public Object clone() {
        return new JSONArray(new ArrayList<Object>(list));
    }

    public boolean equals(Object obj) {
        return this.list.equals(obj);

            

Reported by PMD.

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

Line: 474

                  }

    private void readObject(final java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
        JSONObject.SecureObjectInputStream.ensureFields();
        if (JSONObject.SecureObjectInputStream.fields != null && !JSONObject.SecureObjectInputStream.fields_error) {
            ObjectInputStream secIn = new JSONObject.SecureObjectInputStream(in);
            try {
                secIn.defaultReadObject();
                return;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1200/Issue1226.java
15 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 16/05/2017.
 */
public class Issue1226 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"c\":\"c\"}";
        TestBean tb1 = JSON.parseObject(json, TestBean.class);
        assertEquals('c', tb1.getC());

        TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 16/05/2017.
 */
public class Issue1226 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"c\":\"c\"}";
        TestBean tb1 = JSON.parseObject(json, TestBean.class);
        assertEquals('c', tb1.getC());

        TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);

            

Reported by PMD.

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

Line: 15

                  public void test_for_issue() throws Exception {
        String json = "{\"c\":\"c\"}";
        TestBean tb1 = JSON.parseObject(json, TestBean.class);
        assertEquals('c', tb1.getC());

        TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);
        assertEquals('c', tb2.getC().charValue());

        String json2 = JSON.toJSONString(tb2);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                  public void test_for_issue() throws Exception {
        String json = "{\"c\":\"c\"}";
        TestBean tb1 = JSON.parseObject(json, TestBean.class);
        assertEquals('c', tb1.getC());

        TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);
        assertEquals('c', tb2.getC().charValue());

        String json2 = JSON.toJSONString(tb2);

            

Reported by PMD.

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

Line: 18

                      assertEquals('c', tb1.getC());

        TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);
        assertEquals('c', tb2.getC().charValue());

        String json2 = JSON.toJSONString(tb2);
        JSONObject jo = JSON.parseObject(json2);

        TestBean tb12 = jo.toJavaObject(TestBean.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      assertEquals('c', tb1.getC());

        TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);
        assertEquals('c', tb2.getC().charValue());

        String json2 = JSON.toJSONString(tb2);
        JSONObject jo = JSON.parseObject(json2);

        TestBean tb12 = jo.toJavaObject(TestBean.class);

            

Reported by PMD.

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

Line: 18

                      assertEquals('c', tb1.getC());

        TestBean2 tb2 = JSON.parseObject(json, TestBean2.class);
        assertEquals('c', tb2.getC().charValue());

        String json2 = JSON.toJSONString(tb2);
        JSONObject jo = JSON.parseObject(json2);

        TestBean tb12 = jo.toJavaObject(TestBean.class);

            

Reported by PMD.

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

Line: 23

                      String json2 = JSON.toJSONString(tb2);
        JSONObject jo = JSON.parseObject(json2);

        TestBean tb12 = jo.toJavaObject(TestBean.class);
        assertEquals('c', tb12.getC());

        TestBean2 tb22 = jo.toJavaObject(TestBean2.class);
        assertEquals('c', tb22.getC().charValue());
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                      JSONObject jo = JSON.parseObject(json2);

        TestBean tb12 = jo.toJavaObject(TestBean.class);
        assertEquals('c', tb12.getC());

        TestBean2 tb22 = jo.toJavaObject(TestBean2.class);
        assertEquals('c', tb22.getC().charValue());
    }


            

Reported by PMD.

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

Line: 24

                      JSONObject jo = JSON.parseObject(json2);

        TestBean tb12 = jo.toJavaObject(TestBean.class);
        assertEquals('c', tb12.getC());

        TestBean2 tb22 = jo.toJavaObject(TestBean2.class);
        assertEquals('c', tb22.getC().charValue());
    }


            

Reported by PMD.

src/main/java/com/alibaba/fastjson/support/spring/FastJsonJsonView.java
15 issues
Avoid using a branching statement as the last in a loop.
Error

Line: 381

                      if (extractValueFromSingleKeyModel) {
            if (result.size() == 1) {
                for (Map.Entry<String, Object> entry : result.entrySet()) {
                    return entry.getValue();
                }
            }
        }
        return result;
    }

            

Reported by PMD.

The class 'FastJsonJsonView' is suspected to be a Data Class (WOC=5.556%, NOPA=2, NOAM=16, WMC=38)
Design

Line: 33

               * @since 1.2.9
 */

public class FastJsonJsonView extends AbstractView {


    /**
     * default content type
     */

            

Reported by PMD.

Avoid unused private fields such as 'CALLBACK_PARAM_PATTERN'.
Design

Line: 49

                  /**
     * Pattern for validating jsonp callback parameter values.
     */
    private static final Pattern CALLBACK_PARAM_PATTERN = Pattern.compile("[0-9A-Za-z_\\.]*");

    @Deprecated
    protected Charset charset = Charset.forName("UTF-8");

    @Deprecated

            

Reported by PMD.

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

Line: 66

                  /**
     * renderedAttributes
     */
    private Set<String> renderedAttributes;

    /**
     * disableCaching
     */
    private boolean disableCaching = true;

            

Reported by PMD.

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

Line: 71

                  /**
     * disableCaching
     */
    private boolean disableCaching = true;

    /**
     * updateContentLength
     */
    private boolean updateContentLength = true;

            

Reported by PMD.

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

Line: 76

                  /**
     * updateContentLength
     */
    private boolean updateContentLength = true;

    /**
     * extractValueFromSingleKeyModel
     */
    private boolean extractValueFromSingleKeyModel = false;

            

Reported by PMD.

Avoid using redundant field initializer for 'extractValueFromSingleKeyModel'
Performance

Line: 81

                  /**
     * extractValueFromSingleKeyModel
     */
    private boolean extractValueFromSingleKeyModel = false;

    /**
     * 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: 91

                  /**
     * jsonp parameter name
     */
    private String[] jsonpParameterNames = {"jsonp", "callback"};

    /**
     * Set default param.
     */
    public FastJsonJsonView() {

            

Reported by PMD.

This call to Collection.toArray() may be optimizable
Performance

Line: 264

                   */
    public void setJsonpParameterNames(Set<String> jsonpParameterNames) {
        Assert.notEmpty(jsonpParameterNames, "jsonpParameterName cannot be empty");
        this.jsonpParameterNames = jsonpParameterNames.toArray(new String[jsonpParameterNames.size()]);
    }


    private String getJsonpParameterValue(HttpServletRequest request) {
        if (this.jsonpParameterNames != null) {

            

Reported by PMD.

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

Line: 318

                      ServletOutputStream out = response.getOutputStream();
        outnew.writeTo(out);
        outnew.close();
        out.flush();
    }

    @Override
    protected void prepareResponse(HttpServletRequest request, //
                                   HttpServletResponse response) {

            

Reported by PMD.

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

Line: 11

              
public class SerializeWriterTest_10 extends TestCase {

    public void test_erro_0() throws Exception {
        SerializeWriter out = new SerializeWriter();
        Exception error = null;
        try {
            out.write(new char[0], -1, 0);
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 16

                      Exception error = null;
        try {
            out.write(new char[0], -1, 0);
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        out.close();
    }

            

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

                      out.close();
    }

    public void test_erro_1() throws Exception {
        SerializeWriter out = new SerializeWriter();
        Exception error = null;
        try {
            out.write(new char[0], 1, 0);
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 28

                      Exception error = null;
        try {
            out.write(new char[0], 1, 0);
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        out.close();
    }

            

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

                      out.close();
    }

    public void test_erro_2() throws Exception {
        SerializeWriter out = new SerializeWriter();
        Exception error = null;
        try {
            out.write(new char[0], 0, -1);
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 40

                      Exception error = null;
        try {
            out.write(new char[0], 0, -1);
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        out.close();
    }

            

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

                      out.close();
    }

    public void test_erro_3() throws Exception {
        SerializeWriter out = new SerializeWriter();
        Exception error = null;
        try {
            out.write(new char[] { '0', '0' }, 1, 2);
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 52

                      Exception error = null;
        try {
            out.write(new char[] { '0', '0' }, 1, 2);
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        out.close();
    }

            

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

                      out.close();
    }
    
    public void test_erro_4() throws Exception {
        SerializeWriter out = new SerializeWriter();
        Exception error = null;
        try {
            out.write(new char[] { '0', '0' }, 1, Integer.MAX_VALUE);
        } catch (Exception ex) {

            

Reported by PMD.

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

Line: 64

                      Exception error = null;
        try {
            out.write(new char[] { '0', '0' }, 1, Integer.MAX_VALUE);
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        out.close();
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONLexerTest_set.java
14 issues
JUnit tests should include assert() or fail()
Design

Line: 11

              
public class JSONLexerTest_set extends TestCase {

    public void test_treeSet() throws Exception {
        JSON.parse("Set[]");
    }

    public void test_error() throws Exception {
        Exception error = null;

            

Reported by PMD.

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

Line: 11

              
public class JSONLexerTest_set extends TestCase {

    public void test_treeSet() throws Exception {
        JSON.parse("Set[]");
    }

    public void test_error() throws Exception {
        Exception error = null;

            

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

                      JSON.parse("Set[]");
    }

    public void test_error() throws Exception {
        Exception error = null;
        try {
            JSON.parse("S_t[]");
        } catch (Exception ex) {
            error = ex;

            

Reported by PMD.

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

Line: 19

                      Exception error = null;
        try {
            JSON.parse("S_t[]");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
   

            

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

                      Assert.assertNotNull(error);
    }
   
    public void test_error_1() throws Exception {
        Exception error = null;
        try {
            JSON.parse("Se_[]");
        } catch (Exception ex) {
            error = ex;

            

Reported by PMD.

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

Line: 29

                      Exception error = null;
        try {
            JSON.parse("Se_[]");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    

            

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

                  }
    
    
    public void test_error_2() throws Exception {
        Exception error = null;
        try {
            JSON.parse("Set_[]");
        } catch (Exception ex) {
            error = ex;

            

Reported by PMD.

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

Line: 40

                      Exception error = null;
        try {
            JSON.parse("Set_[]");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    

            

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

                      Assert.assertNotNull(error);
    }
    
    public void test_error_3() throws Exception {
        Exception error = null;
        try {
            JSON.parse("Xet[]");
        } catch (Exception ex) {
            error = ex;

            

Reported by PMD.

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

Line: 50

                      Exception error = null;
        try {
            JSON.parse("Xet[]");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest5.java
14 issues
System.out.println is used
Design

Line: 20

                      model.a = b;

        String str = JSON.toJSONString(model);
        System.out.println(str);
        assertEquals("{\"a\":{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest5$B\",\"id\":1001,\"value\":2017}}", str);

        Model model2 = JSON.parseObject(str, Model.class);
        assertTrue(model2.a instanceof B);
    }

            

Reported by PMD.

System.out.println is used
Design

Line: 34

                      model.a = a;

        String str = JSON.toJSONString(model);
        System.out.println(str);
        assertEquals("{\"a\":{\"id\":1001}}", str);

        Model model2 = JSON.parseObject(str, Model.class);
        assertSame(A.class, model2.a.getClass());
    }

            

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

               * Created by wenshao on 14/08/2017.
 */
public class WriteClassNameTest5 extends TestCase {
    public void test_for_writeClassName() throws Exception {
        Model model = new Model();
        B b = new B();
        b.id = 1001;
        b.value = 2017;
        model.a = b;

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 14/08/2017.
 */
public class WriteClassNameTest5 extends TestCase {
    public void test_for_writeClassName() throws Exception {
        Model model = new Model();
        B b = new B();
        b.id = 1001;
        b.value = 2017;
        model.a = b;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

              
        String str = JSON.toJSONString(model);
        System.out.println(str);
        assertEquals("{\"a\":{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest5$B\",\"id\":1001,\"value\":2017}}", str);

        Model model2 = JSON.parseObject(str, Model.class);
        assertTrue(model2.a instanceof B);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                      assertEquals("{\"a\":{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest5$B\",\"id\":1001,\"value\":2017}}", str);

        Model model2 = JSON.parseObject(str, Model.class);
        assertTrue(model2.a instanceof B);
    }

    public void test_for_writeClassName_no() throws Exception {
        Model model = new Model();
        A a = new A();

            

Reported by PMD.

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

Line: 27

                      assertTrue(model2.a instanceof B);
    }

    public void test_for_writeClassName_no() throws Exception {
        Model model = new Model();
        A a = new A();
        a.id = 1001;
        model.a = a;


            

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

                      assertTrue(model2.a instanceof B);
    }

    public void test_for_writeClassName_no() throws Exception {
        Model model = new Model();
        A a = new A();
        a.id = 1001;
        model.a = a;


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 35

              
        String str = JSON.toJSONString(model);
        System.out.println(str);
        assertEquals("{\"a\":{\"id\":1001}}", str);

        Model model2 = JSON.parseObject(str, Model.class);
        assertSame(A.class, model2.a.getClass());
    }


            

Reported by PMD.

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

Line: 38

                      assertEquals("{\"a\":{\"id\":1001}}", str);

        Model model2 = JSON.parseObject(str, Model.class);
        assertSame(A.class, model2.a.getClass());
    }

    public static class Model {
        @JSONField(serialzeFeatures = SerializerFeature.WriteClassName)
        public A a;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Set5.java
14 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 14

              
public class WriteClassNameTest_Set5 extends TestCase {

    public void test_list() throws Exception {
        Model model = new Model();
        LinkedHashSet tables = new LinkedHashSet();
        tables.add(new ExtTable(1001));
        tables.add(new Table());
        model.setTables(tables);

            

Reported by PMD.

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

Line: 14

              
public class WriteClassNameTest_Set5 extends TestCase {

    public void test_list() throws Exception {
        Model model = new Model();
        LinkedHashSet tables = new LinkedHashSet();
        tables.add(new ExtTable(1001));
        tables.add(new Table());
        model.setTables(tables);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      model.setTables(tables);

        String json = JSON.toJSONString(model);
        assertEquals("{\"tables\":[{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set5$ExtTable\",\"id\":1001},{}]}", json);

        Model model2 = JSON.parseObject(json, Model.class);
        assertEquals(ExtTable.class, model2.getTables().iterator().next().getClass());

        JSONObject jsonObject = JSON.parseObject(json, Feature.IgnoreAutoType);

            

Reported by PMD.

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

Line: 25

                      assertEquals("{\"tables\":[{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set5$ExtTable\",\"id\":1001},{}]}", json);

        Model model2 = JSON.parseObject(json, Model.class);
        assertEquals(ExtTable.class, model2.getTables().iterator().next().getClass());

        JSONObject jsonObject = JSON.parseObject(json, Feature.IgnoreAutoType);
        assertEquals("{\"tables\":[{\"id\":1001},{}]}", jsonObject.toJSONString());
    }


            

Reported by PMD.

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

Line: 25

                      assertEquals("{\"tables\":[{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set5$ExtTable\",\"id\":1001},{}]}", json);

        Model model2 = JSON.parseObject(json, Model.class);
        assertEquals(ExtTable.class, model2.getTables().iterator().next().getClass());

        JSONObject jsonObject = JSON.parseObject(json, Feature.IgnoreAutoType);
        assertEquals("{\"tables\":[{\"id\":1001},{}]}", jsonObject.toJSONString());
    }


            

Reported by PMD.

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

Line: 25

                      assertEquals("{\"tables\":[{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set5$ExtTable\",\"id\":1001},{}]}", json);

        Model model2 = JSON.parseObject(json, Model.class);
        assertEquals(ExtTable.class, model2.getTables().iterator().next().getClass());

        JSONObject jsonObject = JSON.parseObject(json, Feature.IgnoreAutoType);
        assertEquals("{\"tables\":[{\"id\":1001},{}]}", jsonObject.toJSONString());
    }


            

Reported by PMD.

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

Line: 25

                      assertEquals("{\"tables\":[{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set5$ExtTable\",\"id\":1001},{}]}", json);

        Model model2 = JSON.parseObject(json, Model.class);
        assertEquals(ExtTable.class, model2.getTables().iterator().next().getClass());

        JSONObject jsonObject = JSON.parseObject(json, Feature.IgnoreAutoType);
        assertEquals("{\"tables\":[{\"id\":1001},{}]}", jsonObject.toJSONString());
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                      assertEquals("{\"tables\":[{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set5$ExtTable\",\"id\":1001},{}]}", json);

        Model model2 = JSON.parseObject(json, Model.class);
        assertEquals(ExtTable.class, model2.getTables().iterator().next().getClass());

        JSONObject jsonObject = JSON.parseObject(json, Feature.IgnoreAutoType);
        assertEquals("{\"tables\":[{\"id\":1001},{}]}", jsonObject.toJSONString());
    }


            

Reported by PMD.

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

Line: 28

                      assertEquals(ExtTable.class, model2.getTables().iterator().next().getClass());

        JSONObject jsonObject = JSON.parseObject(json, Feature.IgnoreAutoType);
        assertEquals("{\"tables\":[{\"id\":1001},{}]}", jsonObject.toJSONString());
    }

    public static class Model {
        @JSONField(serialzeFeatures = SerializerFeature.WriteClassName)
        private LinkedHashSet<? extends Table> tables;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 28

                      assertEquals(ExtTable.class, model2.getTables().iterator().next().getClass());

        JSONObject jsonObject = JSON.parseObject(json, Feature.IgnoreAutoType);
        assertEquals("{\"tables\":[{\"id\":1001},{}]}", jsonObject.toJSONString());
    }

    public static class Model {
        @JSONField(serialzeFeatures = SerializerFeature.WriteClassName)
        private LinkedHashSet<? extends Table> tables;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/list/ArrayDeserializerTest.java
14 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 10

              
public class ArrayDeserializerTest extends TestCase {

    public void test_null() throws Exception {
        Assert.assertNull(JSON.parseObject("null", Object[].class));
        Assert.assertNull(JSON.parseObject("null", String[].class));
        Assert.assertNull(JSON.parseObject("null", VO[].class));
        Assert.assertNull(JSON.parseObject("null", VO[][].class));
    }

            

Reported by PMD.

The String literal 'null' appears 4 times in this file; the first occurrence is on line 11
Error

Line: 11

              public class ArrayDeserializerTest extends TestCase {

    public void test_null() throws Exception {
        Assert.assertNull(JSON.parseObject("null", Object[].class));
        Assert.assertNull(JSON.parseObject("null", String[].class));
        Assert.assertNull(JSON.parseObject("null", VO[].class));
        Assert.assertNull(JSON.parseObject("null", VO[][].class));
    }


            

Reported by PMD.

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

Line: 17

                      Assert.assertNull(JSON.parseObject("null", VO[][].class));
    }

    public void test_0() throws Exception {
        Assert.assertEquals(0, JSON.parseObject("[]", Object[].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][].class).length);

            

Reported by PMD.

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

Line: 18

                  }

    public void test_0() throws Exception {
        Assert.assertEquals(0, JSON.parseObject("[]", Object[].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[[[[[[]]]]]]", Object[][].class).length);

            

Reported by PMD.

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

Line: 19

              
    public void test_0() throws Exception {
        Assert.assertEquals(0, JSON.parseObject("[]", Object[].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[[[[[[]]]]]]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][][].class).length);

            

Reported by PMD.

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

Line: 20

                  public void test_0() throws Exception {
        Assert.assertEquals(0, JSON.parseObject("[]", Object[].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[[[[[[]]]]]]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][][].class).length);
        Assert.assertEquals(null, JSON.parseObject("{\"value\":null}", VO.class).getValue());

            

Reported by PMD.

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

Line: 21

                      Assert.assertEquals(0, JSON.parseObject("[]", Object[].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[[[[[[]]]]]]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][][].class).length);
        Assert.assertEquals(null, JSON.parseObject("{\"value\":null}", VO.class).getValue());
    }

            

Reported by PMD.

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

Line: 22

                      Assert.assertEquals(0, JSON.parseObject("[]", Object[][].class).length);
        Assert.assertEquals(0, JSON.parseObject("[]", Object[][][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[[[[[[]]]]]]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][][].class).length);
        Assert.assertEquals(null, JSON.parseObject("{\"value\":null}", VO.class).getValue());
    }


            

Reported by PMD.

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

Line: 23

                      Assert.assertEquals(0, JSON.parseObject("[]", Object[][][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[[[[[[]]]]]]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][][].class).length);
        Assert.assertEquals(null, JSON.parseObject("{\"value\":null}", VO.class).getValue());
    }

    public static class VO {

            

Reported by PMD.

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

Line: 24

                      Assert.assertEquals(1, JSON.parseObject("[null]", Object[].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[[[[[[]]]]]]", Object[][].class).length);
        Assert.assertEquals(1, JSON.parseObject("[null]", Object[][][].class).length);
        Assert.assertEquals(null, JSON.parseObject("{\"value\":null}", VO.class).getValue());
    }

    public static class VO {


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1100/Issue969.java
14 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 08/05/2017.
 */
public class Issue969 extends TestCase {
    public void test_for_issue() throws Exception {
        JSONObject jsonObject = new JSONObject();

        JSONArray jsonArray = new JSONArray();
        jsonArray.add(new Model());
        jsonObject.put("models", jsonArray);

            

Reported by PMD.

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

Line: 17

               * Created by wenshao on 08/05/2017.
 */
public class Issue969 extends TestCase {
    public void test_for_issue() throws Exception {
        JSONObject jsonObject = new JSONObject();

        JSONArray jsonArray = new JSONArray();
        jsonArray.add(new Model());
        jsonObject.put("models", jsonArray);

            

Reported by PMD.

The String literal 'models' appears 4 times in this file; the first occurrence is on line 22
Error

Line: 22

              
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(new Model());
        jsonObject.put("models", jsonArray);

        List list = jsonObject.getObject("models", new TypeReference<List<Model>>(){});

        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

              
        List list = jsonObject.getObject("models", new TypeReference<List<Model>>(){});

        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());
    }

    public void test_for_issue_1() throws Exception {
        JSONObject jsonObject = new JSONObject();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

                      List list = jsonObject.getObject("models", new TypeReference<List<Model>>(){});

        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());
    }

    public void test_for_issue_1() throws Exception {
        JSONObject jsonObject = new JSONObject();


            

Reported by PMD.

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

Line: 27

                      List list = jsonObject.getObject("models", new TypeReference<List<Model>>(){});

        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());
    }

    public void test_for_issue_1() throws Exception {
        JSONObject jsonObject = new JSONObject();


            

Reported by PMD.

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

Line: 30

                      assertEquals(Model.class, list.get(0).getClass());
    }

    public void test_for_issue_1() throws Exception {
        JSONObject jsonObject = new JSONObject();

        JSONArray jsonArray = new JSONArray();
        jsonArray.add(new Model());
        jsonObject.put("models", jsonArray);

            

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

                      assertEquals(Model.class, list.get(0).getClass());
    }

    public void test_for_issue_1() throws Exception {
        JSONObject jsonObject = new JSONObject();

        JSONArray jsonArray = new JSONArray();
        jsonArray.add(new Model());
        jsonObject.put("models", jsonArray);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

              
        List list = jsonObject.getObject("models", new TypeReference<List<Model>>(){}.getType());

        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());
    }

    public static class Model {


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

                      List list = jsonObject.getObject("models", new TypeReference<List<Model>>(){}.getType());

        assertEquals(1, list.size());
        assertEquals(Model.class, list.get(0).getClass());
    }

    public static class Model {

    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/TypeUtils_parseFloat_Test.java
14 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: 9

              import java.util.Random;

public class TypeUtils_parseFloat_Test extends TestCase {
    public void test_0() throws Exception {
        Random r = new Random();

        for (int i = 0; i < 1000 * 1000; ++i) {
            String str = Float.toString(r.nextFloat());
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

              
        for (int i = 0; i < 1000 * 1000; ++i) {
            String str = Float.toString(r.nextFloat());
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));
        }
    }

    public void test_1() throws Exception {
        Random r = new Random();

            

Reported by PMD.

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

Line: 18

                      }
    }

    public void test_1() throws Exception {
        Random r = new Random();

        for (int i = 0; i < 1000 * 1000; ++i) {
            String str = Integer.toString(r.nextInt());
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

              
        for (int i = 0; i < 1000 * 1000; ++i) {
            String str = Integer.toString(r.nextInt());
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));
        }
    }

    public void test_2() throws Exception {
        Random r = new Random();

            

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

                      }
    }

    public void test_2() throws Exception {
        Random r = new Random();

        for (int i = 0; i < 1000 * 1000; ++i) {
            String str = Integer.toString(r.nextInt(1000000000));
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 32

              
        for (int i = 0; i < 1000 * 1000; ++i) {
            String str = Integer.toString(r.nextInt(1000000000));
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));
        }
    }

    public void test_3() throws Exception {
        Random r = new Random();

            

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

                      }
    }

    public void test_3() throws Exception {
        Random r = new Random();

        for (int i = 0; i < 1000 * 1000; ++i) {
            String str = Long.toString(r.nextLong());
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 41

              
        for (int i = 0; i < 1000 * 1000; ++i) {
            String str = Long.toString(r.nextLong());
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));
        }
    }

    public void test_4() throws Exception {
        String[] array = new String[] {

            

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

                      }
    }

    public void test_4() throws Exception {
        String[] array = new String[] {
                "0.34856254",
                "1",
                "12",
                "123",

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 82

                      };

        for (String str : array) {
            assertEquals(Float.parseFloat(str), TypeUtils.parseFloat(str));
        }
    }
}

            

Reported by PMD.