The following issues were found

src/main/java/com/alibaba/fastjson/support/jaxrs/FastJsonFeature.java
5 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 31

                          final Configuration config = context.getConfiguration();

            final String jsonFeature = CommonProperties.getValue(
                    config.getProperties()
                    , config.getRuntimeType()
                    , InternalProperties.JSON_FEATURE, JSON_FEATURE,
                    String.class
            );


            

Reported by PMD.

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

Line: 32

              
            final String jsonFeature = CommonProperties.getValue(
                    config.getProperties()
                    , config.getRuntimeType()
                    , InternalProperties.JSON_FEATURE, JSON_FEATURE,
                    String.class
            );

            // Other JSON providers registered.

            

Reported by PMD.

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

Line: 44

              
            // Disable other JSON providers.
            context.property(
                    PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType())
                    , JSON_FEATURE);

            // Register FastJson.
            if (!config.isRegistered(FastJsonProvider.class)) {
                context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);

            

Reported by PMD.

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

Line: 48

                                  , JSON_FEATURE);

            // Register FastJson.
            if (!config.isRegistered(FastJsonProvider.class)) {
                context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
            }
        } catch (NoSuchMethodError e) {
            // skip
        }

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 51

                          if (!config.isRegistered(FastJsonProvider.class)) {
                context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
            }
        } catch (NoSuchMethodError e) {
            // skip
        }

        return true;
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/Bug12.java
5 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: 15

              
public class Bug12 extends TestCase {

