The following issues were found

src/test/java/com/alibaba/json/bvt/serializer/SpecialTest.java
10 issues
System.out.println is used
Design

Line: 16

                              count++;
            }
        }
        System.out.println(count);
    }
    
    final static long flags;
    static {
        long val = 0L;

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 5

              
import com.alibaba.fastjson.serializer.SerializerFeature;

public class SpecialTest {
    
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {

            

Reported by PMD.

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

Line: 7

              
public class SpecialTest {
    
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 28

                  }
    
    static boolean isSpecial(char ch) {
        if (ch <= 31) {
            return true;
        }
        
        if (ch > '\\') { // 92
            return false;

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 32

                          return true;
        }
        
        if (ch > '\\') { // 92
            return false;
        }
        
        return ((1L << (ch - 31)) & flags) != 0;
    }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 44

                      // return false;
        // }
        
        if (ch == ' ') { // 32
            return false;
        }

        if (ch == '/') { // 47
            return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 48

                          return false;
        }

        if (ch == '/') { // 47
            return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);
        }

        if (ch > '#' // 35
            && ch != '\\' // 92

            

Reported by PMD.

Avoid unnecessary if..then..else statements when returning booleans
Design

Line: 58

                          return false;
        }

        if (ch <= 0x1F // 31
                || ch == '\\' // 92
                || ch == '"' // 34
                ) {
            return true;
        }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'count' (lines '9'-'13').
Error

Line: 9

                  
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {
                count++;
            }

            

Reported by PMD.

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

Line: 13

                      for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {
                count++;
            }
        }
        System.out.println(count);
    }
    

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/support/retrofit/Retrofit2ConverterFactory.java
9 issues
Avoid throwing null pointer exceptions.
Design

Line: 55

                  }

    public static Retrofit2ConverterFactory create(FastJsonConfig fastJsonConfig) {
        if (fastJsonConfig == null) throw new NullPointerException("fastJsonConfig == null");
        return new Retrofit2ConverterFactory(fastJsonConfig);
    }

    @Override
    public Converter<ResponseBody, Object> responseBodyConverter(Type type, //

            

Reported by PMD.

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

Line: 32

                  @Deprecated
    private static final Feature[] EMPTY_SERIALIZER_FEATURES = new Feature[0];
    @Deprecated
    private ParserConfig parserConfig = ParserConfig.getGlobalInstance();
    @Deprecated
    private int featureValues = JSON.DEFAULT_PARSER_FEATURE;
    @Deprecated
    private Feature[] features;
    @Deprecated

            

Reported by PMD.

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

Line: 34

                  @Deprecated
    private ParserConfig parserConfig = ParserConfig.getGlobalInstance();
    @Deprecated
    private int featureValues = JSON.DEFAULT_PARSER_FEATURE;
    @Deprecated
    private Feature[] features;
    @Deprecated
    private SerializeConfig serializeConfig;
    @Deprecated

            

Reported by PMD.

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

Line: 213

                  }

    final class ResponseBodyConverter<T> implements Converter<ResponseBody, T> {
        private Type type;

        ResponseBodyConverter(Type type) {
            this.type = type;
        }


            

Reported by PMD.

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

Line: 213

                  }

    final class ResponseBodyConverter<T> implements Converter<ResponseBody, T> {
        private Type type;

        ResponseBodyConverter(Type type) {
            this.type = type;
        }


            

Reported by PMD.

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

Line: 229

                                      , JSON.DEFAULT_PARSER_FEATURE
                        , fastJsonConfig.getFeatures()
                );
            } catch (Exception e) {
                throw new IOException("JSON parse error: " + e.getMessage(), e);
            } finally {
                value.close();
            }
        }

            

Reported by PMD.

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

