The following issues were found

src/test/java/com/alibaba/json/bvt/bug/Issue74.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: 14

              

public class Issue74 extends TestCase {
    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue74.json");
        String text = org.apache.commons.io.IOUtils.toString(is);
        is.close();
        
        JSONArray json = (JSONArray) JSON.parse(text);

            

Reported by PMD.

Ensure that resources like this InputStream object are closed after use
Error

Line: 15

              
public class Issue74 extends TestCase {
    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue74.json");
        String text = org.apache.commons.io.IOUtils.toString(is);
        is.close();
        
        JSONArray json = (JSONArray) JSON.parse(text);
        

            

Reported by PMD.

In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
Error

Line: 15

              
public class Issue74 extends TestCase {
    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue74.json");
        String text = org.apache.commons.io.IOUtils.toString(is);
        is.close();
        
        JSONArray json = (JSONArray) JSON.parse(text);
        

            

Reported by PMD.

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

Line: 15

              
public class Issue74 extends TestCase {
    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue74.json");
        String text = org.apache.commons.io.IOUtils.toString(is);
        is.close();
        
        JSONArray json = (JSONArray) JSON.parse(text);
        

            

Reported by PMD.

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

Line: 15

              
public class Issue74 extends TestCase {
    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue74.json");
        String text = org.apache.commons.io.IOUtils.toString(is);
        is.close();
        
        JSONArray json = (JSONArray) JSON.parse(text);
        

            

Reported by PMD.

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

Line: 16

              public class Issue74 extends TestCase {
    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue74.json");
        String text = org.apache.commons.io.IOUtils.toString(is);
        is.close();
        
        JSONArray json = (JSONArray) JSON.parse(text);
        
        Assert.assertNotNull(json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));

            

Reported by PMD.

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

Line: 17

                  public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue74.json");
        String text = org.apache.commons.io.IOUtils.toString(is);
        is.close();
        
        JSONArray json = (JSONArray) JSON.parse(text);
        
        Assert.assertNotNull(json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
        Assert.assertSame(json.getJSONObject(0).getJSONObject("dataType"), json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));

            

Reported by PMD.

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

Line: 21

                      
        JSONArray json = (JSONArray) JSON.parse(text);
        
        Assert.assertNotNull(json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
        Assert.assertSame(json.getJSONObject(0).getJSONObject("dataType"), json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
    }
}

            

Reported by PMD.

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

Line: 21

                      
        JSONArray json = (JSONArray) JSON.parse(text);
        
        Assert.assertNotNull(json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
        Assert.assertSame(json.getJSONObject(0).getJSONObject("dataType"), json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
    }
}

            

Reported by PMD.

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

Line: 21

                      
        JSONArray json = (JSONArray) JSON.parse(text);
        
        Assert.assertNotNull(json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
        Assert.assertSame(json.getJSONObject(0).getJSONObject("dataType"), json.getJSONObject(0).getJSONObject("dataType").getJSONObject("categoryType").getJSONArray("dataTypes").get(0));
    }
}

            

Reported by PMD.

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

Line: 18

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

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

            

Reported by PMD.

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

Line: 19

              import com.alibaba.fastjson.parser.ParserConfig;

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

            

Reported by PMD.

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

Line: 24

                      JSON.defaultLocale = Locale.CHINA;
    }
    
    public void test_date_new() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("new Date(1294552193254)");

        java.util.Date date = parser.parseObject(java.util.Date.class);

        Assert.assertEquals(new java.util.Date(1294552193254L), date);

            

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

                      parser.close();
    }
    
    public void test_date_new_1() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("new Date(1294552193254)");

        java.util.Date date = (java.util.Date) parser.parse();

        Assert.assertEquals(new java.util.Date(1294552193254L), date);

            

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

                      parser.close();
    }
    
    public void test_date_0() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("1294552193254");

        java.util.Date date = parser.parseObject(java.util.Date.class);

        Assert.assertEquals(new java.util.Date(1294552193254L), date);

            

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

