The following issues were found

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/fastjson/codegen/ClassGen.java
10 issues
This class has too many methods, consider refactoring it.
Design

Line: 6

              import java.io.IOException;
import java.lang.reflect.Type;

public abstract class ClassGen {

    protected Class<?>   clazz;
    protected Type       type;
    protected Appendable out;


            

Reported by PMD.

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

Line: 8

              
public abstract class ClassGen {

    protected Class<?>   clazz;
    protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

            

Reported by PMD.

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

Line: 9

              public abstract class ClassGen {

    protected Class<?>   clazz;
    protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;


            

Reported by PMD.

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

Line: 10

              
    protected Class<?>   clazz;
    protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){

            

Reported by PMD.

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

Line: 12

                  protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){
        this(clazz, null, out);
    }

            

Reported by PMD.

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

Line: 12

                  protected Type       type;
    protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){
        this(clazz, null, out);
    }

            

Reported by PMD.

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

Line: 13

                  protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){
        this(clazz, null, out);
    }


            

Reported by PMD.

Avoid using redundant field initializer for 'indentCount'
Performance

Line: 13

                  protected Appendable out;

    private String       indent      = "\t";
    private int          indentCount = 0;

    public ClassGen(Class<?> clazz, Appendable out){
        this(clazz, null, out);
    }


            

Reported by PMD.

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

Line: 44

              
    protected void printPackage() throws IOException {
        print("package ");
        print(clazz.getPackage().getName());
        println(";");
    }

    protected void beginClass(String className) throws IOException {
        print("public class ");

            

Reported by PMD.

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

Line: 102

                  
    protected void printClassName(Class<?> clazz) throws IOException {
        String name = clazz.getName();
        name = name.replace('$', '.');
        print(name);
    }
}

            

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/bug/Bug_for_NonStringKeyMap.java
10 issues
System.out.println is used
Design

Line: 22

                      vo.getMap().put(1L, new VAL());
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        System.out.println(text);
        
        JSON.parse(text);
    }
    
    public void test_1() throws Exception {

            

Reported by PMD.

System.out.println is used
Design

Line: 33

                      submap.put("subkey", "subvalue");
        map.put(submap, "value");
        String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        System.out.println(jsonString);
        Object object = JSON.parse(jsonString);
        System.out.println(object.toString());
    }

    public static class VO {

            

Reported by PMD.

System.out.println is used
Design

Line: 35

                      String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        System.out.println(jsonString);
        Object object = JSON.parse(jsonString);
        System.out.println(object.toString());
    }

    public static class VO {

        private Map<Long, VAL> map = new HashMap<Long, VAL>();

            

Reported by PMD.

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

Line: 13

              import junit.framework.TestCase;

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

    public void test_bug() throws Exception {
        VO vo = new VO();

            

Reported by PMD.

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

Line: 14

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

    public void test_bug() throws Exception {
        VO vo = new VO();
        vo.getMap().put(1L, new VAL());

            

Reported by PMD.

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

Line: 17

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

    public void test_bug() throws Exception {
        VO vo = new VO();
        vo.getMap().put(1L, new VAL());
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        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: 17

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

    public void test_bug() throws Exception {
        VO vo = new VO();
        vo.getMap().put(1L, new VAL());
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        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: 27

                      JSON.parse(text);
    }
    
    public void test_1() throws Exception {
        Map<Map<String, String>, String> map = new HashMap<Map<String, String>, String>();
        Map<String, String> submap = new HashMap<String, String>();
        submap.put("subkey", "subvalue");
        map.put(submap, "value");
        String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 27

                      JSON.parse(text);
    }
    
    public void test_1() throws Exception {
        Map<Map<String, String>, String> map = new HashMap<Map<String, String>, String>();
        Map<String, String> submap = new HashMap<String, String>();
        submap.put("subkey", "subvalue");
        map.put(submap, "value");
        String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 35

                      String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);
        System.out.println(jsonString);
        Object object = JSON.parse(jsonString);
        System.out.println(object.toString());
    }

    public static class VO {

        private Map<Long, VAL> map = new HashMap<Long, VAL>();

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/EnumerationSerializer.java
10 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 21

                      }
        
        Type elementType = null;
        if (out.isEnabled(SerializerFeature.WriteClassName)) {
            if (fieldType instanceof ParameterizedType) {
                ParameterizedType param = (ParameterizedType) fieldType;
                elementType = param.getActualTypeArguments()[0];
            }
        }

            

Reported by PMD.

These nested if statements could be combined
Design

Line: 22

                      
        Type elementType = null;
        if (out.isEnabled(SerializerFeature.WriteClassName)) {
            if (fieldType instanceof ParameterizedType) {
                ParameterizedType param = (ParameterizedType) fieldType;
                elementType = param.getActualTypeArguments()[0];
            }
        }
        

            

Reported by PMD.

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

Line: 24

                      if (out.isEnabled(SerializerFeature.WriteClassName)) {
            if (fieldType instanceof ParameterizedType) {
                ParameterizedType param = (ParameterizedType) fieldType;
                elementType = param.getActualTypeArguments()[0];
            }
        }
        
        Enumeration<?> e = (Enumeration<?>) object;
        

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 38

                          out.append('[');
            while (e.hasMoreElements()) {
                Object item = e.nextElement();
                if (i++ != 0) {
                    out.append(',');
                }

                if (item == null) {
                    out.writeNull();

            

Reported by PMD.

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

Line: 47

                                  continue;
                }

                ObjectSerializer itemSerializer = serializer.getObjectWriter(item.getClass());
                itemSerializer.write(serializer, item, i - 1, elementType, 0);
            }
            out.append(']');
        } finally {
            serializer.context = context;

            

Reported by PMD.

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

Line: 48

                              }

                ObjectSerializer itemSerializer = serializer.getObjectWriter(item.getClass());
                itemSerializer.write(serializer, item, i - 1, elementType, 0);
            }
            out.append(']');
        } finally {
            serializer.context = context;
        }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'elementType' (lines '20'-'24').