Line: 252

                                      , fastJsonConfig.getSerializerFeatures()
                );
                return RequestBody.create(MEDIA_TYPE, content);
            } catch (Exception e) {
                throw new IOException("Could not write JSON: " + e.getMessage(), e);
            }
        }
    }
}

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 155

                   * @deprecated
     */
    @Deprecated
    public Retrofit2ConverterFactory setParserFeatures(Feature[] features) {
        fastJsonConfig.setFeatures(features);
        return this;
    }

    /**

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 207

                   * @deprecated
     */
    @Deprecated
    public Retrofit2ConverterFactory setSerializerFeatures(SerializerFeature[] features) {
        fastJsonConfig.setSerializerFeatures(features);
        return this;
    }

    final class ResponseBodyConverter<T> implements Converter<ResponseBody, T> {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/SerializeEnumAsJavaBeanTest_private.java
9 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 08/01/2017.
 */
public class SerializeEnumAsJavaBeanTest_private extends TestCase {
    public void test_serializeEnumAsJavaBean() throws Exception {
        String text = JSON.toJSONString(OrderType.PayOrder);
        assertEquals("{\"remark\":\"支付订单\",\"value\":1}", text);
    }

    public void test_field() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

              public class SerializeEnumAsJavaBeanTest_private extends TestCase {
    public void test_serializeEnumAsJavaBean() throws Exception {
        String text = JSON.toJSONString(OrderType.PayOrder);
        assertEquals("{\"remark\":\"支付订单\",\"value\":1}", text);
    }

    public void test_field() throws Exception {
        Model model = new Model();
        model.orderType = OrderType.SettleBill;

            

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

                      assertEquals("{\"remark\":\"支付订单\",\"value\":1}", text);
    }

    public void test_field() throws Exception {
        Model model = new Model();
        model.orderType = OrderType.SettleBill;
        String text = JSON.toJSONString(model);
        assertEquals("{\"orderType\":{\"remark\":\"结算单\",\"value\":2}}", text);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      Model model = new Model();
        model.orderType = OrderType.SettleBill;
        String text = JSON.toJSONString(model);
        assertEquals("{\"orderType\":{\"remark\":\"结算单\",\"value\":2}}", text);
    }

    public void test_field_2() throws Exception {
        Model model = new Model();
        model.orderType = OrderType.SettleBill;

            

Reported by PMD.

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

Line: 24

                      assertEquals("{\"orderType\":{\"remark\":\"结算单\",\"value\":2}}", text);
    }

    public void test_field_2() throws Exception {
        Model model = new Model();
        model.orderType = OrderType.SettleBill;
        model.orderType1 = OrderType.SettleBill;
        String text = JSON.toJSONString(model);
        assertEquals("{\"orderType\":{\"remark\":\"结算单\",\"value\":2},\"orderType1\":{\"remark\":\"结算单\",\"value\":2}}", text);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

                      model.orderType = OrderType.SettleBill;
        model.orderType1 = OrderType.SettleBill;
        String text = JSON.toJSONString(model);
        assertEquals("{\"orderType\":{\"remark\":\"结算单\",\"value\":2},\"orderType1\":{\"remark\":\"结算单\",\"value\":2}}", text);
    }

    @JSONType(serializeEnumAsJavaBean = true)
    private static enum OrderType {
        PayOrder(1, "支付订单"), //

            

Reported by PMD.

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

Line: 47

                  }

    private static class Model {
        public OrderType orderType;
        public OrderType orderType1;
    }
}

            

Reported by PMD.

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

Line: 48

              
    private static class Model {
        public OrderType orderType;
        public OrderType orderType1;
    }
}

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.serializer.SerializeConfig'
Design

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONType;
import com.alibaba.fastjson.serializer.SerializeConfig;
import junit.framework.TestCase;

/**
 * Created by wenshao on 08/01/2017.
 */

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1700/Issue1764_bean_biginteger_type.java
9 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

              import static com.alibaba.fastjson.serializer.SerializerFeature.BrowserCompatible;

public class Issue1764_bean_biginteger_type extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L)));

        assertEquals("{\"value\":\"-9007199254741992\"}"

            

Reported by PMD.

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

Line: 12

              import static com.alibaba.fastjson.serializer.SerializerFeature.BrowserCompatible;

public class Issue1764_bean_biginteger_type extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L)));

        assertEquals("{\"value\":\"-9007199254741992\"}"

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

              
public class Issue1764_bean_biginteger_type extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L)));

        assertEquals("{\"value\":\"-9007199254741992\"}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                              , JSON.toJSONString(
                        new Model(9007199254741992L)));

        assertEquals("{\"value\":\"-9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(-9007199254741992L)));

        assertEquals("{\"value\":9007199254740990}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                              , JSON.toJSONString(
                        new Model(-9007199254741992L)));

        assertEquals("{\"value\":9007199254740990}"
                , JSON.toJSONString(
                        new Model(9007199254740990L)));

        assertEquals("{\"value\":-9007199254740990}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                              , JSON.toJSONString(
                        new Model(9007199254740990L)));

        assertEquals("{\"value\":-9007199254740990}"
                , JSON.toJSONString(
                        new Model(-9007199254740990L)));

        assertEquals("{\"value\":100}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

                              , JSON.toJSONString(
                        new Model(-9007199254740990L)));

        assertEquals("{\"value\":100}"
                , JSON.toJSONString(
                        new Model(100)));

        assertEquals("{\"value\":-100}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                              , JSON.toJSONString(
                        new Model(100)));

        assertEquals("{\"value\":-100}"
                , JSON.toJSONString(
                        new Model(-100)));
    }



            

