The following issues were found

src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_630.java
19 issues
JUnit tests should include assert() or fail()
Design

Line: 14

              
public class Bug_for_issue_630 extends TestCase {

    public void test_for_issue_null() throws Exception {
        Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;

            

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

              
public class Bug_for_issue_630 extends TestCase {

    public void test_for_issue_null() throws Exception {
        Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 17

                  public void test_for_issue_null() throws Exception {
        Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;
//        model.persons = new ArrayList<Person>();
//        model.persons.add(new Person());
        

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 18

                      Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;
//        model.persons = new ArrayList<Person>();
//        model.persons.add(new Person());
        
        String str = JSON.toJSONString(model, SerializerFeature.BeanToArray);

            

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

                      JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
    }
    
    public void test_for_issue_empty() throws Exception {
        Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;

            

Reported by PMD.

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

Line: 28

                      JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
    }
    
    public void test_for_issue_empty() throws Exception {
        Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 31

                  public void test_for_issue_empty() throws Exception {
        Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;
        model.persons = new ArrayList<Person>();
//        model.persons.add(new Person());
        

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 32

                      Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;
        model.persons = new ArrayList<Person>();
//        model.persons.add(new Person());
        
        String str = JSON.toJSONString(model, SerializerFeature.BeanToArray);

            

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

                      JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
    }
    
    public void test_for_issue_one() throws Exception {
        Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;

            

Reported by PMD.

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

Line: 42

                      JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
    }
    
    public void test_for_issue_one() throws Exception {
        Model model = new Model();
        model.id = 123;
        model.name = null;
        model.modelName = null;
        model.isFlay = false;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_scanSymbol.java
19 issues
This class has too many methods, consider refactoring it.
Design

Line: 19

               * 
 * @author wenshao[szujobs@hotmail.com]
 */
public class JSONScannerTest_scanSymbol extends TestCase {

    public void test_0() throws Exception {
        JSONScanner lexer = new JSONScanner("\"value\":\"aa\\n\"");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
        assertEquals(0, hashCode);

            

Reported by PMD.

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

Line: 21

               */
public class JSONScannerTest_scanSymbol extends TestCase {

    public void test_0() throws Exception {
        JSONScanner lexer = new JSONScanner("\"value\":\"aa\\n\"");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
        assertEquals(0, hashCode);
        Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
    }

            

Reported by PMD.

The String literal '\'value\':' appears 11 times in this file; the first occurrence is on line 23
Error

Line: 23

              
    public void test_0() throws Exception {
        JSONScanner lexer = new JSONScanner("\"value\":\"aa\\n\"");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
        assertEquals(0, hashCode);
        Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
    }

    public void test_1() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                  public void test_0() throws Exception {
        JSONScanner lexer = new JSONScanner("\"value\":\"aa\\n\"");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
        assertEquals(0, hashCode);
        Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
    }

    public void test_1() throws Exception {
        JSONScanner lexer = new JSONScanner("\"value\":\"aa\"},");

            

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

                      Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
    }

    public void test_1() throws Exception {
        JSONScanner lexer = new JSONScanner("\"value\":\"aa\"},");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
        Assert.assertEquals(fnv_hash("aa"), hashCode);
        Assert.assertEquals(JSONScanner.END, lexer.matchStat());
        Assert.assertEquals(JSONToken.COMMA, lexer.token());

            

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

                      Assert.assertEquals(JSONToken.COMMA, lexer.token());
    }
    
    public void test_2() throws Exception {
        JSONScanner lexer = new JSONScanner("\"value\":\"aa\"}]");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
        Assert.assertEquals(fnv_hash("aa"), hashCode);
        Assert.assertEquals(JSONScanner.END, lexer.matchStat());
        Assert.assertEquals(JSONToken.RBRACKET, lexer.token());

            

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

                      Assert.assertEquals(JSONToken.RBRACKET, lexer.token());
    }
    
    public void test_3() throws Exception {
        JSONScanner lexer = new JSONScanner("\"value\":\"aa\"}}");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
        Assert.assertEquals(fnv_hash("aa"), hashCode);
        Assert.assertEquals(JSONScanner.END, lexer.matchStat());
        Assert.assertEquals(JSONToken.RBRACE, lexer.token());

            

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

                      Assert.assertEquals(JSONToken.RBRACE, lexer.token());
    }
    
    public void test_4() throws Exception {
    	JSONScanner lexer = new JSONScanner("\"value\":\"aa\"}");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
    	Assert.assertEquals(fnv_hash("aa"), hashCode);
    	Assert.assertEquals(JSONScanner.END, lexer.matchStat());
    	Assert.assertEquals(JSONToken.EOF, lexer.token());

            

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

                  	Assert.assertEquals(JSONToken.EOF, lexer.token());
    }
    
    public void test_6() throws Exception {
    	JSONScanner lexer = new JSONScanner("\"value\":\"aa\"}{");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
    	Assert.assertEquals(0, hashCode);
    	Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
    }

            

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

                  	Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
    }
    
    public void test_7() throws Exception {
    	JSONScanner lexer = new JSONScanner("\"value\":\"aa\"");
        long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
    	Assert.assertEquals(0, hashCode);
    	Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
    }

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/JSONPatch.java
19 issues
Avoid using a branching statement as the last in a loop.
Error

Line: 73

                          if (JSONScanner.isWhitespace(ch)) {
                continue;
            }
            return ch == '{';
        }

        return false;
    }


            

Reported by PMD.

The class 'JSONPatch' has a Standard Cyclomatic Complexity of 6 (Highest = 11).
Design

Line: 8

              import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.JSONScanner;

public class JSONPatch {
    public static String apply(String original, String patch) {
        Object object
                = apply(
                        JSON.parse(original, Feature.OrderedField), patch);
        return JSON.toJSONString(object);

            

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

              import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.JSONScanner;

public class JSONPatch {
    public static String apply(String original, String patch) {
        Object object
                = apply(
                        JSON.parse(original, Feature.OrderedField), patch);
        return JSON.toJSONString(object);

            

Reported by PMD.

The method 'apply' has a Standard Cyclomatic Complexity of 11.
Design

Line: 16

                      return JSON.toJSONString(object);
    }

    public static Object apply(Object object, String patch) {
        Operation[] operations;
        if (isObject(patch)) {
            operations = new Operation[] {
                    JSON.parseObject(patch, Operation.class)};
        } else {

            

Reported by PMD.

The method 'apply(Object, String)' has a cyclomatic complexity of 13.
Design

Line: 16

                      return JSON.toJSONString(object);
    }

    public static Object apply(Object object, String patch) {
        Operation[] operations;
        if (isObject(patch)) {
            operations = new Operation[] {
                    JSON.parseObject(patch, Operation.class)};
        } else {

            

Reported by PMD.

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

Line: 29

                          JSONPath path = JSONPath.compile(op.path);
            switch (op.type) {
                case add:
                    path.patchAdd(object, op.value, false);
                    break;
                case replace:
                    path.patchAdd(object, op.value, true);
                    break;
                case remove:

            

Reported by PMD.

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

Line: 32

                                  path.patchAdd(object, op.value, false);
                    break;
                case replace:
                    path.patchAdd(object, op.value, true);
                    break;
                case remove:
                    path.remove(object);
                    break;
                case copy:

            

Reported by PMD.

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

Line: 35

                                  path.patchAdd(object, op.value, true);
                    break;
                case remove:
                    path.remove(object);
                    break;
                case copy:
                case move:
                    JSONPath from = JSONPath.compile(op.from);
                    Object fromValue = from.eval(object);

            

Reported by PMD.

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

Line: 40

                              case copy:
                case move:
                    JSONPath from = JSONPath.compile(op.from);
                    Object fromValue = from.eval(object);
                    if (op.type == OperationType.move) {
                        boolean success = from.remove(object);
                        if (!success) {
                            throw new JSONException("json patch move error : " + op.from + " -> " + op.path);
                        }

            

Reported by PMD.

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

Line: 42

                                  JSONPath from = JSONPath.compile(op.from);
                    Object fromValue = from.eval(object);
                    if (op.type == OperationType.move) {
                        boolean success = from.remove(object);
                        if (!success) {
                            throw new JSONException("json patch move error : " + op.from + " -> " + op.path);
                        }
                    }
                    path.set(object, fromValue);

            

Reported by PMD.

src/test/java/com/alibaba/json/test/codec/Jackson2AfterBurnCodec.java
19 issues
Avoid throwing raw exception types.
Design

Line: 33

                      try {
            return mapper.readValue(text, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    

    public <T> T decodeObject(byte[] input, Class<T> clazz) throws Exception {

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 42

                      try {
            return mapper.readValue(input, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception {
        try {

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 51

                          return (Collection<T>) mapper.readValue(text, new TypeReference<T>() {
            });
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public final Object decodeObject(String text) {
        try {

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 59

                      try {
            return (ObjectNode) mapper.readTree(text);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public Object decode(String text) {
        try {

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 67

                      try {
            return mapper.readTree(text);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public String encode(Object object) throws Exception {
        return mapper.writeValueAsString(object);

            

Reported by PMD.

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

Line: 19

              
public class Jackson2AfterBurnCodec implements Codec {

    private ObjectMapper mapper = new ObjectMapper();
    
    public Jackson2AfterBurnCodec() {
        mapper.registerModule(new AfterburnerModule());
    }


            

Reported by PMD.

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

Line: 19

              
public class Jackson2AfterBurnCodec implements Codec {

    private ObjectMapper mapper = new ObjectMapper();
    
    public Jackson2AfterBurnCodec() {
        mapper.registerModule(new AfterburnerModule());
    }


            

Reported by PMD.

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

Line: 32

                  public final <T> T decodeObject(String text, Class<T> clazz) {
        try {
            return mapper.readValue(text, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    


            

Reported by PMD.

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

Line: 38

                  }
    

    public <T> T decodeObject(byte[] input, Class<T> clazz) throws Exception {
        try {
            return mapper.readValue(input, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }

            

Reported by PMD.

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

Line: 41

                  public <T> T decodeObject(byte[] input, Class<T> clazz) throws Exception {
        try {
            return mapper.readValue(input, clazz);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception {

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/util/ServiceLoader.java
19 issues
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: 13

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

public class ServiceLoader {

    private static final String      PREFIX     = "META-INF/services/";

    private static final Set<String> loadedUrls = new HashSet<String>();


            

Reported by PMD.

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

Line: 34

              
        try {
            Enumeration<URL> urls = classLoader.getResources(path);
            while (urls.hasMoreElements()) {
                URL url = urls.nextElement();
                if (loadedUrls.contains(url.toString())) {
                    continue;
                }
                load(url, serviceNames);

            

Reported by PMD.

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

Line: 35

                      try {
            Enumeration<URL> urls = classLoader.getResources(path);
            while (urls.hasMoreElements()) {
                URL url = urls.nextElement();
                if (loadedUrls.contains(url.toString())) {
                    continue;
                }
                load(url, serviceNames);
                loadedUrls.add(url.toString());

            

Reported by PMD.

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

Line: 36

                          Enumeration<URL> urls = classLoader.getResources(path);
            while (urls.hasMoreElements()) {
                URL url = urls.nextElement();
                if (loadedUrls.contains(url.toString())) {
                    continue;
                }
                load(url, serviceNames);
                loadedUrls.add(url.toString());
            }

            

Reported by PMD.

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

Line: 40

                                  continue;
                }
                load(url, serviceNames);
                loadedUrls.add(url.toString());
            }
        } catch (Throwable ex) {
            // skip
        }


            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 42

                              load(url, serviceNames);
                loadedUrls.add(url.toString());
            }
        } catch (Throwable ex) {
            // skip
        }

        for (String serviceName : serviceNames) {
            try {

            

Reported by PMD.

A catch statement should never catch throwable since it includes errors.
Error

Line: 42

                              load(url, serviceNames);
                loadedUrls.add(url.toString());
            }
        } catch (Throwable ex) {
            // skip
        }

        for (String serviceName : serviceNames) {
            try {

            

Reported by PMD.

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

Line: 49

                      for (String serviceName : serviceNames) {
            try {
                Class<?> serviceClass = classLoader.loadClass(serviceName);
                T service = (T) serviceClass.newInstance();
                services.add(service);
            } catch (Exception e) {
                // skip
            }
        }

            

Reported by PMD.

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

Line: 51

                              Class<?> serviceClass = classLoader.loadClass(serviceName);
                T service = (T) serviceClass.newInstance();
                services.add(service);
            } catch (Exception e) {
                // skip
            }
        }

        return services;

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 51

                              Class<?> serviceClass = classLoader.loadClass(serviceName);
                T service = (T) serviceClass.newInstance();
                services.add(service);
            } catch (Exception e) {
                // skip
            }
        }

        return services;

            

Reported by PMD.

src/test/java/com/alibaba/json/test/UTF8Test.java
19 issues
System.out.println is used
Design

Line: 28

                  ByteBuffer byteBuffer;

    protected void setUp() throws Exception {
        System.out.println(System.getProperty("java.runtime.version"));
        byteBuffer = ByteBuffer.allocate(text.length() * 3);
    }

    public void test_encode() throws Exception {


            

Reported by PMD.

System.out.println is used
Design

Line: 54

                          text.getBytes(charset);
        }
        long millis = System.currentTimeMillis() - start;
        System.out.println("f0 millis : " + millis);
    }

    private void f1() throws Exception {
        long start = System.currentTimeMillis();
        for (int i = 0; i < COUNT; ++i) {

            

Reported by PMD.

System.out.println is used
Design

Line: 63

                          IOUtils.encodeUTF8(chars, 0, chars.length, bytes);
        }
        long millis = System.currentTimeMillis() - start;
        System.out.println("f1 millis : " + millis);
    }

    private void f2() throws Exception {
        long start = System.currentTimeMillis();
        for (int i = 0; i < COUNT; ++i) {

            

Reported by PMD.

System.out.println is used
Design

Line: 72

                          charset.newEncoder().encode(CharBuffer.wrap(chars));
        }
        long millis = System.currentTimeMillis() - start;
        System.out.println("f2 millis : " + millis);
    }
}

            

Reported by PMD.

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

Line: 14

               * Created by wenshao on 24/07/2017.
 */
public class UTF8Test extends TestCase {
    String T0 = "央视的报道《陆军第82集团军:聚合重塑 强军路上当先锋!》披露,从南昌起义到平江起义,从井冈山斗争到两万五千里长征,从首战平型关到历经三大战役,从穿插三所里到全歼美军北极熊团,22勇士飞夺泸定桥、18勇士强渡乌江、鏖战冀中“野八旅”、屡战屡胜“老虎连”、万岁军,一支支善战的部队,一个个滚烫的名字,熔铸成第82集团军新的灵魂。";
    String T1 = "Model and actress Emily Ratajkowski would you like you to know she has wonderful abs. We don’t know this because we’re psychic, but rather can surmise this desire from her many photos she posts on Instagram. Whether it’s due to genetics, diet, great Instagram techniques, or some combination of the above, the rising star takes ample opportunity to show you what she’s got, and her fans love it.";

    Charset charset = Charset.forName("UTF-8");
    String text = new StringBuilder().append(T0).append(System.currentTimeMillis()).toString();
    //String text = "Model and actress Emily Ratajkowski would you like you to know she has wonderful abs. We don’t know this because we’re psychic, but rather can surmise this desire from her many photos she posts on Instagram. Whether it’s due to genetics, diet, great Instagram techniques, or some combination of the above, the rising star takes ample opportunity to show you what she’s got, and her fans love it.";

            

Reported by PMD.

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

Line: 17

                  String T0 = "央视的报道《陆军第82集团军:聚合重塑 强军路上当先锋!》披露,从南昌起义到平江起义,从井冈山斗争到两万五千里长征,从首战平型关到历经三大战役,从穿插三所里到全歼美军北极熊团,22勇士飞夺泸定桥、18勇士强渡乌江、鏖战冀中“野八旅”、屡战屡胜“老虎连”、万岁军,一支支善战的部队,一个个滚烫的名字,熔铸成第82集团军新的灵魂。";
    String T1 = "Model and actress Emily Ratajkowski would you like you to know she has wonderful abs. We don’t know this because we’re psychic, but rather can surmise this desire from her many photos she posts on Instagram. Whether it’s due to genetics, diet, great Instagram techniques, or some combination of the above, the rising star takes ample opportunity to show you what she’s got, and her fans love it.";

    Charset charset = Charset.forName("UTF-8");
    String text = new StringBuilder().append(T0).append(System.currentTimeMillis()).toString();
    //String text = "Model and actress Emily Ratajkowski would you like you to know she has wonderful abs. We don’t know this because we’re psychic, but rather can surmise this desire from her many photos she posts on Instagram. Whether it’s due to genetics, diet, great Instagram techniques, or some combination of the above, the rising star takes ample opportunity to show you what she’s got, and her fans love it.";
    char[] chars = text.toCharArray();
    byte[] bytes = new byte[chars.length * 3];


            

Reported by PMD.

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

Line: 18

                  String T1 = "Model and actress Emily Ratajkowski would you like you to know she has wonderful abs. We don’t know this because we’re psychic, but rather can surmise this desire from her many photos she posts on Instagram. Whether it’s due to genetics, diet, great Instagram techniques, or some combination of the above, the rising star takes ample opportunity to show you what she’s got, and her fans love it.";

    Charset charset = Charset.forName("UTF-8");
    String text = new StringBuilder().append(T0).append(System.currentTimeMillis()).toString();
    //String text = "Model and actress Emily Ratajkowski would you like you to know she has wonderful abs. We don’t know this because we’re psychic, but rather can surmise this desire from her many photos she posts on Instagram. Whether it’s due to genetics, diet, great Instagram techniques, or some combination of the above, the rising star takes ample opportunity to show you what she’s got, and her fans love it.";
    char[] chars = text.toCharArray();
    byte[] bytes = new byte[chars.length * 3];



            

Reported by PMD.

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

Line: 20

                  Charset charset = Charset.forName("UTF-8");
    String text = new StringBuilder().append(T0).append(System.currentTimeMillis()).toString();
    //String text = "Model and actress Emily Ratajkowski would you like you to know she has wonderful abs. We don’t know this because we’re psychic, but rather can surmise this desire from her many photos she posts on Instagram. Whether it’s due to genetics, diet, great Instagram techniques, or some combination of the above, the rising star takes ample opportunity to show you what she’s got, and her fans love it.";
    char[] chars = text.toCharArray();
    byte[] bytes = new byte[chars.length * 3];



    ByteBuffer byteBuffer;

            

Reported by PMD.

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

Line: 21

                  String text = new StringBuilder().append(T0).append(System.currentTimeMillis()).toString();
    //String text = "Model and actress Emily Ratajkowski would you like you to know she has wonderful abs. We don’t know this because we’re psychic, but rather can surmise this desire from her many photos she posts on Instagram. Whether it’s due to genetics, diet, great Instagram techniques, or some combination of the above, the rising star takes ample opportunity to show you what she’s got, and her fans love it.";
    char[] chars = text.toCharArray();
    byte[] bytes = new byte[chars.length * 3];



    ByteBuffer byteBuffer;


            

Reported by PMD.

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

Line: 25

              


    ByteBuffer byteBuffer;

    protected void setUp() throws Exception {
        System.out.println(System.getProperty("java.runtime.version"));
        byteBuffer = ByteBuffer.allocate(text.length() * 3);
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/list/ListStringFieldTest_stream_array_2.java
19 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: 19

              
public class ListStringFieldTest_stream_array_2 extends TestCase {

    public void test_list() throws Exception {
        String text = "[[\"a\",null,\"b\",\"ab\\\\c\"],[]]";

        JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertEquals(4, model.values.size());

            

Reported by PMD.

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

Line: 24

              
        JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertEquals(4, model.values.size());
        Assert.assertEquals("a", model.values.get(0));
        Assert.assertEquals(null, model.values.get(1));
        Assert.assertEquals("b", model.values.get(2));
        Assert.assertEquals("ab\\c", model.values.get(3));
        

            

Reported by PMD.

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

Line: 25

                      JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertEquals(4, model.values.size());
        Assert.assertEquals("a", model.values.get(0));
        Assert.assertEquals(null, model.values.get(1));
        Assert.assertEquals("b", model.values.get(2));
        Assert.assertEquals("ab\\c", model.values.get(3));
        
        Assert.assertEquals(0, model.values2.size());

            

Reported by PMD.

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

Line: 26

                      Model model = reader.readObject(Model.class);
        Assert.assertEquals(4, model.values.size());
        Assert.assertEquals("a", model.values.get(0));
        Assert.assertEquals(null, model.values.get(1));
        Assert.assertEquals("b", model.values.get(2));
        Assert.assertEquals("ab\\c", model.values.get(3));
        
        Assert.assertEquals(0, model.values2.size());
    }

            

Reported by PMD.

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

Line: 27

                      Assert.assertEquals(4, model.values.size());
        Assert.assertEquals("a", model.values.get(0));
        Assert.assertEquals(null, model.values.get(1));
        Assert.assertEquals("b", model.values.get(2));
        Assert.assertEquals("ab\\c", model.values.get(3));
        
        Assert.assertEquals(0, model.values2.size());
    }
    

            

Reported by PMD.

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

Line: 28

                      Assert.assertEquals("a", model.values.get(0));
        Assert.assertEquals(null, model.values.get(1));
        Assert.assertEquals("b", model.values.get(2));
        Assert.assertEquals("ab\\c", model.values.get(3));
        
        Assert.assertEquals(0, model.values2.size());
    }
    
    public void test_list2() throws Exception {

            

Reported by PMD.

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

Line: 30

                      Assert.assertEquals("b", model.values.get(2));
        Assert.assertEquals("ab\\c", model.values.get(3));
        
        Assert.assertEquals(0, model.values2.size());
    }
    
    public void test_list2() throws Exception {
        String text = "{\"values\":[\"a\",null,\"b\",\"ab\\\\c\"],\"values2\":[]}";


            

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

                      Assert.assertEquals(0, model.values2.size());
    }
    
    public void test_list2() throws Exception {
        String text = "{\"values\":[\"a\",null,\"b\",\"ab\\\\c\"],\"values2\":[]}";

        JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertEquals(4, model.values.size());

            

Reported by PMD.

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

Line: 38

              
        JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertEquals(4, model.values.size());
        Assert.assertEquals("a", model.values.get(0));
        Assert.assertEquals(null, model.values.get(1));
        Assert.assertEquals("b", model.values.get(2));
        Assert.assertEquals("ab\\c", model.values.get(3));
        

            

Reported by PMD.

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

Line: 39

                      JSONReader reader = new JSONReader(new StringReader(text));
        Model model = reader.readObject(Model.class);
        Assert.assertEquals(4, model.values.size());
        Assert.assertEquals("a", model.values.get(0));
        Assert.assertEquals(null, model.values.get(1));
        Assert.assertEquals("b", model.values.get(2));
        Assert.assertEquals("ab\\c", model.values.get(3));
        
        Assert.assertEquals(0, model.values2.size());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONReaderTest_object_string.java
19 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 14

              
public class JSONReaderTest_object_string extends TestCase {

    String text = "{\"f0\":\"0\",\"f1\":\"1\",\"f2\":\"2\",\"f3\":\"3\",\"f4\":\"4\", " + //
                  "\"f5\":\"5\",\"f6\":\"6\",\"f7\":\"7\",\"f8\":\"8\",\"f9\":\"9\"}";

    public void test_read() throws Exception {

        JSONReader reader = new JSONReader(new StringReader(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

                  String text = "{\"f0\":\"0\",\"f1\":\"1\",\"f2\":\"2\",\"f3\":\"3\",\"f4\":\"4\", " + //
                  "\"f5\":\"5\",\"f6\":\"6\",\"f7\":\"7\",\"f8\":\"8\",\"f9\":\"9\"}";

    public void test_read() throws Exception {

        JSONReader reader = new JSONReader(new StringReader(text));

        reader.startObject();


            

Reported by PMD.

Avoid unused local variables such as 'key'.
Design

Line: 25

              
        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            String value = reader.readString();
            count++;
        }
        Assert.assertEquals(10, count);


            

Reported by PMD.

Avoid unused local variables such as 'value'.
Design

Line: 26

                      int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            String value = reader.readString();
            count++;
        }
        Assert.assertEquals(10, count);

        reader.endObject();

            

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

                      reader.close();
    }

    public void test_read_1() throws Exception {
        JSONReader reader = new JSONReader(new JSONScanner(text));

        reader.startObject();

        int count = 0;

            

Reported by PMD.

Avoid unused local variables such as 'key'.
Design

Line: 42

              
        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            Long value = reader.readLong();
            count++;
        }
        Assert.assertEquals(10, count);


            

Reported by PMD.

Avoid unused local variables such as 'value'.
Design

Line: 43

                      int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            Long value = reader.readLong();
            count++;
        }
        Assert.assertEquals(10, count);

        reader.endObject();

            

Reported by PMD.

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

Line: 23

              
        reader.startObject();

        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            String value = reader.readString();
            count++;
        }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'key' (lines '25'-'33').
Error

Line: 25

              
        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            String value = reader.readString();
            count++;
        }
        Assert.assertEquals(10, count);


            

Reported by PMD.

Found 'DD'-anomaly for variable 'key' (lines '25'-'25').
Error

Line: 25

              
        int count = 0;
        while (reader.hasNext()) {
            String key = (String) reader.readObject();
            String value = reader.readString();
            count++;
        }
        Assert.assertEquals(10, count);


            

Reported by PMD.

src/main/java/com/alibaba/fastjson/serializer/CharArrayCodec.java
19 issues
The class 'CharArrayCodec' has a Modified Cyclomatic Complexity of 5 (Highest = 11).
Design

Line: 14

              import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;


public class CharArrayCodec implements ObjectDeserializer {

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
        return (T) deserialze(parser);
    }

            

Reported by PMD.

The class 'CharArrayCodec' has a Standard Cyclomatic Complexity of 5 (Highest = 11).
Design

Line: 14

              import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;


public class CharArrayCodec implements ObjectDeserializer {

    @SuppressWarnings("unchecked")
    public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
        return (T) deserialze(parser);
    }

            

Reported by PMD.

The method 'deserialze(DefaultJSONParser)' has an NPath complexity of 272, current threshold is 200
Design

Line: 22

                  }
    
    @SuppressWarnings("unchecked")
    public static <T> T deserialze(DefaultJSONParser parser) {
        final JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.LITERAL_STRING) {
            String val = lexer.stringVal();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val.toCharArray();

            

Reported by PMD.

The method 'deserialze' has a Standard Cyclomatic Complexity of 11.
Design

Line: 22

                  }
    
    @SuppressWarnings("unchecked")
    public static <T> T deserialze(DefaultJSONParser parser) {
        final JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.LITERAL_STRING) {
            String val = lexer.stringVal();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val.toCharArray();

            

Reported by PMD.

The method 'deserialze(DefaultJSONParser)' has a cyclomatic complexity of 12.
Design

Line: 22

                  }
    
    @SuppressWarnings("unchecked")
    public static <T> T deserialze(DefaultJSONParser parser) {
        final JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.LITERAL_STRING) {
            String val = lexer.stringVal();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val.toCharArray();

            

Reported by PMD.

The method 'deserialze' has a Modified Cyclomatic Complexity of 11.
Design

Line: 22

                  }
    
    @SuppressWarnings("unchecked")
    public static <T> T deserialze(DefaultJSONParser parser) {
        final JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.LITERAL_STRING) {
            String val = lexer.stringVal();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val.toCharArray();

            

Reported by PMD.

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

Line: 24

                  @SuppressWarnings("unchecked")
    public static <T> T deserialze(DefaultJSONParser parser) {
        final JSONLexer lexer = parser.lexer;
        if (lexer.token() == JSONToken.LITERAL_STRING) {
            String val = lexer.stringVal();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val.toCharArray();
        }
        

            

Reported by PMD.

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

Line: 27

                      if (lexer.token() == JSONToken.LITERAL_STRING) {
            String val = lexer.stringVal();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val.toCharArray();
        }
        
        if (lexer.token() == JSONToken.LITERAL_INT) {
            Number val = lexer.integerValue();
            lexer.nextToken(JSONToken.COMMA);

            

Reported by PMD.

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

Line: 30

                          return (T) val.toCharArray();
        }
        
        if (lexer.token() == JSONToken.LITERAL_INT) {
            Number val = lexer.integerValue();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val.toString().toCharArray();
        }


            

Reported by PMD.

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

Line: 33

                      if (lexer.token() == JSONToken.LITERAL_INT) {
            Number val = lexer.integerValue();
            lexer.nextToken(JSONToken.COMMA);
            return (T) val.toString().toCharArray();
        }

        Object value = parser.parse();

        if (value instanceof  String) {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/basicType/FloatTest3_random.java
19 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 java.util.Random;

public class FloatTest3_random extends TestCase {
    public void test_ran() throws Exception {
        Random rand = new Random();

        for (int i = 0; i < 1000 * 1000 * 1; ++i) {
            float val = rand.nextFloat();


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 19

                      for (int i = 0; i < 1000 * 1000 * 1; ++i) {
            float val = rand.nextFloat();

            String str = JSON.toJSONString(new Model(val));
            Model m = JSON.parseObject(str, Model.class);

            assertEquals(val, m.value);
        }
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                          String str = JSON.toJSONString(new Model(val));
            Model m = JSON.parseObject(str, Model.class);

            assertEquals(val, m.value);
        }
    }

    public void test_ran_2() throws Exception {
        Random rand = new Random();

            

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

                      }
    }

    public void test_ran_2() throws Exception {
        Random rand = new Random();

        for (int i = 0; i < 1000 * 1000 * 1; ++i) {
            float val = rand.nextFloat();


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 32

                      for (int i = 0; i < 1000 * 1000 * 1; ++i) {
            float val = rand.nextFloat();

            String str = JSON.toJSONString(new Model(val), SerializerFeature.BeanToArray);
            Model m = JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);

            assertEquals(val, m.value);
        }
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 35

                          String str = JSON.toJSONString(new Model(val), SerializerFeature.BeanToArray);
            Model m = JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);

            assertEquals(val, m.value);
        }
    }

    public void test_ran_3() throws Exception {
        Random rand = new Random();

            

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

                      }
    }

    public void test_ran_3() throws Exception {
        Random rand = new Random();

        for (int i = 0; i < 1000 * 1000 * 1; ++i) {
            float val = rand.nextFloat();


            

Reported by PMD.

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

Line: 45

                      for (int i = 0; i < 1000 * 1000 * 1; ++i) {
            float val = rand.nextFloat();

            String str = JSON.toJSONString(Collections.singletonMap("val", val));
            float val2 = JSON.parseObject(str).getFloatValue("val");

            assertEquals(val, val2);
        }
    }

            

Reported by PMD.

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

Line: 46

                          float val = rand.nextFloat();

            String str = JSON.toJSONString(Collections.singletonMap("val", val));
            float val2 = JSON.parseObject(str).getFloatValue("val");

            assertEquals(val, val2);
        }
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 48

                          String str = JSON.toJSONString(Collections.singletonMap("val", val));
            float val2 = JSON.parseObject(str).getFloatValue("val");

            assertEquals(val, val2);
        }
    }

    public void test_ran_4() throws Exception {
        Random rand = new Random();

            

Reported by PMD.