The following issues were found

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

Line: 19

                  public void test_for_issue() throws Exception {
        String text = "[{\"x\":\"y\"},{\"x\":\"y\"}]";
        List<Model> jsonObject = JSONObject.parseObject(text, new TypeReference<List<Model>>(){});
        System.out.println(JSON.toJSONString(jsonObject));
        String jsonpath = "$..x";
        String value="y2";
        JSONPath.set(jsonObject, jsonpath, value);
        assertEquals("[{\"x\":\"y2\"},{\"x\":\"y2\"}]", JSON.toJSONString(jsonObject));


            

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

               * Created by wenshao on 05/05/2017.
 */
public class Issue1177_3 extends TestCase {
    public void test_for_issue() throws Exception {
        String text = "[{\"x\":\"y\"},{\"x\":\"y\"}]";
        List<Model> jsonObject = JSONObject.parseObject(text, new TypeReference<List<Model>>(){});
        System.out.println(JSON.toJSONString(jsonObject));
        String jsonpath = "$..x";
        String value="y2";

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                      String jsonpath = "$..x";
        String value="y2";
        JSONPath.set(jsonObject, jsonpath, value);
        assertEquals("[{\"x\":\"y2\"},{\"x\":\"y2\"}]", JSON.toJSONString(jsonObject));

    }

    public static class Model {
        public String x;

            

Reported by PMD.

Avoid unused imports such as 'java.util.Map'
Design

Line: 10

              import junit.framework.TestCase;

import java.util.List;
import java.util.Map;

/**
 * Created by wenshao on 05/05/2017.
 */
public class Issue1177_3 extends TestCase {

            

Reported by PMD.

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

Line: 14

                  public void test_for_issue() throws Exception {
        String text = "{\"a\":{\"x\":\"y\"},\"b\":{\"x\":\"y\"}}";
        JSONObject jsonObject = JSONObject.parseObject(text);
        System.out.println(jsonObject);
        String jsonpath = "$..x";
        String value="y2";
        JSONPath.set(jsonObject, jsonpath, value);
        assertEquals("{\"a\":{\"x\":\"y2\"},\"b\":{\"x\":\"y2\"}}", jsonObject.toString());


            

Reported by PMD.

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

Line: 11

               * Created by wenshao on 05/05/2017.
 */
public class Issue1177_1 extends TestCase {
    public void test_for_issue() throws Exception {
        String text = "{\"a\":{\"x\":\"y\"},\"b\":{\"x\":\"y\"}}";
        JSONObject jsonObject = JSONObject.parseObject(text);
        System.out.println(jsonObject);
        String jsonpath = "$..x";
        String value="y2";

            

Reported by PMD.

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

Line: 18

                      String jsonpath = "$..x";
        String value="y2";
        JSONPath.set(jsonObject, jsonpath, value);
        assertEquals("{\"a\":{\"x\":\"y2\"},\"b\":{\"x\":\"y2\"}}", jsonObject.toString());

    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      String jsonpath = "$..x";
        String value="y2";
        JSONPath.set(jsonObject, jsonpath, value);
        assertEquals("{\"a\":{\"x\":\"y2\"},\"b\":{\"x\":\"y2\"}}", jsonObject.toString());

    }
}

            

Reported by PMD.

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

              
public class JSONReaderScannerTest__entity_double extends TestCase {

    public void test_scanFloat() throws Exception {
        StringBuffer buf = new StringBuffer();
        buf.append('[');
        for (int i = 0; i < 1024; ++i) {
            if (i != 0) {
                buf.append(',');

            

Reported by PMD.

Avoid concatenating nonliterals in a StringBuffer/StringBuilder constructor or append().
Performance

Line: 23

                          if (i != 0) {
                buf.append(',');
            }
            buf.append("{\"id\":" + i + ".0}");
        }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());


            

Reported by PMD.

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

Line: 27

                      }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

        JSONReaderScanner scanner = new JSONReaderScanner(reader);

        DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);

            

Reported by PMD.

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

Line: 34

                      DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);
        for (int i = 0; i < array.size(); ++i) {
            Assert.assertTrue((double) i == array.get(i).getId());
        }
        parser.close();
    }

    public static class VO {

            

Reported by PMD.

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

              
public class JSONReaderScannerTest__entity_double_2 extends TestCase {

    public void test_scanFloat() throws Exception {
        StringBuffer buf = new StringBuffer();
        buf.append('[');
        for (int i = 0; i < 1024; ++i) {
            if (i != 0) {
                buf.append(',');

            

Reported by PMD.

Avoid concatenating nonliterals in a StringBuffer/StringBuilder constructor or append().
Performance

Line: 23

                          if (i != 0) {
                buf.append(',');
            }
            buf.append("{\"id\":" + i + ".0}");
        }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());


            

Reported by PMD.

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

Line: 27

                      }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

        JSONReaderScanner scanner = new JSONReaderScanner(reader);

        DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);

            

Reported by PMD.

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

Line: 34

                      DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);
        for (int i = 0; i < array.size(); ++i) {
            Assert.assertTrue(Integer.toString(i), (double) i == array.get(i).getId());
        }
        parser.close();
    }

    private static class VO {

            

Reported by PMD.

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

              
public class JSONReaderScannerTest__entity_float extends TestCase {

    public void test_scanFloat() throws Exception {
        StringBuffer buf = new StringBuffer();
        buf.append('[');
        for (int i = 0; i < 1024; ++i) {
            if (i != 0) {
                buf.append(',');

            

Reported by PMD.

Avoid concatenating nonliterals in a StringBuffer/StringBuilder constructor or append().
Performance

Line: 23

                          if (i != 0) {
                buf.append(',');
            }
            buf.append("{\"id\":" + i + ".0}");
        }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());


            

Reported by PMD.

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

Line: 27

                      }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

        JSONReaderScanner scanner = new JSONReaderScanner(reader);

        DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);

            

Reported by PMD.

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

Line: 34

                      DefaultJSONParser parser = new DefaultJSONParser(scanner);
        List<VO> array = parser.parseArray(VO.class);
        for (int i = 0; i < array.size(); ++i) {
            Assert.assertTrue((float) i == array.get(i).getId());
        }
        parser.close();
    }

    public static class VO {

            

Reported by PMD.

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

              
public class JSONReaderScannerTest__map_string extends TestCase {

    public void test_scanInt() throws Exception {
        StringBuffer buf = new StringBuffer();
        buf.append('[');
        for (int i = 0; i < 10; ++i) {
            if (i != 0) {
                buf.append(',');

            

Reported by PMD.

Avoid concatenating nonliterals in a StringBuffer/StringBuilder constructor or append().
Performance

Line: 25

                          }
            // 1000000000000
            //
            buf.append("{\"id\":\"" + i + "\"}");

        }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

            

Reported by PMD.

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

Line: 30

                      }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

        JSONReaderScanner scanner = new JSONReaderScanner(reader);

        DefaultJSONParser parser = new DefaultJSONParser(scanner);
        JSONArray array = (JSONArray) parser.parse();

            

Reported by PMD.

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

Line: 37

                      DefaultJSONParser parser = new DefaultJSONParser(scanner);
        JSONArray array = (JSONArray) parser.parse();
        for (int i = 0; i < array.size(); ++i) {
            Assert.assertEquals(Integer.toString(i), array.getJSONObject(i).get("id"));
        }
    }

}

            

Reported by PMD.

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

    public void test_e() throws Exception {
        VO vo = new VO();
        vo.setValue("ABC".getBytes("UTF-8"));
        
        String text = JSON.toJSONString(vo);
        

            

Reported by PMD.

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

Line: 22

                      
        JSONReader reader = new JSONReader(new StringReader(text));
        VO vo2 = reader.readObject(VO.class);
        Assert.assertEquals("ABC", new String(vo2.getValue()));
        reader.close();
    }

    public static class VO {


            

Reported by PMD.

Returning 'value' may expose an internal array.
Design

Line: 31

                      private byte[] value;

        public byte[] getValue() {
            return value;
        }

        public void setValue(byte[] value) {
            this.value = value;
        }

            

Reported by PMD.

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

Line: 34

                          return value;
        }

        public void setValue(byte[] value) {
            this.value = value;
        }

    }
}

            