Reported by PMD.

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

Line: 42

              
    @JSONType(serialzeFeatures = BrowserCompatible)
    public static class Model {
        public BigInteger value;

        public Model() {

        }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/generic/GenericTest2.java
9 issues
Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 22

              		Assert.assertNotNull(pageBean.getItems());
		Assert.assertEquals(1, pageBean.getItems().size());
		ActiveBase active = pageBean.getItems().get(0);
		Assert.assertEquals(new Integer(234), active.getId());
		Assert.assertTrue(3.7D == active.getLongtitude());
		Assert.assertTrue(2.5D == active.getLatitude());
	}

	public static class ActiveBase extends BaseModel {

            

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

              import com.alibaba.fastjson.TypeReference;

public class GenericTest2 extends TestCase {
	public void test_for_bingyang() throws Exception {
		String text = "{\"count\":123,\"index\":7,\"items\":[{\"id\":234,\"latitude\":2.5,\"longtitude\":3.7}]}";
		PageBean<ActiveBase> pageBean = JSON.parseObject(text, new TypeReference<PageBean<ActiveBase>>() {});
		Assert.assertNotNull(pageBean);
		Assert.assertEquals(123, pageBean.getCount());
		Assert.assertEquals(7, pageBean.getIndex());

            

Reported by PMD.

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

Line: 20

              		Assert.assertEquals(123, pageBean.getCount());
		Assert.assertEquals(7, pageBean.getIndex());
		Assert.assertNotNull(pageBean.getItems());
		Assert.assertEquals(1, pageBean.getItems().size());
		ActiveBase active = pageBean.getItems().get(0);
		Assert.assertEquals(new Integer(234), active.getId());
		Assert.assertTrue(3.7D == active.getLongtitude());
		Assert.assertTrue(2.5D == active.getLatitude());
	}

            

Reported by PMD.

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

Line: 21

              		Assert.assertEquals(7, pageBean.getIndex());
		Assert.assertNotNull(pageBean.getItems());
		Assert.assertEquals(1, pageBean.getItems().size());
		ActiveBase active = pageBean.getItems().get(0);
		Assert.assertEquals(new Integer(234), active.getId());
		Assert.assertTrue(3.7D == active.getLongtitude());
		Assert.assertTrue(2.5D == active.getLatitude());
	}


            

Reported by PMD.

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

Line: 22

              		Assert.assertNotNull(pageBean.getItems());
		Assert.assertEquals(1, pageBean.getItems().size());
		ActiveBase active = pageBean.getItems().get(0);
		Assert.assertEquals(new Integer(234), active.getId());
		Assert.assertTrue(3.7D == active.getLongtitude());
		Assert.assertTrue(2.5D == active.getLatitude());
	}

	public static class ActiveBase extends BaseModel {

            

Reported by PMD.

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

Line: 23

              		Assert.assertEquals(1, pageBean.getItems().size());
		ActiveBase active = pageBean.getItems().get(0);
		Assert.assertEquals(new Integer(234), active.getId());
		Assert.assertTrue(3.7D == active.getLongtitude());
		Assert.assertTrue(2.5D == active.getLatitude());
	}

	public static class ActiveBase extends BaseModel {
		private double latitude;

            

Reported by PMD.

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

Line: 24

              		ActiveBase active = pageBean.getItems().get(0);
		Assert.assertEquals(new Integer(234), active.getId());
		Assert.assertTrue(3.7D == active.getLongtitude());
		Assert.assertTrue(2.5D == active.getLatitude());
	}

	public static class ActiveBase extends BaseModel {
		private double latitude;
		private double longtitude;

            

Reported by PMD.

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

Line: 27

              		Assert.assertTrue(2.5D == active.getLatitude());
	}

	public static class ActiveBase extends BaseModel {
		private double latitude;
		private double longtitude;
		public double getLatitude() {
			return latitude;
		}

            

Reported by PMD.

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

Line: 56

              		}
	}

	public static class PageBean<T> {
		private int count;
		private int index;
		private List<T> items;

		public int getCount() {

            

Reported by PMD.

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

Line: 22

                      A a = new A();
        a.setList(Collections.singletonList(new B()));
        String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
        System.out.println(text);
        Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection2$A\",\"list\":[{}]}",
                            text);

        A a1 = (A) JSON.parse(text);


            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 14

              import com.alibaba.fastjson.serializer.SerializerFeature;

public class WriteClassNameTest_Collection2 extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection2");
    }

    public void test_list() throws Exception {
        A a = new A();

            

Reported by PMD.

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

Line: 15

              
public class WriteClassNameTest_Collection2 extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection2");
    }

    public void test_list() throws Exception {
        A a = new A();
        a.setList(Collections.singletonList(new B()));

            

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

                      ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection2");
    }

    public void test_list() throws Exception {
        A a = new A();
        a.setList(Collections.singletonList(new B()));
        String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
        System.out.println(text);
        Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection2$A\",\"list\":[{}]}",

            

Reported by PMD.

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

Line: 28

              
        A a1 = (A) JSON.parse(text);

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    public static class A {


            

Reported by PMD.

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

Line: 28

              
        A a1 = (A) JSON.parse(text);

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    public static class A {


            

Reported by PMD.

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

Line: 29

                      A a1 = (A) JSON.parse(text);

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    public static class A {

        private Collection<B> list;

            

Reported by PMD.

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

Line: 29

                      A a1 = (A) JSON.parse(text);

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    public static class A {

        private Collection<B> list;

            

Reported by PMD.

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

Line: 29

                      A a1 = (A) JSON.parse(text);

        Assert.assertEquals(1, a1.getList().size());
        Assert.assertTrue(a1.getList().iterator().next() instanceof B);
    }

    public static class A {

        private Collection<B> list;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1700/Issue1764_bean.java
9 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

              import static com.alibaba.fastjson.serializer.SerializerFeature.BrowserCompatible;

public class Issue1764_bean extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L)));

        assertEquals("{\"value\":\"9007199254741990\"}"

            

Reported by PMD.

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

Line: 11

              import static com.alibaba.fastjson.serializer.SerializerFeature.BrowserCompatible;

public class Issue1764_bean extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L)));

        assertEquals("{\"value\":\"9007199254741990\"}"

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

              
public class Issue1764_bean extends TestCase {
    public void test_for_issue() throws Exception {
        assertEquals("{\"value\":\"9007199254741992\"}"
                , JSON.toJSONString(
                        new Model(9007199254741992L)));

        assertEquals("{\"value\":\"9007199254741990\"}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                              , JSON.toJSONString(
                        new Model(9007199254741992L)));

        assertEquals("{\"value\":\"9007199254741990\"}"
                , JSON.toJSONString(
                        new Model(9007199254741990L)));

        assertEquals("{\"value\":100}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                              , JSON.toJSONString(
                        new Model(9007199254741990L)));

        assertEquals("{\"value\":100}"
                , JSON.toJSONString(
                        new Model(100L)));

        assertEquals("{\"value\":\"-9007199254741990\"}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                              , JSON.toJSONString(
                        new Model(100L)));

        assertEquals("{\"value\":\"-9007199254741990\"}"
                , JSON.toJSONString(
                        new Model(-9007199254741990L)));

        assertEquals("{\"value\":-9007199254740990}"
                , JSON.toJSONString(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 28

                              , JSON.toJSONString(
                        new Model(-9007199254741990L)));

        assertEquals("{\"value\":-9007199254740990}"
                , JSON.toJSONString(
                        new Model(-9007199254740990L)));

    }


            

