The following issues were found

src/test/java/com/alibaba/json/bvt/date/DateFieldTest8.java
3 issues
JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 16

              import com.alibaba.fastjson.annotation.JSONField;

public class DateFieldTest8 extends TestCase {
    protected void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
        JSON.defaultLocale = Locale.CHINA;
    }
    
    public void test_0() throws Exception {

            

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

                      JSON.defaultLocale = Locale.CHINA;
    }
    
    public void test_0() throws Exception {
        Entity object = new Entity();
        object.setValue(new Date());
        String text = JSON.toJSONStringWithDateFormat(object, "yyyy");
        SimpleDateFormat format = new SimpleDateFormat("yyyy", JSON.defaultLocale);
        format.setTimeZone(JSON.defaultTimeZone);

            

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

                                          text);
    }

    public void test_1() throws Exception {
        Entity object = new Entity();
        object.setValue(new Date());
        String text = JSON.toJSONString(object);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
        format.setTimeZone(JSON.defaultTimeZone);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1700/Issue1764.java
3 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 static com.alibaba.fastjson.serializer.SerializerFeature.BrowserCompatible;

public class Issue1764 extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        model.value = 9007199254741992L;

        String str = JSON.toJSONString(model);
        assertEquals("{\"value\":\"9007199254741992\"}", str);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                      model.value = 9007199254741992L;

        String str = JSON.toJSONString(model);
        assertEquals("{\"value\":\"9007199254741992\"}", str);
    }

    public static class Model {
        @JSONField(serialzeFeatures = BrowserCompatible)
        public long value;

            

Reported by PMD.

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

Line: 20

              
    public static class Model {
        @JSONField(serialzeFeatures = BrowserCompatible)
        public long value;
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1100/Issue1165.java
3 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

               * Created by wenshao on 27/04/2017.
 */
public class Issue1165 extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        model.__v = 3;

        String json = JSON.toJSONString(model);
        assertEquals("{\"__v\":3}", json);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                      model.__v = 3;

        String json = JSON.toJSONString(model);
        assertEquals("{\"__v\":3}", json);
    }

    public static class Model {
        public Number __v;
    }

            

Reported by PMD.

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

Line: 19

                  }

    public static class Model {
        public Number __v;
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2600/Issue2685.java
3 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: 21

              import junit.framework.TestCase;

public class Issue2685 extends TestCase {
    public void test_field() throws Exception {
        SMGPSubmitMessage smgpSubmitMessage = new SMGPSubmitMessage();
        smgpSubmitMessage.setSequenceNo(1);
        smgpSubmitMessage.setServiceId("hell");
        smgpSubmitMessage.setMsgContent("hello"); // 注释掉可以正常
        smgpSubmitMessage.setChargeTermId("123555");

            

Reported by PMD.

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

Line: 37

              
        JSON.addMixInAnnotations(SMGPSubmitMessage.class, Mixin.class);
        smgpSubmitMessage = JSON.parseObject(smsMsg, SMGPSubmitMessage.class);
        assertEquals("hello", smgpSubmitMessage.getMsgContent());
    }

    public interface Mixin {
        @JSONField(deserializeUsing = MyDeserializer.class)
        void setMsgContent(SmsMessage msg);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 37

              
        JSON.addMixInAnnotations(SMGPSubmitMessage.class, Mixin.class);
        smgpSubmitMessage = JSON.parseObject(smsMsg, SMGPSubmitMessage.class);
        assertEquals("hello", smgpSubmitMessage.getMsgContent());
    }

    public interface Mixin {
        @JSONField(deserializeUsing = MyDeserializer.class)
        void setMsgContent(SmsMessage msg);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONReaderScannerTest_array_string.java
3 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 JSONReaderScannerTest_array_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: 24

                          }
            // 1000000000000
            //
            buf.append("\"" + 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: 28

                      }
        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.

src/test/java/com/alibaba/json/bvt/parser/bug/Bug_for_changhao.java
3 issues
System.out.println is used
Design

Line: 15

                      ParserConfig parseConfig = new ParserConfig();
        parseConfig.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
        TestClass t = JSON.parseObject(s, TestClass.class, parseConfig, Feature.DisableFieldSmartMatch);
        System.out.println(JSON.toJSONString(t));
    }

    static class TestClass {
        String stringValue;
        int intValue;

            

Reported by PMD.

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

Line: 10

              import junit.framework.TestCase;

public class Bug_for_changhao extends TestCase {
    public void test_for_bug() throws Exception {
        String s = "{\"intValue\":1,\"stringValue\":\"abc\"}";
        ParserConfig parseConfig = new ParserConfig();
        parseConfig.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
        TestClass t = JSON.parseObject(s, TestClass.class, parseConfig, Feature.DisableFieldSmartMatch);
        System.out.println(JSON.toJSONString(t));

            

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 junit.framework.TestCase;

public class Bug_for_changhao extends TestCase {
    public void test_for_bug() throws Exception {
        String s = "{\"intValue\":1,\"stringValue\":\"abc\"}";
        ParserConfig parseConfig = new ParserConfig();
        parseConfig.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
        TestClass t = JSON.parseObject(s, TestClass.class, parseConfig, Feature.DisableFieldSmartMatch);
        System.out.println(JSON.toJSONString(t));

            

Reported by PMD.

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

    public void test_e() throws Exception {
        Exception error = null;
        try {
            new JSONReader(new MyReader());
        } catch (Exception ex) {
            error = ex;

            

Reported by PMD.

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

Line: 17

                      Exception error = null;
        try {
            new JSONReader(new MyReader());
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }


            

Reported by PMD.

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

Line: 14

              public class JSONReaderScannerTest_error extends TestCase {

    public void test_e() throws Exception {
        Exception error = null;
        try {
            new JSONReader(new MyReader());
        } catch (Exception ex) {
            error = ex;
        }

            

Reported by PMD.

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

    public void test_long_list() throws Exception {
        String str = "{\"tnt_inst_id\":\"MYBKC1CN\",\"interface_id\":\"ant.mybank.loantrade.existvalidloan.query @1.0.0\",\"template_id\":\"EX-SYNC-IN-\n" +
                "\n" +
                "OPEN-API\"}";

        JSON.parseObject(str);

            

Reported by PMD.

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

Line: 15

               */
public class Bug_for_guanxiu extends TestCase {

    public void test_long_list() throws Exception {
        String str = "{\"tnt_inst_id\":\"MYBKC1CN\",\"interface_id\":\"ant.mybank.loantrade.existvalidloan.query @1.0.0\",\"template_id\":\"EX-SYNC-IN-\n" +
                "\n" +
                "OPEN-API\"}";

        JSON.parseObject(str);

            

Reported by PMD.

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

Line: 6

              import com.alibaba.fastjson.JSON;
import junit.framework.TestCase;

import java.util.List;

/**
 * 这个bug由李先锋反馈
 * @author wenshao
 *

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2300/Issue2387.java
3 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

              
public class Issue2387 extends TestCase
{
    public void test_for_issue() throws Exception {
        String jsonStr = "{id:\"ss\",ddd:\"sdfsd\",name:\"hh\"}";
        TestEntity news = JSON.parseObject(jsonStr, TestEntity.class, Feature.InitStringFieldAsEmpty);
        assertEquals("{\"ddd\":\"sdfsd\",\"id\":\"ss\",\"name\":\"hh\"}", JSON.toJSONString(news));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

                  public void test_for_issue() throws Exception {
        String jsonStr = "{id:\"ss\",ddd:\"sdfsd\",name:\"hh\"}";
        TestEntity news = JSON.parseObject(jsonStr, TestEntity.class, Feature.InitStringFieldAsEmpty);
        assertEquals("{\"ddd\":\"sdfsd\",\"id\":\"ss\",\"name\":\"hh\"}", JSON.toJSONString(news));
    }

    public static class TestEntity {
        private String id;
        private String ddd;

            

Reported by PMD.

The class 'TestEntity' is suspected to be a Data Class (WOC=0.000%, NOPA=0, NOAM=6, WMC=6)
Design

Line: 15

                      assertEquals("{\"ddd\":\"sdfsd\",\"id\":\"ss\",\"name\":\"hh\"}", JSON.toJSONString(news));
    }

    public static class TestEntity {
        private String id;
        private String ddd;
        private String name;

        public String getId()

            

Reported by PMD.

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

Line: 18

                              "}";

        JSONObject jsonObject =JSON.parseObject(json);
        System.out.println(jsonObject);
    }
}

            

Reported by PMD.

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

Line: 11

               * Created by wenshao on 08/05/2017.
 */
public class Issue1153 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\n" +
                "name: 'zhangshan', //这是一个姓名\n" +
                "test : '//helo'\n" +
                "}";


            

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 08/05/2017.
 */
public class Issue1153 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\n" +
                "name: 'zhangshan', //这是一个姓名\n" +
                "test : '//helo'\n" +
                "}";


            

Reported by PMD.