The following issues were found

src/test/java/com/alibaba/json/bvt/parser/JSONReaderScannerTest_error4.java
4 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

              
public class JSONReaderScannerTest_error4 extends TestCase {

    public void test_e() throws Exception {
        Exception error = null;
        try {
            StringBuilder buf = new StringBuilder();
            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {

            

Reported by PMD.

StringBuffer constructor is initialized with size 16, but has at least 17 characters appended.
Performance

Line: 17

                  public void test_e() throws Exception {
        Exception error = null;
        try {
            StringBuilder buf = new StringBuilder();
            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {
                buf.append('A');
            }
            buf.append("\\t");

            

Reported by PMD.

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

Line: 26

                          JSONReader reader = new JSONReader(new MyReader(buf.toString()));
            reader.readObject();
            reader.close();
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '15'-'27').
Error

Line: 15

              public class JSONReaderScannerTest_error4 extends TestCase {

    public void test_e() throws Exception {
        Exception error = null;
        try {
            StringBuilder buf = new StringBuilder();
            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {
                buf.append('A');

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONReaderScannerTest_error5.java
4 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

              
public class JSONReaderScannerTest_error5 extends TestCase {

    public void test_e() throws Exception {
        Exception error = null;
        try {
            StringBuilder buf = new StringBuilder();
            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {

            

Reported by PMD.

StringBuffer constructor is initialized with size 16, but has at least 17 characters appended.
Performance

Line: 17

                  public void test_e() throws Exception {
        Exception error = null;
        try {
            StringBuilder buf = new StringBuilder();
            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {
                buf.append('A');
            }
            buf.append("\\t");

            

Reported by PMD.

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

Line: 26

                          JSONReader reader = new JSONReader(new MyReader(buf.toString()));
            reader.readObject();
            reader.close();
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '15'-'27').
Error

Line: 15

              public class JSONReaderScannerTest_error5 extends TestCase {

    public void test_e() throws Exception {
        Exception error = null;
        try {
            StringBuilder buf = new StringBuilder();
            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {
                buf.append('A');

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1100/Issue1121.java
4 issues
System.out.println is used
Design

Line: 23

                      result.put("admin",userObject);

        String json = JSON.toJSONString(result, true);
        System.out.println(json);

        JSONObject jsonObject2 = JSON.parseObject(json);
        assertEquals(result, jsonObject2);
    }
}

            

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

               * Created by wenshao on 01/04/2017.
 */
public class Issue1121 extends TestCase {
    public void test_for_issue() throws Exception {
        JSONObject userObject = new JSONObject();
        userObject.put("name","jack");
        userObject.put("age",20);

        JSONObject result = new JSONObject();

            

Reported by PMD.

Do not hard code the IP address
Design

Line: 17

                      userObject.put("age",20);

        JSONObject result = new JSONObject();
        result.put("host","127.0.0.1");
        result.put("port",3306);
        result.put("user",userObject);
        result.put("admin",userObject);

        String json = JSON.toJSONString(result, true);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                      System.out.println(json);

        JSONObject jsonObject2 = JSON.parseObject(json);
        assertEquals(result, jsonObject2);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONReader_top.java
4 issues
Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 16

                  public void test_int() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("123"));

        Assert.assertEquals(new Integer(123), reader.readInteger());

        reader.close();
    }

    public void test_long() throws Exception {

            

Reported by PMD.

Avoid instantiating Long objects.Call Long.valueOf() instead
Performance

Line: 24

                  public void test_long() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("123"));

        Assert.assertEquals(new Long(123), reader.readLong());

        reader.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: 13

              
public class JSONReader_top extends TestCase {

    public void test_int() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("123"));

        Assert.assertEquals(new Integer(123), reader.readInteger());

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

                      reader.close();
    }

    public void test_long() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("123"));

        Assert.assertEquals(new Long(123), reader.readLong());

        reader.close();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_ISO8601.java
4 issues
The method 'test_0()' has a NCSS line count of 94.
Design

Line: 12

              
public class JSONScannerTest_ISO8601 extends TestCase {

    public void test_0() throws Exception {
        Assert.assertEquals(false, new JSONScanner("1").scanISO8601DateIfMatch());
        Assert.assertEquals(false, new JSONScanner("2").scanISO8601DateIfMatch());
        Assert.assertEquals(false, new JSONScanner("3").scanISO8601DateIfMatch());
        Assert.assertEquals(true, new JSONScanner("3000-10-02").scanISO8601DateIfMatch());
        Assert.assertEquals(true, new JSONScanner("4000-10-02").scanISO8601DateIfMatch());

            

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

    public void test_0() throws Exception {
        Assert.assertEquals(false, new JSONScanner("1").scanISO8601DateIfMatch());
        Assert.assertEquals(false, new JSONScanner("2").scanISO8601DateIfMatch());
        Assert.assertEquals(false, new JSONScanner("3").scanISO8601DateIfMatch());
        Assert.assertEquals(true, new JSONScanner("3000-10-02").scanISO8601DateIfMatch());
        Assert.assertEquals(true, new JSONScanner("4000-10-02").scanISO8601DateIfMatch());

            

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

                      Assert.assertEquals(false, new JSONScanner("2000-02-10T00:00:00.00a").scanISO8601DateIfMatch());
    }

    public void test_2() throws Exception {
        JSONScanner lexer = new JSONScanner("2000-02-10T00:00:00.000");
        lexer.config(Feature.AllowISO8601DateFormat, true);
        Assert.assertEquals(true, lexer.scanISO8601DateIfMatch());
        Assert.assertEquals(JSONToken.LITERAL_ISO8601_DATE, lexer.token());
        lexer.nextToken();

            

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

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

    public void test_3() throws Exception {
        JSONScanner lexer = new JSONScanner("2000-2");
        lexer.config(Feature.AllowISO8601DateFormat, true);
        lexer.nextToken();
        Assert.assertEquals(JSONToken.LITERAL_INT, lexer.token());
        lexer.nextToken();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest__x.java
4 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 JSONScannerTest__x extends TestCase {

    public void test_x() throws Exception {
        StringBuilder buf = new StringBuilder();
        buf.append("\"");
        for (int i = 0; i < 16; ++i) {
            for (int j = 0; j < 16; ++j) {
                buf.append("\\x");

            

Reported by PMD.

Avoid appending characters as strings in StringBuffer.append.
Performance

Line: 12

              
    public void test_x() throws Exception {
        StringBuilder buf = new StringBuilder();
        buf.append("\"");
        for (int i = 0; i < 16; ++i) {
            for (int j = 0; j < 16; ++j) {
                buf.append("\\x");
                buf.append(Integer.toHexString(i));
                buf.append(Integer.toHexString(j));

            

Reported by PMD.

Avoid appending characters as strings in StringBuffer.append.
Performance

Line: 20

                              buf.append(Integer.toHexString(j));
            }
        }
        buf.append("\"");
        String jsonString = (String) JSON.parse(buf.toString());
        Assert.assertEquals(16 * 16, jsonString.length());
        for (int i = 0; i < 16 * 16; ++i) {
            char c = jsonString.charAt(i);
            if ((int) c != i) {

            

Reported by PMD.

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

Line: 22

                      }
        buf.append("\"");
        String jsonString = (String) JSON.parse(buf.toString());
        Assert.assertEquals(16 * 16, jsonString.length());
        for (int i = 0; i < 16 * 16; ++i) {
            char c = jsonString.charAt(i);
            if ((int) c != i) {
                Assert.fail();
            }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1000/Issue1095.java
4 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 22/03/2017.
 */
public class Issue1095 extends TestCase {
    public void test_for_issue() throws Exception {
        String text = "{\"Grade\": 1, \"UpdateTime\": \"2017-03-22T11:41:17\"}";
        JSONObject jsonObject = JSON.parseObject(text, Feature.AllowISO8601DateFormat);
        assertEquals(Date.class, jsonObject.get("UpdateTime").getClass());
    }
}

            

Reported by PMD.

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

Line: 17

                  public void test_for_issue() throws Exception {
        String text = "{\"Grade\": 1, \"UpdateTime\": \"2017-03-22T11:41:17\"}";
        JSONObject jsonObject = JSON.parseObject(text, Feature.AllowISO8601DateFormat);
        assertEquals(Date.class, jsonObject.get("UpdateTime").getClass());
    }
}

            

Reported by PMD.

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

Line: 17

                  public void test_for_issue() throws Exception {
        String text = "{\"Grade\": 1, \"UpdateTime\": \"2017-03-22T11:41:17\"}";
        JSONObject jsonObject = JSON.parseObject(text, Feature.AllowISO8601DateFormat);
        assertEquals(Date.class, jsonObject.get("UpdateTime").getClass());
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                  public void test_for_issue() throws Exception {
        String text = "{\"Grade\": 1, \"UpdateTime\": \"2017-03-22T11:41:17\"}";
        JSONObject jsonObject = JSON.parseObject(text, Feature.AllowISO8601DateFormat);
        assertEquals(Date.class, jsonObject.get("UpdateTime").getClass());
    }
}

            

Reported by PMD.

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

Line: 16

               * Created by wenshao on 11/06/2017.
 */
public class Issue1083 extends TestCase {
    public void test_for_issue() throws Exception {
        Map map = new HashMap();
        map.put("userId", 456);
        String json = JSON.toJSONString(map, SerializerFeature.WriteNonStringValueAsString);
        assertEquals("{\"userId\":\"456\"}", json);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      Map map = new HashMap();
        map.put("userId", 456);
        String json = JSON.toJSONString(map, SerializerFeature.WriteNonStringValueAsString);
        assertEquals("{\"userId\":\"456\"}", json);
    }
}

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONArray'
Design

Line: 4

              package com.alibaba.json.bvt.issue_1000;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.util.HashMap;

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONObject'
Design

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.util.HashMap;
import java.util.Map;

            

Reported by PMD.

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

Line: 8

              import junit.framework.TestCase;

public class MaximumLevelTest extends TestCase {
    public void test_for_maximum() throws Exception {
        int[] chars = new int[] {0x5b, 0x7b};

        for (int ch : chars) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 1000; ++i) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 12

                      int[] chars = new int[] {0x5b, 0x7b};

        for (int ch : chars) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 1000; ++i) {
                sb.append((char) ch);
            }

            Exception error = null;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                              error = ex;
            }

            assertNotNull(error);
        }

    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '17'-'21').
Error

Line: 17

                              sb.append((char) ch);
            }

            Exception error = null;
            try {
                JSON.parseObject(sb.toString());
            } catch (JSONException ex) {
                error = ex;
            }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/fullSer/ToJavaObjectTest.java
4 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

               * Created by wenshao on 04/02/2017.
 */
public class ToJavaObjectTest extends TestCase {
    public void test_for_toJavaObject() throws Exception {
        JSONObject obj = JSON.parseObject("{\"id\":123}");
        Model model = obj.toJavaObject(Model.class);
        assertEquals(123, model.id);
    }


            

Reported by PMD.

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

Line: 13

              public class ToJavaObjectTest extends TestCase {
    public void test_for_toJavaObject() throws Exception {
        JSONObject obj = JSON.parseObject("{\"id\":123}");
        Model model = obj.toJavaObject(Model.class);
        assertEquals(123, model.id);
    }

    public static class Model {
        public int id;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

                  public void test_for_toJavaObject() throws Exception {
        JSONObject obj = JSON.parseObject("{\"id\":123}");
        Model model = obj.toJavaObject(Model.class);
        assertEquals(123, model.id);
    }

    public static class Model {
        public int id;
    }

            

Reported by PMD.

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

Line: 18

                  }

    public static class Model {
        public int id;
    }
}

            

Reported by PMD.