Reported by PMD.

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

Line: 38

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

        public Model() {

        }


            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.annotation.JSONField'
Design

Line: 4

              package com.alibaba.json.bvt.issue_1700;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
import junit.framework.TestCase;

import static com.alibaba.fastjson.serializer.SerializerFeature.BrowserCompatible;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue87_hashset.java
9 issues
System.out.println is used
Design

Line: 18

                      to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

            

Reported by PMD.

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

Line: 13

              

public class Issue87_hashset extends TestCase {
    public void test_for_issue() throws Exception {
        TestObject to = new TestObject();
        to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(text);

            

Reported by PMD.

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

Line: 13

              

public class Issue87_hashset extends TestCase {
    public void test_for_issue() throws Exception {
        TestObject to = new TestObject();
        to.add("test1");
        to.add("test2");
        String text = JSON.toJSONString(to);
        System.out.println(text);

            

Reported by PMD.

The value assigned to variable 'to' is never used
Design

Line: 20

                      String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

        private HashSet<String> set = new HashSet<String>(0);

            

Reported by PMD.

Avoid using implementation types like 'HashSet'; use the interface instead
Design

Line: 25

                  
    public static class TestObject {

        private HashSet<String> set = new HashSet<String>(0);

        public HashSet<String> getSet() {
            return set;
        }


            

Reported by PMD.

Avoid using implementation types like 'HashSet'; use the interface instead
Design

Line: 27

              
        private HashSet<String> set = new HashSet<String>(0);

        public HashSet<String> getSet() {
            return set;
        }

        public void setSet(HashSet<String> set) {
            this.set = set;

            

Reported by PMD.

Avoid using implementation types like 'HashSet'; use the interface instead
Design

Line: 31

                          return set;
        }

        public void setSet(HashSet<String> set) {
            this.set = set;
        }

        public void add(String str) {
            set.add(str);

            

Reported by PMD.

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

Line: 4

              package com.alibaba.json.bvt.bug;

import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'to' (lines '20'-'21').
Error

Line: 20

                      String text = JSON.toJSONString(to);
        System.out.println(text);
        JSONObject jo = JSON.parseObject(text);
        to = JSON.toJavaObject(jo, TestObject.class);
    }
    
    public static class TestObject {

        private HashSet<String> set = new HashSet<String>(0);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/MapRefTest1.java
9 issues
System.out.println is used
Design

Line: 33

                          text = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        }
        
        System.out.println(text);
        Map<String, Object> map = JSON.parseObject(text);
        //Assert.assertEquals(map, map.get("this"));
        Assert.assertEquals(map.get("u1"), map.get("u2"));
    }


            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 14

              import com.alibaba.fastjson.serializer.SerializerFeature;

public class MapRefTest1 extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.MapRefTest1");
    }

    public void test_0() throws Exception {
        String text;

            

Reported by PMD.

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

Line: 15

              
public class MapRefTest1 extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.MapRefTest1");
    }

    public void test_0() throws Exception {
        String text;
        {

            

Reported by PMD.

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

Line: 18

                      ParserConfig.global.addAccept("com.alibaba.json.bvt.MapRefTest1");
    }

    public void test_0() throws Exception {
        String text;
        {
            Map<String, Object> map = new HashMap<String, Object>();

            User user = new User();

            

Reported by PMD.

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

Line: 27

                          user.setId(123);
            user.setName("wenshao");
            
            map.put("u1", user);
            map.put("u2", user);
            
            text = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        }
        

            

Reported by PMD.

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

Line: 28

                          user.setName("wenshao");
            
            map.put("u1", user);
            map.put("u2", user);
            
            text = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        }
        
        System.out.println(text);

            

Reported by PMD.

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

Line: 36

                      System.out.println(text);
        Map<String, Object> map = JSON.parseObject(text);
        //Assert.assertEquals(map, map.get("this"));
        Assert.assertEquals(map.get("u1"), map.get("u2"));
    }

    public static class User {

        private int    id;

            

Reported by PMD.

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

Line: 36

                      System.out.println(text);
        Map<String, Object> map = JSON.parseObject(text);
        //Assert.assertEquals(map, map.get("this"));
        Assert.assertEquals(map.get("u1"), map.get("u2"));
    }

    public static class User {

        private int    id;

            

Reported by PMD.

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

Line: 39

                      Assert.assertEquals(map.get("u1"), map.get("u2"));
    }

    public static class User {

        private int    id;
        private String name;

        public int getId() {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1600/Issue_for_gaorui.java
9 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 Issue_for_gaorui extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"@type\":\"java.util.HashMap\",\"COUPON\":[{\"@type\":\"com.alibaba.json.bvt.issue_1600.Issue_for_gaorui.PromotionTermDetail\",\"activityId\":\"1584034\",\"choose\":true,\"couponId\":1251068987,\"couponType\":\"limitp\",\"match\":true,\"realPrice\":{\"amount\":0.6,\"currency\":\"USD\"}}],\"grayTrade\":\"true\"}";

        JSON.parseObject(json, Object.class, Feature.SupportAutoType);
    }


            

Reported by PMD.

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

Line: 8

              import junit.framework.TestCase;

public class Issue_for_gaorui extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"@type\":\"java.util.HashMap\",\"COUPON\":[{\"@type\":\"com.alibaba.json.bvt.issue_1600.Issue_for_gaorui.PromotionTermDetail\",\"activityId\":\"1584034\",\"choose\":true,\"couponId\":1251068987,\"couponType\":\"limitp\",\"match\":true,\"realPrice\":{\"amount\":0.6,\"currency\":\"USD\"}}],\"grayTrade\":\"true\"}";

        JSON.parseObject(json, Object.class, Feature.SupportAutoType);
    }


            

Reported by PMD.

The class 'PromotionTermDetail' is suspected to be a Data Class (WOC=22.222%, NOPA=0, NOAM=14, WMC=18)
Design

Line: 14

                      JSON.parseObject(json, Object.class, Feature.SupportAutoType);
    }

    public static class PromotionTermDetail {
        /**
         * 卡券Id
         */
        private Long couponId;
        /**

            

Reported by PMD.

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

Line: 40

                      /**
         * 是否能够获取到该优惠
         */
        private boolean isMatch = false;
        /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**

            

Reported by PMD.

Avoid using redundant field initializer for 'isMatch'
Performance

Line: 40

                      /**
         * 是否能够获取到该优惠
         */
        private boolean isMatch = false;
        /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**

            

Reported by PMD.

Field isMatch has the same name as a method
Error

Line: 40

                      /**
         * 是否能够获取到该优惠
         */
        private boolean isMatch = false;
        /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**

            

Reported by PMD.

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

Line: 44

                      /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**
         * 未获取到优惠的原因
         */
        private String reasonForLose;
        /**

            

Reported by PMD.

Avoid using redundant field initializer for 'isChoose'
Performance

Line: 44

                      /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**
         * 未获取到优惠的原因
         */
        private String reasonForLose;
        /**

            

Reported by PMD.

Field isChoose has the same name as a method
Error

Line: 44

                      /**
         * 是否选择了该优惠
         */
        private boolean isChoose = false;
        /**
         * 未获取到优惠的原因
         */
        private String reasonForLose;
        /**

            

Reported by PMD.