Error

Line: 20

                          return;
        }
        
        Type elementType = null;
        if (out.isEnabled(SerializerFeature.WriteClassName)) {
            if (fieldType instanceof ParameterizedType) {
                ParameterizedType param = (ParameterizedType) fieldType;
                elementType = param.getActualTypeArguments()[0];
            }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'elementType' (lines '20'-'54').
Error

Line: 20

                          return;
        }
        
        Type elementType = null;
        if (out.isEnabled(SerializerFeature.WriteClassName)) {
            if (fieldType instanceof ParameterizedType) {
                ParameterizedType param = (ParameterizedType) fieldType;
                elementType = param.getActualTypeArguments()[0];
            }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'elementType' (lines '24'-'54').
Error

Line: 24

                      if (out.isEnabled(SerializerFeature.WriteClassName)) {
            if (fieldType instanceof ParameterizedType) {
                ParameterizedType param = (ParameterizedType) fieldType;
                elementType = param.getActualTypeArguments()[0];
            }
        }
        
        Enumeration<?> e = (Enumeration<?>) object;
        

            

Reported by PMD.

Found 'DU'-anomaly for variable 'i' (lines '34'-'54').
Error

Line: 34

                      serializer.setContext(context, object, fieldName, 0);

        try {
            int i = 0;
            out.append('[');
            while (e.hasMoreElements()) {
                Object item = e.nextElement();
                if (i++ != 0) {
                    out.append(',');

            

Reported by PMD.

src/test/java/com/alibaba/json/bvtVO/IncomingDataPoint.java
10 issues
The class 'IncomingDataPoint' is suspected to be a Data Class (WOC=5.556%, NOPA=0, NOAM=14, WMC=20)
Design

Line: 19

                      orders = {"metric", "timestamp", "value", "tags", "tsuid", "granularity", "aggregator"},
        asm = true
        )
public class IncomingDataPoint {
    /** The incoming metric name */
    private String metric;

    /** The incoming timestamp in Unix epoch seconds or milliseconds */
    private long timestamp;

            

Reported by PMD.

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

Line: 33

                  private Map<String, String> tags;

    /** TSUID for the data point */
    private String tsuid;

    private String granularity;

    private String aggregator;


            

Reported by PMD.

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

Line: 56

                  public IncomingDataPoint(final String metric,
                             final long timestamp,
                             final String value,
                             final HashMap<String, String> tags,
                             final String granularity,
                             final String aggregator) {
        this.metric = metric;
        this.granularity = granularity;
        this.timestamp = timestamp;

            

Reported by PMD.

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

Line: 88

                   */
    @Override
    public String toString() {
        final StringBuilder buf = new StringBuilder();
        buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 89

                  @Override
    public String toString() {
        final StringBuilder buf = new StringBuilder();
        buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);
        if (this.tags != null) {

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 90

                  public String toString() {
        final StringBuilder buf = new StringBuilder();
        buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 91

                      final StringBuilder buf = new StringBuilder();
        buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {
                buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 92

                      buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {
                buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());
            }

            

Reported by PMD.

Avoid appending characters as strings in StringBuffer.append.
Performance

Line: 96

                      buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {
                buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());
            }
        }
        return buf.toString();
    }


            

Reported by PMD.

Avoid appending characters as strings in StringBuffer.append.
Performance

Line: 96

                      buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {
                buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());
            }
        }
        return buf.toString();
    }


            

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/bug/Issue1017.java
10 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 13

               * Created by wenshao on 11/02/2017.
 */
public class Issue1017 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());

            

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

               * Created by wenshao on 11/02/2017.
 */
public class Issue1017 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {

            

Reported by PMD.

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

Line: 18

              
        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;

            

Reported by PMD.

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

Line: 19

                      User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;

            

Reported by PMD.

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

Line: 20

                      assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 23

                      assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {
            return pictureList;
        }
        public User setPictureList(List<String> pictureList) {

            

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/bvtVO/IncomingDataPoint_double.java
10 issues
The class 'IncomingDataPoint_double' is suspected to be a Data Class (WOC=5.556%, NOPA=0, NOAM=14, WMC=20)
Design

Line: 19

                      orders = {"metric", "timestamp", "value", "tags", "tsuid", "granularity", "aggregator"},
        asm = true
        )
public class IncomingDataPoint_double {
    /** The incoming metric name */
    private String metric;

    /** The incoming timestamp in Unix epoch seconds or milliseconds */
    private long timestamp;

            

Reported by PMD.

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

Line: 33

                  private Map<String, String> tags;

    /** TSUID for the data point */
    private String tsuid;

    private String granularity;

    private String aggregator;


            

Reported by PMD.

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

Line: 56

                  public IncomingDataPoint_double(final String metric,
                                    final long timestamp,
                                    final double value,
                                    final HashMap<String, String> tags,
                                    final String granularity,
                                    final String aggregator) {
        this.metric = metric;
        this.granularity = granularity;
        this.timestamp = timestamp;

            

Reported by PMD.

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

Line: 88

                   */
    @Override
    public String toString() {
        final StringBuilder buf = new StringBuilder();
        buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 89

                  @Override
    public String toString() {
        final StringBuilder buf = new StringBuilder();
        buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);
        if (this.tags != null) {

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 90

                  public String toString() {
        final StringBuilder buf = new StringBuilder();
        buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 91

                      final StringBuilder buf = new StringBuilder();
        buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {
                buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());

            

Reported by PMD.

StringBuffer (or StringBuilder).append is called consecutively without reusing the target variable.
Performance

Line: 92

                      buf.append(" metric=").append(this.metric);
        buf.append(" granularity=").append(this.granularity);
        buf.append(" aggregator=").append(this.aggregator);
        buf.append(" ts=").append(this.timestamp);
        buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {
                buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());
            }

            

Reported by PMD.

Avoid appending characters as strings in StringBuffer.append.
Performance

Line: 96

                      buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {
                buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());
            }
        }
        return buf.toString();
    }


            

Reported by PMD.

Avoid appending characters as strings in StringBuffer.append.
Performance

Line: 96

                      buf.append(" value=").append(this.value);
        if (this.tags != null) {
            for (Map.Entry<String, String> entry : this.tags.entrySet()) {
                buf.append(" ").append(entry.getKey()).append("=").append(entry.getValue());
            }
        }
        return buf.toString();
    }


            

Reported by PMD.