The following issues were found

src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_Eishay.java
10 issues
Do not use the short type
Performance

Line: 22

                  }
    
    public static class VO {
        private short id;
        private String name;

        public short getId() {
            return id;
        }

            

Reported by PMD.

Do not use the short type
Performance

Line: 25

                      private short id;
        private String name;

        public short getId() {
            return id;
        }

        public void setId(short id) {
            this.id = id;

            

Reported by PMD.

Do not use the short type
Performance

Line: 29

                          return id;
        }

        public void setId(short id) {
            this.id = id;
        }

        public String getName() {
            return name;

            

Reported by PMD.

System.out.println is used
Design

Line: 17

                      MediaContent content = EishayDecodeBytes.instance.getContent();
        
        String text = JSON.toJSONString(content, SerializerFeature.BeanToArray);
        System.out.println(text.getBytes().length);
        JSON.parseObject(text, MediaContent.class, Feature.SupportArrayToBean);
    }
    
    public static class VO {
        private short id;

            

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 data.media.MediaContent;

public class WriteAsArray_Eishay extends TestCase {
    public void test_0 () throws Exception {
        MediaContent content = EishayDecodeBytes.instance.getContent();
        
        String text = JSON.toJSONString(content, SerializerFeature.BeanToArray);
        System.out.println(text.getBytes().length);
        JSON.parseObject(text, MediaContent.class, Feature.SupportArrayToBean);

            

Reported by PMD.

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

Line: 13

              import data.media.MediaContent;

public class WriteAsArray_Eishay extends TestCase {
    public void test_0 () throws Exception {
        MediaContent content = EishayDecodeBytes.instance.getContent();
        
        String text = JSON.toJSONString(content, SerializerFeature.BeanToArray);
        System.out.println(text.getBytes().length);
        JSON.parseObject(text, MediaContent.class, Feature.SupportArrayToBean);

            

Reported by PMD.

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

Line: 14

              
public class WriteAsArray_Eishay extends TestCase {
    public void test_0 () throws Exception {
        MediaContent content = EishayDecodeBytes.instance.getContent();
        
        String text = JSON.toJSONString(content, SerializerFeature.BeanToArray);
        System.out.println(text.getBytes().length);
        JSON.parseObject(text, MediaContent.class, Feature.SupportArrayToBean);
    }

            

Reported by PMD.

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

Line: 17

                      MediaContent content = EishayDecodeBytes.instance.getContent();
        
        String text = JSON.toJSONString(content, SerializerFeature.BeanToArray);
        System.out.println(text.getBytes().length);
        JSON.parseObject(text, MediaContent.class, Feature.SupportArrayToBean);
    }
    
    public static class VO {
        private short id;

            

Reported by PMD.

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

Line: 17

                      MediaContent content = EishayDecodeBytes.instance.getContent();
        
        String text = JSON.toJSONString(content, SerializerFeature.BeanToArray);
        System.out.println(text.getBytes().length);
        JSON.parseObject(text, MediaContent.class, Feature.SupportArrayToBean);
    }
    
    public static class VO {
        private short id;

            

Reported by PMD.

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

Line: 21

                      JSON.parseObject(text, MediaContent.class, Feature.SupportArrayToBean);
    }
    
    public static class VO {
        private short id;
        private String name;

        public short getId() {
            return id;

            

Reported by PMD.

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/test/java/com/alibaba/json/bvt/issue_1300/Issue1300.java
10 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 14

               * Created by wenshao on 01/07/2017.
 */
public class Issue1300 extends TestCase {
    public void testFullJSON() {
        JSONObject data = new JSONObject();
        data.put("name", "string");
        data.put("code", 1);
        data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.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: 14

               * Created by wenshao on 01/07/2017.
 */
public class Issue1300 extends TestCase {
    public void testFullJSON() {
        JSONObject data = new JSONObject();
        data.put("name", "string");
        data.put("code", 1);
        data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);

            

Reported by PMD.

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

Line: 18

                      JSONObject data = new JSONObject();
        data.put("name", "string");
        data.put("code", 1);
        data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);
        assertEquals("string", object.name);
        assertEquals(1, object.code);
        assertEquals("pinyin", object.pinyin);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      data.put("code", 1);
        data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);
        assertEquals("string", object.name);
        assertEquals(1, object.code);
        assertEquals("pinyin", object.pinyin);
    }

    public void testEmptyJSON() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      data.put("pinyin", "pinyin");
        City object = TypeUtils.castToJavaBean(data, City.class);
        assertEquals("string", object.name);
        assertEquals(1, object.code);
        assertEquals("pinyin", object.pinyin);
    }

    public void testEmptyJSON() {
        City object = TypeUtils.castToJavaBean(new JSONObject(), City.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      City object = TypeUtils.castToJavaBean(data, City.class);
        assertEquals("string", object.name);
        assertEquals(1, object.code);
        assertEquals("pinyin", object.pinyin);
    }

    public void testEmptyJSON() {
        City object = TypeUtils.castToJavaBean(new JSONObject(), City.class);
        Assert.assertEquals(null, object.name);

            

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

                      assertEquals("pinyin", object.pinyin);
    }

    public void testEmptyJSON() {
        City object = TypeUtils.castToJavaBean(new JSONObject(), City.class);
        Assert.assertEquals(null, object.name);
        Assert.assertEquals(0, object.code);
    }


            

Reported by PMD.

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

Line: 33

              

    public static class City implements Parcelable {
        public final int code;
        public final String name;
        public final String pinyin;

        @JSONCreator
        public City(@JSONField(name = "code") int code,

            

Reported by PMD.

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

Line: 34

              
    public static class City implements Parcelable {
        public final int code;
        public final String name;
        public final String pinyin;

        @JSONCreator
        public City(@JSONField(name = "code") int code,
                    @JSONField(name = "name") String name,

            

Reported by PMD.

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

Line: 35

                  public static class City implements Parcelable {
        public final int code;
        public final String name;
        public final String pinyin;

        @JSONCreator
        public City(@JSONField(name = "code") int code,
                    @JSONField(name = "name") String name,
                    @JSONField(name = "pinyin") String pinyin) {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_465.java
10 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

              import junit.framework.TestCase;

public class Bug_for_issue_465 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "[\"abc\",\"efg\",\"sss\",[1,2]]";
        
        TestBean testBean = JSON.parseObject(json, TestBean.class);
        Assert.assertEquals("abc", testBean.name);
        Assert.assertEquals("efg", testBean.country);

            

Reported by PMD.

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

Line: 25

                      Assert.assertEquals(2, testBean.location[1]);
    }
    
    public void f_test_for_issue_private() throws Exception {
        String json = "[\"abc\",\"efg\",\"sss\",[1,2]]";
        
        TestBean1 testBean = JSON.parseObject(json, TestBean1.class);
        Assert.assertEquals("abc", testBean.name);
        Assert.assertEquals("efg", testBean.country);

            

Reported by PMD.

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

Line: 38

                  }
    
    @JSONType(parseFeatures = Feature.SupportArrayToBean)
    public static class TestBean {
      private String name;

      private String password;

      private String country;

            

Reported by PMD.

Returning 'location' may expose an internal array.
Design

Line: 75

                    }

      public int[] getLocation() {
        return location;
      }

      @JSONField(ordinal = 3)
      public void setLocation(int[] location) {
        this.location = location;

            

Reported by PMD.

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

Line: 79

                    }

      @JSONField(ordinal = 3)
      public void setLocation(int[] location) {
        this.location = location;
      }
    }
    
    @JSONType(parseFeatures = Feature.SupportArrayToBean)

            

Reported by PMD.

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

Line: 85

                  }
    
    @JSONType(parseFeatures = Feature.SupportArrayToBean)
    private static class TestBean1 {
      private String name;

      private String password;

      private String country;

            

Reported by PMD.

Returning 'location' may expose an internal array.
Design

Line: 122

                    }

      public int[] getLocation() {
        return location;
      }

      @JSONField(ordinal = 3)
      public void setLocation(int[] location) {
        this.location = location;

            

Reported by PMD.

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

Line: 126

                    }

      @JSONField(ordinal = 3)
      public void setLocation(int[] location) {
        this.location = location;
      }
    }
}

            

Reported by PMD.

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

Line: 79

                    }

      @JSONField(ordinal = 3)
      public void setLocation(int[] location) {
        this.location = location;
      }
    }
    
    @JSONType(parseFeatures = Feature.SupportArrayToBean)

            

Reported by PMD.

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

Line: 126

                    }

      @JSONField(ordinal = 3)
      public void setLocation(int[] location) {
        this.location = location;
      }
    }
}

            

Reported by PMD.

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

Line: 21

                      jsonObject.put("value", Currency.getInstance("CNY"));

        String text = JSON.toJSONString(jsonObject, config);
        System.out.println(text);
        String str1 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"symbol\":\"CNY\"}}";
        String str2 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"symbol\":\"¥\"}}";
        String str3 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"numericCodeAsString\":\"156\",\"symbol\":\"CN¥\"}}";
        String str4 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"numericCodeAsString\":\"156\",\"symbol\":\"¥\"}}";
        assertTrue(text.equals(str1)

            

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

    public void test_0() throws Exception {
        SerializeConfig config = new SerializeConfig();
        config.put(Currency.class
                , config.createJavaBeanSerializer(Currency.class));

        JSONObject jsonObject = new JSONObject();

            

Reported by PMD.

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

Line: 12

              
public class CurrencyTest5 extends TestCase {

    public void test_0() throws Exception {
        SerializeConfig config = new SerializeConfig();
        config.put(Currency.class
                , config.createJavaBeanSerializer(Currency.class));

        JSONObject jsonObject = new JSONObject();

            

Reported by PMD.

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

Line: 26

                      String str2 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"symbol\":\"¥\"}}";
        String str3 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"numericCodeAsString\":\"156\",\"symbol\":\"CN¥\"}}";
        String str4 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"numericCodeAsString\":\"156\",\"symbol\":\"¥\"}}";
        assertTrue(text.equals(str1)
                || text.equals(str2)
                || text.equals(str3)
                || text.equals(str4));

        Currency currency = JSON.parseObject(text, VO.class).value;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                      String str2 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"symbol\":\"¥\"}}";
        String str3 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"numericCodeAsString\":\"156\",\"symbol\":\"CN¥\"}}";
        String str4 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"numericCodeAsString\":\"156\",\"symbol\":\"¥\"}}";
        assertTrue(text.equals(str1)
                || text.equals(str2)
                || text.equals(str3)
                || text.equals(str4));

        Currency currency = JSON.parseObject(text, VO.class).value;

            

Reported by PMD.

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

Line: 27

                      String str3 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"numericCodeAsString\":\"156\",\"symbol\":\"CN¥\"}}";
        String str4 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"numericCodeAsString\":\"156\",\"symbol\":\"¥\"}}";
        assertTrue(text.equals(str1)
                || text.equals(str2)
                || text.equals(str3)
                || text.equals(str4));

        Currency currency = JSON.parseObject(text, VO.class).value;


            

Reported by PMD.

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

Line: 28

                      String str4 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民币\",\"numericCodeAsString\":\"156\",\"symbol\":\"¥\"}}";
        assertTrue(text.equals(str1)
                || text.equals(str2)
                || text.equals(str3)
                || text.equals(str4));

        Currency currency = JSON.parseObject(text, VO.class).value;

        assertSame(Currency.getInstance("CNY"), currency);

            

Reported by PMD.

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

Line: 29

                      assertTrue(text.equals(str1)
                || text.equals(str2)
                || text.equals(str3)
                || text.equals(str4));

        Currency currency = JSON.parseObject(text, VO.class).value;

        assertSame(Currency.getInstance("CNY"), currency);
    }

            

Reported by PMD.

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

Line: 31

                              || text.equals(str3)
                || text.equals(str4));

        Currency currency = JSON.parseObject(text, VO.class).value;

        assertSame(Currency.getInstance("CNY"), currency);
    }

    public static class VO {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

              
        Currency currency = JSON.parseObject(text, VO.class).value;

        assertSame(Currency.getInstance("CNY"), currency);
    }

    public static class VO {
        public Currency value;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1300/Issue1303.java
10 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 kimmking on 02/07/2017.
 */
public class Issue1303 extends TestCase {
    public void test_for_issue() {
        String jsonString = "[{\"author\":{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"a876c49c18\"},\"createdAt\":\"2017-07-02 20:06:13\",\"imgurl\":\"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=11075891,34401011&fm=117&gp=0.jpg\",\"name\":\"衣架\",\"objectId\":\"029d5493cd\",\"prices\":\"1\",\"updatedAt\":\"2017-07-02 20:06:13\"}]";
        JSONArray jsonArray = JSON.parseArray(jsonString);
        //jsonArray = new JSONArray(jsonArray);//这一句打开也一样是正确的
        double total = 0;
        for (int i = 0; i <jsonArray.size() ; i++) {

            

Reported by PMD.

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

Line: 16

               * Created by kimmking on 02/07/2017.
 */
public class Issue1303 extends TestCase {
    public void test_for_issue() {
        String jsonString = "[{\"author\":{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"a876c49c18\"},\"createdAt\":\"2017-07-02 20:06:13\",\"imgurl\":\"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=11075891,34401011&fm=117&gp=0.jpg\",\"name\":\"衣架\",\"objectId\":\"029d5493cd\",\"prices\":\"1\",\"updatedAt\":\"2017-07-02 20:06:13\"}]";
        JSONArray jsonArray = JSON.parseArray(jsonString);
        //jsonArray = new JSONArray(jsonArray);//这一句打开也一样是正确的
        double total = 0;
        for (int i = 0; i <jsonArray.size() ; i++) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                      double total = 0;
        for (int i = 0; i <jsonArray.size() ; i++) {
            JSONObject object=jsonArray.getJSONObject(i);
            assertEquals("衣架",object.getString("name"));
            total=total+ Double.valueOf(object.getString("prices"));
        }
        assertEquals(1.0d,total);
    }
}

            

Reported by PMD.

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

Line: 23

                      double total = 0;
        for (int i = 0; i <jsonArray.size() ; i++) {
            JSONObject object=jsonArray.getJSONObject(i);
            assertEquals("衣架",object.getString("name"));
            total=total+ Double.valueOf(object.getString("prices"));
        }
        assertEquals(1.0d,total);
    }
}

            

Reported by PMD.

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

Line: 24

                      for (int i = 0; i <jsonArray.size() ; i++) {
            JSONObject object=jsonArray.getJSONObject(i);
            assertEquals("衣架",object.getString("name"));
            total=total+ Double.valueOf(object.getString("prices"));
        }
        assertEquals(1.0d,total);
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                          assertEquals("衣架",object.getString("name"));
            total=total+ Double.valueOf(object.getString("prices"));
        }
        assertEquals(1.0d,total);
    }
}

            

Reported by PMD.

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

Line: 6

              import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.util.TypeUtils;
import junit.framework.TestCase;
import org.junit.Assert;


            

Reported by PMD.

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

Line: 7

              import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.util.TypeUtils;
import junit.framework.TestCase;
import org.junit.Assert;

/**

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.util.TypeUtils'
Design

Line: 8

              import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.util.TypeUtils;
import junit.framework.TestCase;
import org.junit.Assert;

/**
 * Created by kimmking on 02/07/2017.

            

Reported by PMD.

Avoid unused imports such as 'org.junit.Assert'
Design

Line: 10

              import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.util.TypeUtils;
import junit.framework.TestCase;
import org.junit.Assert;

/**
 * Created by kimmking on 02/07/2017.
 */
public class Issue1303 extends TestCase {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/mixins/MixinSerForFieldsTest.java
10 issues
No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.
Design

Line: 20

                      }
    }

    abstract class MixIn {
        @JSONField(serialize = false)
        public String a;
        @JSONField(name = "banana")
        public String b;
    }

            

Reported by PMD.

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

Line: 11

              
public class MixinSerForFieldsTest extends TestCase {
    static class BeanClass {
        public String a;
        public String b;

        public BeanClass(String a, String b) {
            this.a = a;
            this.b = b;

            

Reported by PMD.

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

Line: 12

              public class MixinSerForFieldsTest extends TestCase {
    static class BeanClass {
        public String a;
        public String b;

        public BeanClass(String a, String b) {
            this.a = a;
            this.b = b;
        }

            

Reported by PMD.

This abstract class does not have any abstract methods
Design

Line: 20

                      }
    }

    abstract class MixIn {
        @JSONField(serialize = false)
        public String a;
        @JSONField(name = "banana")
        public String b;
    }

            

Reported by PMD.

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

Line: 27

                      public String b;
    }

    public void test() throws Exception{
        BeanClass bean = new BeanClass("1", "2");

        JSON.addMixInAnnotations(BeanClass.class, MixIn.class);
        String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);

            

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 String b;
    }

    public void test() throws Exception{
        BeanClass bean = new BeanClass("1", "2");

        JSON.addMixInAnnotations(BeanClass.class, MixIn.class);
        String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);

            

Reported by PMD.

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

Line: 33

                      JSON.addMixInAnnotations(BeanClass.class, MixIn.class);
        String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);
        assertEquals(1, result.size());
        assertEquals("2", result.get("banana"));
        JSON.removeMixInAnnotations(BeanClass.class);
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                      JSON.addMixInAnnotations(BeanClass.class, MixIn.class);
        String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);
        assertEquals(1, result.size());
        assertEquals("2", result.get("banana"));
        JSON.removeMixInAnnotations(BeanClass.class);
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

                      String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);
        assertEquals(1, result.size());
        assertEquals("2", result.get("banana"));
        JSON.removeMixInAnnotations(BeanClass.class);
    }
}

            