                      parser.close();
    }

    public void test_date_1() throws Exception {
        int features = JSON.DEFAULT_PARSER_FEATURE;
        features = Feature.config(features, Feature.AllowISO8601DateFormat, true);
        DefaultJSONParser parser = new DefaultJSONParser("\"2011-01-09T13:49:53.254\"", ParserConfig.getGlobalInstance(), features);

        java.util.Date date = parser.parseObject(java.util.Date.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: 62

                      parser.close();
    }

    public void test_date_2() throws Exception {
        int features = JSON.DEFAULT_PARSER_FEATURE;
        DefaultJSONParser parser = new DefaultJSONParser("new Date(1294552193254)", ParserConfig.getGlobalInstance(), features);

        java.util.Date date = parser.parseObject(java.util.Date.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: 72

                      parser.close();
    }

    public void test_date_3() throws Exception {
        java.util.Date date = JSON.parseObject("\"2011-01-09T13:49:53\"", java.util.Date.class, Feature.AllowISO8601DateFormat);

        Assert.assertEquals(new java.util.Date(1294552193000L), date);
    }


            

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

                      Assert.assertEquals(new java.util.Date(1294552193000L), date);
    }

    public void test_date_4() throws Exception {
        int features = JSON.DEFAULT_PARSER_FEATURE;
        features = Feature.config(features, Feature.AllowISO8601DateFormat, true);
        DefaultJSONParser parser = new DefaultJSONParser("\"2011-01-09\"", ParserConfig.getGlobalInstance(), features);

        java.util.Date date = parser.parseObject(java.util.Date.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: 89

                      parser.close();
    }

    public void test_date_5() throws Exception {
        JSONObject object = JSON.parseObject("{d:'2011-01-09T13:49:53'}", Feature.AllowISO8601DateFormat);
        Assert.assertEquals(new java.util.Date(1294552193000L), object.get("d"));
    }

    public void test_date_6() throws Exception {

            

Reported by PMD.

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

Line: 29

                      List<Map<String, List<String>>> list = new ArrayList(4);
        list.add(Collections.singletonMap("key1", Collections.singletonList("item")));
        String text = JSON.toJSONString(list);
        System.out.println("text = " + text);

        List<Map<String, List<String>>> result = parseObject(text,
            new SelfTypeReference<Map<String, List<String>>>() {});
        System.out.println("result = " + result);
        TestCase.assertTrue(result.get(0) instanceof Map);

            

Reported by PMD.

System.out.println is used
Design

Line: 33

              
        List<Map<String, List<String>>> result = parseObject(text,
            new SelfTypeReference<Map<String, List<String>>>() {});
        System.out.println("result = " + result);
        TestCase.assertTrue(result.get(0) instanceof Map);
        TestCase.assertTrue(result.get(0).get("key1").get(0) instanceof String);
    }

    public <T> List<T> parseObject(String text, SelfTypeReference<T> selfTypeReference) {

            

Reported by PMD.

System.out.println is used
Design

Line: 49

                      List<Map<String, List<String>>> list = new ArrayList(4);
        list.add(Collections.singletonMap("key1", Collections.singletonList("item")));
        String text = JSON.toJSONString(list);
        System.out.println("text = " + text);

        List<Map<String, List<String>>> result = parseObject2(text,
                new SelfTypeReference<Map<String, List<String>>>() {
                });
        System.out.println("result = " + result);

            

Reported by PMD.

System.out.println is used
Design

Line: 54

                      List<Map<String, List<String>>> result = parseObject2(text,
                new SelfTypeReference<Map<String, List<String>>>() {
                });
        System.out.println("result = " + result);
    }

    @Test
    public void test2() {
        List<List<String>> list = new ArrayList(4);

            

Reported by PMD.

System.out.println is used
Design

Line: 62

                      List<List<String>> list = new ArrayList(4);
        list.add(Collections.singletonList("item"));
        String text = JSON.toJSONString(list);
        System.out.println("text = " + text);

        List<List<String>> result = parseObject2(text,
                new SelfTypeReference<List<String>>() {
                });
        System.out.println("result = " + result);

            

Reported by PMD.

System.out.println is used
Design

Line: 67

                      List<List<String>> result = parseObject2(text,
                new SelfTypeReference<List<String>>() {
                });
        System.out.println("result = " + result);
    }

    @Test
    public void test3() {
        List<String> list = new ArrayList(4);

            

Reported by PMD.

System.out.println is used
Design

Line: 75

                      List<String> list = new ArrayList(4);
        list.add("item");
        String text = JSON.toJSONString(list);
        System.out.println("text = " + text);

        List<String> result = parseObject2(text,
                new SelfTypeReference<String>() {
                });
        System.out.println("result = " + result);

            

Reported by PMD.

System.out.println is used
Design

Line: 80

                      List<String> result = parseObject2(text,
                new SelfTypeReference<String>() {
                });
        System.out.println("result = " + result);
    }

    public <T> List<T> parseObject2(String text, SelfTypeReference<T> selfTypeReference) {
        Type genericSuperclass = selfTypeReference.getClass().getGenericSuperclass();
        Type[] actualTypeArguments = ((ParameterizedType) genericSuperclass).getActualTypeArguments();

            

Reported by PMD.

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

Line: 25

                  }

    @Test
    public void test() {
        List<Map<String, List<String>>> list = new ArrayList(4);
        list.add(Collections.singletonMap("key1", Collections.singletonList("item")));
        String text = JSON.toJSONString(list);
        System.out.println("text = " + text);


            

Reported by PMD.

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

Line: 27

                  @Test
    public void test() {
        List<Map<String, List<String>>> list = new ArrayList(4);
        list.add(Collections.singletonMap("key1", Collections.singletonList("item")));
        String text = JSON.toJSONString(list);
        System.out.println("text = " + text);

        List<Map<String, List<String>>> result = parseObject(text,
            new SelfTypeReference<Map<String, List<String>>>() {});

            

Reported by PMD.

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

Line: 28

                      String hex_2 = hex(bytes_2);

        assertEquals(hex, hex_2);
        System.out.println(hex);
        assertEquals("84C1F969587F5FD1942148EE9D36A0FB", hex);

        list.add(bytes);

        String str = JSON.toJSONString(list, SerializerFeature.WriteClassName);

            

Reported by PMD.

System.out.println is used
Design

Line: 35

              
        String str = JSON.toJSONString(list, SerializerFeature.WriteClassName);

        System.out.println(str);
        assertEquals("[\"a\",x'84C1F969587F5FD1942148EE9D36A0FB']", str);

        JSONArray array = (JSONArray) JSON.parse(str);

        assertEquals("a", array.get(0));

            

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

               * Created by wenshao on 15/05/2017.
 */
public class WriteClassNameTest_bytes extends TestCase {
    public void test_for_bytes() throws Exception {
        List<Object> list = new ArrayList<Object>();
        list.add("a");

        byte[] bytes = hex("84C1F969587F5FD1942148EE9D36A0FB");
        String hex = hex(bytes);

            

Reported by PMD.

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

Line: 17

               * Created by wenshao on 15/05/2017.
 */
public class WriteClassNameTest_bytes extends TestCase {
    public void test_for_bytes() throws Exception {
        List<Object> list = new ArrayList<Object>();
        list.add("a");

        byte[] bytes = hex("84C1F969587F5FD1942148EE9D36A0FB");
        String hex = hex(bytes);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

                      byte[] bytes_2 = hex(hex);
        String hex_2 = hex(bytes_2);

        assertEquals(hex, hex_2);
        System.out.println(hex);
        assertEquals("84C1F969587F5FD1942148EE9D36A0FB", hex);

        list.add(bytes);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

              
        assertEquals(hex, hex_2);
        System.out.println(hex);
        assertEquals("84C1F969587F5FD1942148EE9D36A0FB", hex);

        list.add(bytes);

        String str = JSON.toJSONString(list, SerializerFeature.WriteClassName);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 36

                      String str = JSON.toJSONString(list, SerializerFeature.WriteClassName);

        System.out.println(str);
        assertEquals("[\"a\",x'84C1F969587F5FD1942148EE9D36A0FB']", str);

        JSONArray array = (JSONArray) JSON.parse(str);

        assertEquals("a", array.get(0));
        assertTrue(array.get(1) instanceof byte[]);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

              
        JSONArray array = (JSONArray) JSON.parse(str);

        assertEquals("a", array.get(0));
        assertTrue(array.get(1) instanceof byte[]);

        // list.add(new )
    }


            

Reported by PMD.

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

Line: 40

              
        JSONArray array = (JSONArray) JSON.parse(str);

        assertEquals("a", array.get(0));
        assertTrue(array.get(1) instanceof byte[]);

        // list.add(new )
    }


            

Reported by PMD.

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

Line: 41

                      JSONArray array = (JSONArray) JSON.parse(str);

        assertEquals("a", array.get(0));
        assertTrue(array.get(1) instanceof byte[]);

        // list.add(new )
    }

    public void test_bytes2() throws Exception {

            

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/JSONReader.java
19 issues
Overridable method 'config' called during object construction
Error

Line: 36

                  public JSONReader(Reader reader, Feature... features){
        this(new JSONReaderScanner(reader));
        for (Feature feature : features) {
            this.config(feature, true);
        }
    }

    public JSONReader(JSONLexer lexer){
        this(new DefaultJSONParser(lexer));

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 23

              import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.util.TypeUtils;

public class JSONReader implements Closeable {

    private final DefaultJSONParser parser;
    private JSONStreamContext       context;
    private transient JSONStreamContext lastContext;


            

Reported by PMD.

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

Line: 25

              
public class JSONReader implements Closeable {

    private final DefaultJSONParser parser;
    private JSONStreamContext       context;
    private transient JSONStreamContext lastContext;

    public JSONReader(Reader reader){
        this(reader, new Feature[0]);

            

Reported by PMD.

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

Line: 26

              public class JSONReader implements Closeable {

    private final DefaultJSONParser parser;
    private JSONStreamContext       context;
    private transient JSONStreamContext lastContext;

    public JSONReader(Reader reader){
        this(reader, new Feature[0]);
    }

            

Reported by PMD.

The String literal 'illegal state : ' appears 4 times in this file; the first occurrence is on line 122
Error

Line: 122

                          case StartObject:
                break;
            default:
                throw new JSONException("illegal state : " + context.state);
        }
    }

    private void endStructure() {
        lastContext = context;

            

Reported by PMD.

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

Line: 160

                          throw new JSONException("context is null");
        }

        final int token = parser.lexer.token();
        final int state = context.state;
        switch (state) {
            case StartArray:
            case ArrayValue:
                return token != JSONToken.RBRACKET;

            

Reported by PMD.

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

Line: 175

                  }

    public int peek() {
        return parser.lexer.token();
    }

    public void close() {
        parser.close();
    }

            

Reported by PMD.

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

Line: 215

                      } else {
            readBefore();
            JSONLexer lexer = parser.lexer;
            if (context.state == JSONStreamContext.StartObject && lexer.token() == JSONToken.IDENTIFIER) {
                object = lexer.stringVal();
                lexer.nextToken();
            } else {
                object = parser.parse();
            }

            

Reported by PMD.

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

Line: 216

                          readBefore();
            JSONLexer lexer = parser.lexer;
            if (context.state == JSONStreamContext.StartObject && lexer.token() == JSONToken.IDENTIFIER) {
                object = lexer.stringVal();
                lexer.nextToken();
            } else {
                object = parser.parse();
            }
            readAfter();

            

Reported by PMD.

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

Line: 217

                          JSONLexer lexer = parser.lexer;
            if (context.state == JSONStreamContext.StartObject && lexer.token() == JSONToken.IDENTIFIER) {
                object = lexer.stringVal();
                lexer.nextToken();
            } else {
                object = parser.parse();
            }
            readAfter();
        }

            

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

Line: 35

                      // new Gson().fromJson(text, java.util.HashMap.class);
        //new ObjectMapper().readValue(text, java.util.HashMap.class);
        long costMillis = System.currentTimeMillis() - startMillis;
        System.out.println("cost : " + costMillis);
    }
}

            

Reported by PMD.

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

Line: 20

               * Created by wenshao on 2016/10/19.
 */
public class Issue859 extends TestCase {
    protected void setUp() throws Exception {
        com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.Bug_for_zhaoyao.");
    }

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");

            

Reported by PMD.

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

Line: 21

               */
public class Issue859 extends TestCase {
    protected void setUp() throws Exception {
        com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.Bug_for_zhaoyao.");
    }

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
        GZIPInputStream gzipInputStream = new GZIPInputStream(is);

            

Reported by PMD.

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

Line: 24

                      com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.Bug_for_zhaoyao.");
    }

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
        GZIPInputStream gzipInputStream = new GZIPInputStream(is);
        String text = org.apache.commons.io.IOUtils.toString(gzipInputStream);
        long startMillis = System.currentTimeMillis();
        for (int i = 0; i < 1; ++i) {

            

Reported by PMD.

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

Line: 24

                      com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.Bug_for_zhaoyao.");
    }

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
        GZIPInputStream gzipInputStream = new GZIPInputStream(is);
        String text = org.apache.commons.io.IOUtils.toString(gzipInputStream);
        long startMillis = System.currentTimeMillis();
        for (int i = 0; i < 1; ++i) {

            

Reported by PMD.

Ensure that resources like this InputStream object are closed after use
Error

Line: 25

                  }

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
        GZIPInputStream gzipInputStream = new GZIPInputStream(is);
        String text = org.apache.commons.io.IOUtils.toString(gzipInputStream);
        long startMillis = System.currentTimeMillis();
        for (int i = 0; i < 1; ++i) {
            JSON.parseObject(text);

            

Reported by PMD.

In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
Error

Line: 25

                  }

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
        GZIPInputStream gzipInputStream = new GZIPInputStream(is);
        String text = org.apache.commons.io.IOUtils.toString(gzipInputStream);
        long startMillis = System.currentTimeMillis();
        for (int i = 0; i < 1; ++i) {
            JSON.parseObject(text);

            

Reported by PMD.

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

Line: 25

                  }

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
        GZIPInputStream gzipInputStream = new GZIPInputStream(is);
        String text = org.apache.commons.io.IOUtils.toString(gzipInputStream);
        long startMillis = System.currentTimeMillis();
        for (int i = 0; i < 1; ++i) {
            JSON.parseObject(text);

            

Reported by PMD.

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

Line: 25

                  }

    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
        GZIPInputStream gzipInputStream = new GZIPInputStream(is);
        String text = org.apache.commons.io.IOUtils.toString(gzipInputStream);
        long startMillis = System.currentTimeMillis();
        for (int i = 0; i < 1; ++i) {
            JSON.parseObject(text);

            

Reported by PMD.

Ensure that resources like this InputStream object are closed after use
Error

Line: 26

              
    public void test_for_issue() throws Exception {
        InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue859.zip");
        GZIPInputStream gzipInputStream = new GZIPInputStream(is);
        String text = org.apache.commons.io.IOUtils.toString(gzipInputStream);
        long startMillis = System.currentTimeMillis();
        for (int i = 0; i < 1; ++i) {
            JSON.parseObject(text);
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/mixins/MixinInheritanceTest.java
19 issues
The String literal 'name' appears 4 times in this file; the first occurrence is on line 16
Error

Line: 16

                  }

    static class BeanoMixinSuper {
        @JSONField(name = "name")
        public String nameo;
    }

    static class BeanoMixinSub extends BeanoMixinSuper {
        @JSONField(name = "id")

            

Reported by PMD.

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

Line: 42

                      public abstract int getIdo();
    }

    public void test_field() throws Exception {
        JSON.addMixInAnnotations(Beano.class, BeanoMixinSub.class);
        String str = JSON.toJSONString(new Beano());
        JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        if (!result.containsKey("id")

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

                      JSON.addMixInAnnotations(Beano.class, BeanoMixinSub.class);
        String str = JSON.toJSONString(new Beano());
        JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        if (!result.containsKey("id")
                || !result.containsKey("name")) {
            fail("Should have both 'id' and 'name', but content = " + result);
        }
        JSON.removeMixInAnnotations(Beano.class);

            

Reported by PMD.

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

Line: 46

                      JSON.addMixInAnnotations(Beano.class, BeanoMixinSub.class);
        String str = JSON.toJSONString(new Beano());
        JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        if (!result.containsKey("id")
                || !result.containsKey("name")) {
            fail("Should have both 'id' and 'name', but content = " + result);
        }
        JSON.removeMixInAnnotations(Beano.class);

            

Reported by PMD.

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

Line: 47

                      String str = JSON.toJSONString(new Beano());
        JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        if (!result.containsKey("id")
                || !result.containsKey("name")) {
            fail("Should have both 'id' and 'name', but content = " + result);
        }
        JSON.removeMixInAnnotations(Beano.class);
    }

            

Reported by PMD.

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

Line: 48

                      JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        if (!result.containsKey("id")
                || !result.containsKey("name")) {
            fail("Should have both 'id' and 'name', but content = " + result);
        }
        JSON.removeMixInAnnotations(Beano.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: 54

                      JSON.removeMixInAnnotations(Beano.class);
    }

    public void test_method() throws Exception {
        JSON.addMixInAnnotations(Beano2.class, BeanoMixinSub2.class);
        String str = JSON.toJSONString(new Beano2());
        JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        assertTrue(result.containsKey("id"));

            

Reported by PMD.

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

Line: 54

                      JSON.removeMixInAnnotations(Beano.class);
    }

    public void test_method() throws Exception {
        JSON.addMixInAnnotations(Beano2.class, BeanoMixinSub2.class);
        String str = JSON.toJSONString(new Beano2());
        JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        assertTrue(result.containsKey("id"));

            

Reported by PMD.

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

Line: 58

                      JSON.addMixInAnnotations(Beano2.class, BeanoMixinSub2.class);
        String str = JSON.toJSONString(new Beano2());
        JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        assertTrue(result.containsKey("id"));
        assertTrue(result.containsKey("name"));
        JSON.removeMixInAnnotations(Beano2.class);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 58

                      JSON.addMixInAnnotations(Beano2.class, BeanoMixinSub2.class);
        String str = JSON.toJSONString(new Beano2());
        JSONObject result = JSONObject.parseObject(str);
        assertEquals(2, result.size());
        assertTrue(result.containsKey("id"));
        assertTrue(result.containsKey("name"));
        JSON.removeMixInAnnotations(Beano2.class);
    }


            

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.