    public void test_0() throws Exception {
        String resource = "2.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(new InputStreamReader(is, "UTF-8"));
        is.close();
        

            

Reported by PMD.

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

Line: 17

              
    public void test_0() throws Exception {
        String resource = "2.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(new InputStreamReader(is, "UTF-8"));
        is.close();
        
        Object obj = JSON.parse(text);
        Assert.assertNotNull(obj);

            

Reported by PMD.

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

Line: 17

              
    public void test_0() throws Exception {
        String resource = "2.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(new InputStreamReader(is, "UTF-8"));
        is.close();
        
        Object obj = JSON.parse(text);
        Assert.assertNotNull(obj);

            

Reported by PMD.

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

Line: 17

              
    public void test_0() throws Exception {
        String resource = "2.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(new InputStreamReader(is, "UTF-8"));
        is.close();
        
        Object obj = JSON.parse(text);
        Assert.assertNotNull(obj);

            

Reported by PMD.

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

Line: 19

                      String resource = "2.json";
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String text = IOUtils.toString(new InputStreamReader(is, "UTF-8"));
        is.close();
        
        Object obj = JSON.parse(text);
        Assert.assertNotNull(obj);
    }
}

            

Reported by PMD.

src/main/java/com/alibaba/fastjson/asm/MethodCollector.java
5 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 8

               */
public class MethodCollector {

    private final int paramCount;

    private final int ignoreCount;

    private int currentParameter;


            

Reported by PMD.

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

Line: 10

              
    private final int paramCount;

    private final int ignoreCount;

    private int currentParameter;

    private final StringBuilder result;


            

Reported by PMD.

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

Line: 12

              
    private final int ignoreCount;

    private int currentParameter;

    private final StringBuilder result;

    protected boolean debugInfoPresent;


            

Reported by PMD.

StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time).
Design

Line: 14

              
    private int currentParameter;

    private final StringBuilder result;

    protected boolean debugInfoPresent;

    protected MethodCollector(int ignoreCount, int paramCount) {
        this.ignoreCount = ignoreCount;

            

Reported by PMD.

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

Line: 16

              
    private final StringBuilder result;

    protected boolean debugInfoPresent;

    protected MethodCollector(int ignoreCount, int paramCount) {
        this.ignoreCount = ignoreCount;
        this.paramCount = paramCount;
        this.result = new StringBuilder();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/ByteArrayFieldTest_6_gzip.java
5 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: 10

              
public class ByteArrayFieldTest_6_gzip extends TestCase {

    public void test_0() throws Exception {
        Model model = new Model();

        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < 1000; ++i) {
            buf.append("0123456890");

            

Reported by PMD.

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

Line: 13

                  public void test_0() throws Exception {
        Model model = new Model();

        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < 1000; ++i) {
            buf.append("0123456890");
            buf.append("ABCDEFGHIJ");
        }


            

Reported by PMD.

StringBuffer (or StringBuilder).append is called 2 consecutive times with literals. Use a single append with a single combined String.
Performance

Line: 15

              
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < 1000; ++i) {
            buf.append("0123456890");
            buf.append("ABCDEFGHIJ");
        }

        model.value = buf.toString().getBytes();


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

              
        String json = JSON.toJSONString(model);

        assertEquals("{\"value\":\"H4sIAAAAAAAAAO3IsRGAIBAAsJVeUE5LBBXcfyC3sErKxJLyupX9iHq2ft3PmG8455xzzjnnnHPOOeecc84555xzzjnnnHPOOeecc84555xzzjnnnHPOOeecc84555z7/T6powiAIE4AAA==\"}", json);

        Model model1 = JSON.parseObject(json, Model.class);
        Assert.assertArrayEquals(model.value, model1.value);
    }


            

Reported by PMD.

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

Line: 31

              
    public static class Model {
        @JSONField(format = "gzip")
        public byte[] value;
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/JSONTypeTest_orders_arrayMapping.java
5 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: 10

              import junit.framework.TestCase;

public class JSONTypeTest_orders_arrayMapping extends TestCase {
	public void test_1() throws Exception {
		Model vo = new Model();
		vo.setId(1001);
		vo.setName("xx");
		vo.setAge(33);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              		vo.setAge(33);

		String json = JSON.toJSONString(vo, SerializerFeature.BeanToArray);
		assertEquals("[1001,\"xx\",33]", json);

		JSON.parseObject(json, Model.class, Feature.SupportArrayToBean);

		Model[] array = new Model[] {vo};
		String json2 = JSON.toJSONString(array, 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: 26

              		JSON.parseObject(json2, Model[].class, Feature.SupportArrayToBean);
	}

	public void test_2() throws Exception {
		String json = "[1001,\"xx\"]";
		JSON.parseObject(json, Model.class, Feature.SupportArrayToBean);
	}

	@JSONType(orders = { "id", "name", "age" })

            

Reported by PMD.

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

Line: 26

              		JSON.parseObject(json2, Model[].class, Feature.SupportArrayToBean);
	}

	public void test_2() throws Exception {
		String json = "[1001,\"xx\"]";
		JSON.parseObject(json, Model.class, Feature.SupportArrayToBean);
	}

	@JSONType(orders = { "id", "name", "age" })

            

Reported by PMD.

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

Line: 32

              	}

	@JSONType(orders = { "id", "name", "age" })
	public static class Model {
		private int id;
		private String name;
		private int age;

		public int getId() {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/JSONTest_overflow.java
5 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 12

              
public class JSONTest_overflow extends TestCase {

    public void test_overflow() throws Exception {
        Entity entity = new Entity();
        entity.setSelf(entity);

        String text = JSON.toJSONString(entity, SerializeConfig.getGlobalInstance());
        Entity entity2 = JSON.parseObject(text, Entity.class);

            

Reported by PMD.

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

Line: 18

              
        String text = JSON.toJSONString(entity, SerializeConfig.getGlobalInstance());
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity2 == entity2.getSelf());
    }
    
    public void test_overflow_1() throws Exception {
        Entity entity = new Entity();
        entity.setSelf(entity);

            

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

                      Assert.assertTrue(entity2 == entity2.getSelf());
    }
    
    public void test_overflow_1() throws Exception {
        Entity entity = new Entity();
        entity.setSelf(entity);

        String text = JSON.toJSONStringZ(entity, SerializeConfig.getGlobalInstance());
        Entity entity2 = JSON.parseObject(text, Entity.class);

            

Reported by PMD.

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

Line: 27

              
        String text = JSON.toJSONStringZ(entity, SerializeConfig.getGlobalInstance());
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity2 == entity2.getSelf());
    }

    public static class Entity {

        private Entity self;

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONException'
Design

Line: 7

              import junit.framework.TestCase;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.serializer.SerializeConfig;

public class JSONTest_overflow extends TestCase {

    public void test_overflow() throws Exception {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/annotation/JSONTypejsonType_alphabetic_Test.java
5 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 11

              
public class JSONTypejsonType_alphabetic_Test extends TestCase {

    public void test_alphabetic_true() throws Exception {
        A a = new A();
        a.setF0(101);
        a.setF1(102);

        Assert.assertEquals("{\"f0\":101,\"f1\":102}", JSON.toJSONString(a));

            

Reported by PMD.

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

Line: 27

              //        Assert.assertFalse("{\"f2\":0,\"f1\":102,\"f0\":101}".equals(JSON.toJSONString(b)));
//    }

    public void test_alphabetic_notSet() throws Exception {
        C c = new C();
        c.setF0(101);
        c.setF1(102);

        Assert.assertEquals("{\"f0\":101,\"f1\":102}", JSON.toJSONString(c));

            

Reported by PMD.

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

Line: 36

                  }

    @JSONType(alphabetic = true)
    public static class A {

        private int f1;
        private int f0;

        public int getF1() {

            

Reported by PMD.

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

Line: 60

                  }

    @JSONType(alphabetic = false)
    public static class B {

        private int f2;
        private int f1;
        private int f0;


            

Reported by PMD.

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

Line: 92

              
    }

    public static class C {

        private int f1;
        private int f0;

        public int getF1() {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/JSONTest_null.java
5 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 JSONTest_null extends TestCase {

    public void test_0() throws Exception {
        Assert.assertNull(JSON.parseArray(null));
        Assert.assertNull(JSON.parseArray(""));
        Assert.assertNull(JSON.parseArray("null"));
        Assert.assertNull(JSON.parseArray(null, new Type[] { Object.class, Object.class }));
        Assert.assertNull(JSON.parseObject((char[]) null, 0, int.class, Feature.AllowArbitraryCommas));

            

Reported by PMD.

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

Line: 17

                  public void test_0() throws Exception {
        Assert.assertNull(JSON.parseArray(null));
        Assert.assertNull(JSON.parseArray(""));
        Assert.assertNull(JSON.parseArray("null"));
        Assert.assertNull(JSON.parseArray(null, new Type[] { Object.class, Object.class }));
        Assert.assertNull(JSON.parseObject((char[]) null, 0, int.class, Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parseObject(new char[0], 0, int.class, Feature.AllowArbitraryCommas));

        Assert.assertNull(JSON.parseObject("null".toCharArray(), 4, Object.class,  Feature.AllowArbitraryCommas));

            

Reported by PMD.

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

Line: 24

              
        Assert.assertNull(JSON.parseObject("null".toCharArray(), 4, Object.class,  Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parseObject("null".toCharArray(), 4, Object.class));
        Assert.assertNull(JSON.parse("null".getBytes(), 0, 4, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parse((byte[]) null, 0, 0, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parse(new byte[0], 0, 0, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
    }
}

            

Reported by PMD.

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

Line: 25

                      Assert.assertNull(JSON.parseObject("null".toCharArray(), 4, Object.class,  Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parseObject("null".toCharArray(), 4, Object.class));
        Assert.assertNull(JSON.parse("null".getBytes(), 0, 4, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parse((byte[]) null, 0, 0, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parse(new byte[0], 0, 0, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
    }
}

            

Reported by PMD.

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

Line: 26

                      Assert.assertNull(JSON.parseObject("null".toCharArray(), 4, Object.class));
        Assert.assertNull(JSON.parse("null".getBytes(), 0, 4, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parse((byte[]) null, 0, 0, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
        Assert.assertNull(JSON.parse(new byte[0], 0, 0, Charset.forName("UTF-8").newDecoder(), Feature.AllowArbitraryCommas));
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/asm/ASMUtilsTest.java
5 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: 15

              
public class ASMUtilsTest extends TestCase {

    public void test_isAnroid() throws Exception {
        Assert.assertTrue(ASMUtils.isAndroid("Dalvik"));
    }

    public void test_getDescs() throws Exception {
        Assert.assertEquals("Lcom/alibaba/fastjson/parser/ParseContext;", ASMUtils.desc(ParseContext.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: 19

                      Assert.assertTrue(ASMUtils.isAndroid("Dalvik"));
    }

    public void test_getDescs() throws Exception {
        Assert.assertEquals("Lcom/alibaba/fastjson/parser/ParseContext;", ASMUtils.desc(ParseContext.class));
    }

    public void test_getType_null() throws Exception {
        Assert.assertNull(ASMUtils.getMethodType(ParseContext.class, "XX"));

            

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

                      Assert.assertEquals("Lcom/alibaba/fastjson/parser/ParseContext;", ASMUtils.desc(ParseContext.class));
    }

    public void test_getType_null() throws Exception {
        Assert.assertNull(ASMUtils.getMethodType(ParseContext.class, "XX"));
    }
    
    public static Type getMethodType(Class<?> clazz, String methodName) {
        try {

            

Reported by PMD.

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

Line: 31

                      try {
            Method method = clazz.getMethod(methodName);

            return method.getGenericReturnType();
        } catch (Exception ex) {
            return null;
        }
    }
}

            

Reported by PMD.

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

Line: 32

                          Method method = clazz.getMethod(methodName);

            return method.getGenericReturnType();
        } catch (Exception ex) {
            return null;
        }
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/ByteArrayFieldTest_7_gzip_hex.java
5 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: 10

              
public class ByteArrayFieldTest_7_gzip_hex extends TestCase {

    public void test_0() throws Exception {
        Model model = new Model();

        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < 1000; ++i) {
            buf.append("0123456890");

            

Reported by PMD.

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

Line: 13

                  public void test_0() throws Exception {
        Model model = new Model();

        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < 1000; ++i) {
            buf.append("0123456890");
            buf.append("ABCDEFGHIJ");
        }


            

Reported by PMD.

StringBuffer (or StringBuilder).append is called 2 consecutive times with literals. Use a single append with a single combined String.
Performance

Line: 15

              
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < 1000; ++i) {
            buf.append("0123456890");
            buf.append("ABCDEFGHIJ");
        }

        model.value = buf.toString().getBytes();


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

              
        String json = JSON.toJSONString(model);

        assertEquals("{\"value\":\"H4sIAAAAAAAAAO3IsRGAIBAAsJVeUE5LBBXcfyC3sErKxJLyupX9iHq2ft3PmG8455xzzjnnnHPOOeecc84555xzzjnnnHPOOeecc84555xzzjnnnHPOOeecc84555z7/T6powiAIE4AAA==\"}", json);

        Model model1 = JSON.parseObject(json, Model.class);
        Assert.assertArrayEquals(model.value, model1.value);
    }


            

Reported by PMD.

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

Line: 32

                  private static class Model {

        @JSONField(format = "gzip,base64")
        public byte[] value;


    }
}

            

Reported by PMD.