Reported by PMD.

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

Line: 34

                      String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);
        assertEquals(1, result.size());
        assertEquals("2", result.get("banana"));
        JSON.removeMixInAnnotations(BeanClass.class);
    }
}

            

Reported by PMD.

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

Line: 26

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

        ParserConfig parserConfig = new ParserConfig();
        parserConfig.addAccept("com.alibaba.json.bvt");

            

Reported by PMD.

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

Line: 15

              import com.alibaba.fastjson.serializer.SerializerFeature;

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

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

            

Reported by PMD.

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

Line: 16

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

    public void test_list() throws Exception {
        A a = new A();
        Set<B> set = new LinkedHashSet<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: 19

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

    public void test_list() throws Exception {
        A a = new A();
        Set<B> set = new LinkedHashSet<B>();
        set.add(new B());
        set.add(new B1());
        a.setList(set);

            

Reported by PMD.

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

Line: 34

                      parserConfig.addAccept("com.alibaba.json.bvt");
        A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

            

Reported by PMD.

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

Line: 34

                      parserConfig.addAccept("com.alibaba.json.bvt");
        A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

            

Reported by PMD.

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

Line: 35

                      A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {


            

Reported by PMD.

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

Line: 35

                      A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);

        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {


            

Reported by PMD.

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

Line: 36

              
        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

        private Set<B> list;

            

Reported by PMD.

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

Line: 36

              
        Assert.assertEquals(2, a1.getList().size());
        Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
        Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
    }

    private static class A {

        private Set<B> list;

            

Reported by PMD.

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

Line: 19

                      final AtomicInteger count = new AtomicInteger(0);
        ExtraProcessor extraProcessor = new ExtraProcessor() {
            public void processExtra(Object object, String key, Object value) {
                System.out.println("setter not found, class " + object.getClass().getName() + ", property " + key);
                count.incrementAndGet();
            }
        };



            

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 kimmking on 15/06/2017.
 */
public class Issue1271 extends TestCase {
    public void test_for_issue() throws Exception {

        String json = "{\"a\":1,\"b\":2}";

        final AtomicInteger count = new AtomicInteger(0);
        ExtraProcessor extraProcessor = new ExtraProcessor() {

            

Reported by PMD.

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

Line: 12

               * Created by kimmking on 15/06/2017.
 */
public class Issue1271 extends TestCase {
    public void test_for_issue() throws Exception {

        String json = "{\"a\":1,\"b\":2}";

        final AtomicInteger count = new AtomicInteger(0);
        ExtraProcessor extraProcessor = new ExtraProcessor() {

            

Reported by PMD.

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

Line: 19

                      final AtomicInteger count = new AtomicInteger(0);
        ExtraProcessor extraProcessor = new ExtraProcessor() {
            public void processExtra(Object object, String key, Object value) {
                System.out.println("setter not found, class " + object.getClass().getName() + ", property " + key);
                count.incrementAndGet();
            }
        };



            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

              

        A a = JSON.parseObject(json,A.class,extraProcessor);
        assertEquals(1,a.a);
        assertEquals(1, count.intValue());

        B b = JSON.parseObject(json,B.class,extraProcessor);
        assertEquals(1,b.a);
        assertEquals(2, count.intValue());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

              
        A a = JSON.parseObject(json,A.class,extraProcessor);
        assertEquals(1,a.a);
        assertEquals(1, count.intValue());

        B b = JSON.parseObject(json,B.class,extraProcessor);
        assertEquals(1,b.a);
        assertEquals(2, count.intValue());


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 30

                      assertEquals(1, count.intValue());

        B b = JSON.parseObject(json,B.class,extraProcessor);
        assertEquals(1,b.a);
        assertEquals(2, count.intValue());

    }

    public static class A {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 31

              
        B b = JSON.parseObject(json,B.class,extraProcessor);
        assertEquals(1,b.a);
        assertEquals(2, count.intValue());

    }

    public static class A {
        public int a;

            

Reported by PMD.

It is somewhat confusing to have a field name matching the declaring class name
Error

Line: 36

                  }

    public static class A {
        public int a;
    }

    public static class B {
        private int a;


            

Reported by PMD.

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

Line: 36

                  }

    public static class A {
        public int a;
    }

    public static class B {
        private int a;


            

Reported by PMD.

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

Line: 15

                  public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());

        assertEquals("{\"id\":1001}", JSON.toJSONString(model));

            

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 07/08/2017.
 */
public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());

            

Reported by PMD.

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

Line: 12

               * Created by wenshao on 07/08/2017.
 */
public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());

            

Reported by PMD.

The String literal '{\'id\':1001}' appears 4 times in this file; the first occurrence is on line 13
Error

Line: 13

               */
public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());

            

Reported by PMD.

Avoid unused local variables such as 'model2'.
Design

Line: 14

              public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());


            

Reported by PMD.

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

Line: 15

                  public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());

        assertEquals("{\"id\":1001}", JSON.toJSONString(model));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              //        System.out.println(model.getClass());
//        System.out.println(model2.getClass());

        assertEquals("{\"id\":1001}", JSON.toJSONString(model));
        assertEquals("{\"id\":1001}", JSON.toJSONString(model));

    }

    public static interface Model {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

              //        System.out.println(model2.getClass());

        assertEquals("{\"id\":1001}", JSON.toJSONString(model));
        assertEquals("{\"id\":1001}", JSON.toJSONString(model));

    }

    public static interface Model {
        int getId();

            

Reported by PMD.

Avoid unused imports such as 'java.lang.reflect.Proxy'
Design

Line: 6

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

import java.lang.reflect.Proxy;

/**
 * Created by wenshao on 07/08/2017.
 */
public class ProxyTest2 extends TestCase {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'model2' (lines '14'-'23').
Error

Line: 14

              public class ProxyTest2 extends TestCase {
    public void test_0() throws Exception {
        Model model = JSON.parseObject("{\"id\":1001}", Model.class);
        Model model2 = JSON.parseObject("{\"id\":1001}", Model.class);
        System.out.println(model.getId());

//        System.out.println(model.getClass());
//        System.out.println(model2.getClass());


            

Reported by PMD.