Reported by PMD.

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

              
public class JSONReaderScannerTest_decimal extends TestCase {

    public void test_scanInt() throws Exception {
        StringBuffer buf = new StringBuffer();
        buf.append('[');
        for (int i = 0; i < 1024; ++i) {
            if (i != 0) {
                buf.append(',');

            

Reported by PMD.

Avoid concatenating nonliterals in a StringBuffer/StringBuilder constructor or append().
Performance

Line: 23

                          if (i != 0) {
                buf.append(',');
            }
            buf.append(i + ".0");
        }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());


            

Reported by PMD.

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

Line: 27

                      }
        buf.append(']');

        Reader reader = new StringReader(buf.toString());

        JSONReaderScanner scanner = new JSONReaderScanner(reader);

        DefaultJSONParser parser = new DefaultJSONParser(scanner);
        JSONArray array = (JSONArray) parser.parse();

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 34

                      DefaultJSONParser parser = new DefaultJSONParser(scanner);
        JSONArray array = (JSONArray) parser.parse();
        for (int i = 0; i < array.size(); ++i) {
            BigDecimal value = new BigDecimal(i + ".0");
            Assert.assertEquals(value, array.get(i));
        }
    }
}

            

Reported by PMD.

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

              
public class JSONReaderScannerTest_error2 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: 16

                  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("\"}");

            

Reported by PMD.

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

Line: 25

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


            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '14'-'26').
Error

Line: 14

              public class JSONReaderScannerTest_error2 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_error3.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: 13

              
public class JSONReaderScannerTest_error3 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: 16

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

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


            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '14'-'26').
Error

Line: 14

              public class JSONReaderScannerTest_error3 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.