The following issues were found
src/main/java/com/alibaba/fastjson/support/jaxrs/FastJsonFeature.java
5 issues
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.
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.
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.
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.
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
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.
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.
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.
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.
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
Line: 8
*/
public class MethodCollector {
private final int paramCount;
private final int ignoreCount;
private int currentParameter;
Reported by PMD.
Line: 10
private final int paramCount;
private final int ignoreCount;
private int currentParameter;
private final StringBuilder result;
Reported by PMD.
Line: 12
private final int ignoreCount;
private int currentParameter;
private final StringBuilder result;
protected boolean debugInfoPresent;
Reported by PMD.
Line: 14
private int currentParameter;
private final StringBuilder result;
protected boolean debugInfoPresent;
protected MethodCollector(int ignoreCount, int paramCount) {
this.ignoreCount = ignoreCount;
Reported by PMD.
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
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.
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.
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.
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.
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
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.
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.
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.
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.
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
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.
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.
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.
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.
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
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.
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.
Line: 36
}
@JSONType(alphabetic = true)
public static class A {
private int f1;
private int f0;
public int getF1() {
Reported by PMD.
Line: 60
}
@JSONType(alphabetic = false)
public static class B {
private int f2;
private int f1;
private int f0;
Reported by PMD.
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
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.
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.
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.
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.
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
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.
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.
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.
Line: 31
try {
Method method = clazz.getMethod(methodName);
return method.getGenericReturnType();
} catch (Exception ex) {
return null;
}
}
}
Reported by PMD.
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
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.
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.
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.
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.
Line: 32
private static class Model {
@JSONField(format = "gzip,base64")
public byte[] value;
}
}
Reported by PMD.