The following issues were found
src/main/java/com/alibaba/fastjson/serializer/BigIntegerCodec.java
8 issues
Line: 51
}
BigInteger val = (BigInteger) object;
String str = val.toString();
if (str.length() >= 16
&& SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)
&& (val.compareTo(LOW) < 0
|| val.compareTo(HIGH) > 0))
{
Reported by PMD.
Line: 52
BigInteger val = (BigInteger) object;
String str = val.toString();
if (str.length() >= 16
&& SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)
&& (val.compareTo(LOW) < 0
|| val.compareTo(HIGH) > 0))
{
out.writeString(str);
Reported by PMD.
Line: 54
String str = val.toString();
if (str.length() >= 16
&& SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)
&& (val.compareTo(LOW) < 0
|| val.compareTo(HIGH) > 0))
{
out.writeString(str);
return;
}
Reported by PMD.
Line: 55
if (str.length() >= 16
&& SerializerFeature.isEnabled(features, out.features, SerializerFeature.BrowserCompatible)
&& (val.compareTo(LOW) < 0
|| val.compareTo(HIGH) > 0))
{
out.writeString(str);
return;
}
out.write(str);
Reported by PMD.
Line: 60
out.writeString(str);
return;
}
out.write(str);
}
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
return (T) deserialze(parser);
Reported by PMD.
Line: 71
@SuppressWarnings("unchecked")
public static <T> T deserialze(DefaultJSONParser parser) {
final JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.LITERAL_INT) {
String val = lexer.numberString();
lexer.nextToken(JSONToken.COMMA);
if (val.length() > 65535) {
throw new JSONException("decimal overflow");
Reported by PMD.
Line: 75
String val = lexer.numberString();
lexer.nextToken(JSONToken.COMMA);
if (val.length() > 65535) {
throw new JSONException("decimal overflow");
}
return (T) new BigInteger(val);
}
Reported by PMD.
Line: 75
String val = lexer.numberString();
lexer.nextToken(JSONToken.COMMA);
if (val.length() > 65535) {
throw new JSONException("decimal overflow");
}
return (T) new BigInteger(val);
}
Reported by PMD.
src/test/java/com/alibaba/fastjson/deserializer/issues3796/bean/ObjectP1_B.java
8 issues
Line: 8
public class ObjectP1_B {
private long a = 0;
private int b = 0;
Reported by PMD.
Line: 10
public class ObjectP1_B {
private long a = 0;
private int b = 0;
private int c = 0;
Reported by PMD.
Line: 12
private long a = 0;
private int b = 0;
private int c = 0;
private int d = 0;
Reported by PMD.
Line: 14
private int b = 0;
private int c = 0;
private int d = 0;
private int e = 0;
Reported by PMD.
Line: 16
private int c = 0;
private int d = 0;
private int e = 0;
private int f = 0;
Reported by PMD.
Line: 18
private int d = 0;
private int e = 0;
private int f = 0;
private long g = 0;
Reported by PMD.
Line: 20
private int e = 0;
private int f = 0;
private long g = 0;
private boolean h = true;
Reported by PMD.
Line: 22
private int f = 0;
private long g = 0;
private boolean h = true;
public long getA() {
return a;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Bug_102_for_rongganlin.java
8 issues
Line: 10
public class Bug_102_for_rongganlin extends TestCase {
public void test_bug() throws Exception {
TestBean testProcessInfo = new TestBean();
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
jo.put("id", 121);
ParserConfig config = new ParserConfig();
testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
Reported by PMD.
Line: 10
public class Bug_102_for_rongganlin extends TestCase {
public void test_bug() throws Exception {
TestBean testProcessInfo = new TestBean();
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
jo.put("id", 121);
ParserConfig config = new ParserConfig();
testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
Reported by PMD.
Line: 11
public class Bug_102_for_rongganlin extends TestCase {
public void test_bug() throws Exception {
TestBean testProcessInfo = new TestBean();
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
jo.put("id", 121);
ParserConfig config = new ParserConfig();
testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
}
Reported by PMD.
Line: 11
public class Bug_102_for_rongganlin extends TestCase {
public void test_bug() throws Exception {
TestBean testProcessInfo = new TestBean();
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
jo.put("id", 121);
ParserConfig config = new ParserConfig();
testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
}
Reported by PMD.
Line: 15
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
jo.put("id", 121);
ParserConfig config = new ParserConfig();
testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
}
public static class TestBean {
private double id;
Reported by PMD.
Line: 18
testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
}
public static class TestBean {
private double id;
private double name;
public double getId() {
Reported by PMD.
Line: 11
public class Bug_102_for_rongganlin extends TestCase {
public void test_bug() throws Exception {
TestBean testProcessInfo = new TestBean();
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
jo.put("id", 121);
ParserConfig config = new ParserConfig();
testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
}
Reported by PMD.
Line: 15
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
jo.put("id", 121);
ParserConfig config = new ParserConfig();
testProcessInfo = TypeUtils.cast(jo, TestBean.class, config);
}
public static class TestBean {
private double id;
Reported by PMD.
src/main/java/com/alibaba/fastjson/serializer/BooleanCodec.java
8 issues
Line: 45
return;
}
if (value.booleanValue()) {
out.write("true");
} else {
out.write("false");
}
}
Reported by PMD.
Line: 69
int intValue = lexer.intValue();
lexer.nextToken(JSONToken.COMMA);
if (intValue == 1) {
boolObj = Boolean.TRUE;
} else {
boolObj = Boolean.FALSE;
}
} else {
Reported by PMD.
Line: 83
boolObj = TypeUtils.castToBoolean(value);
}
} catch (Exception ex) {
throw new JSONException("parseBoolean error, field : " + fieldName, ex);
}
if (clazz == AtomicBoolean.class) {
return (T) new AtomicBoolean(boolObj.booleanValue());
Reported by PMD.
Line: 61
try {
if (lexer.token() == JSONToken.TRUE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.TRUE;
} else if (lexer.token() == JSONToken.FALSE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.FALSE;
} else if (lexer.token() == JSONToken.LITERAL_INT) {
int intValue = lexer.intValue();
Reported by PMD.
Line: 64
boolObj = Boolean.TRUE;
} else if (lexer.token() == JSONToken.FALSE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.FALSE;
} else if (lexer.token() == JSONToken.LITERAL_INT) {
int intValue = lexer.intValue();
lexer.nextToken(JSONToken.COMMA);
if (intValue == 1) {
Reported by PMD.
Line: 70
lexer.nextToken(JSONToken.COMMA);
if (intValue == 1) {
boolObj = Boolean.TRUE;
} else {
boolObj = Boolean.FALSE;
}
} else {
Object value = parser.parse();
Reported by PMD.
Line: 72
if (intValue == 1) {
boolObj = Boolean.TRUE;
} else {
boolObj = Boolean.FALSE;
}
} else {
Object value = parser.parse();
if (value == null) {
Reported by PMD.
Line: 81
return null;
}
boolObj = TypeUtils.castToBoolean(value);
}
} catch (Exception ex) {
throw new JSONException("parseBoolean error, field : " + fieldName, ex);
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Bug_376_for_iso8601.java
8 issues
Line: 28
MyObj o = JSON.parseObject(s, MyObj.class, Feature.AllowISO8601DateFormat);
MyObj o2 = JSON.parseObject(s2, MyObj.class, Feature.AllowISO8601DateFormat);
System.out.println(DateFormat.getDateTimeInstance().format(o.getDate()));
System.out.println(DateFormat.getDateTimeInstance().format(o2.getDate()));
// 修复之前输出
// 2015-7-22 19:13:42
// 2015-7-23 3:13:42
Reported by PMD.
Line: 29
MyObj o2 = JSON.parseObject(s2, MyObj.class, Feature.AllowISO8601DateFormat);
System.out.println(DateFormat.getDateTimeInstance().format(o.getDate()));
System.out.println(DateFormat.getDateTimeInstance().format(o2.getDate()));
// 修复之前输出
// 2015-7-22 19:13:42
// 2015-7-23 3:13:42
Reported by PMD.
Line: 20
public class Bug_376_for_iso8601 extends TestCase {
public void test_fix() {
String s = "{date: \"2015-07-22T19:13:42Z\"}";
String s2 = "{date: \"2015-07-22T19:13:42.000Z\"}";
MyObj o = JSON.parseObject(s, MyObj.class, Feature.AllowISO8601DateFormat);
Reported by PMD.
Line: 20
public class Bug_376_for_iso8601 extends TestCase {
public void test_fix() {
String s = "{date: \"2015-07-22T19:13:42Z\"}";
String s2 = "{date: \"2015-07-22T19:13:42.000Z\"}";
MyObj o = JSON.parseObject(s, MyObj.class, Feature.AllowISO8601DateFormat);
Reported by PMD.
Line: 28
MyObj o = JSON.parseObject(s, MyObj.class, Feature.AllowISO8601DateFormat);
MyObj o2 = JSON.parseObject(s2, MyObj.class, Feature.AllowISO8601DateFormat);
System.out.println(DateFormat.getDateTimeInstance().format(o.getDate()));
System.out.println(DateFormat.getDateTimeInstance().format(o2.getDate()));
// 修复之前输出
// 2015-7-22 19:13:42
// 2015-7-23 3:13:42
Reported by PMD.
Line: 28
MyObj o = JSON.parseObject(s, MyObj.class, Feature.AllowISO8601DateFormat);
MyObj o2 = JSON.parseObject(s2, MyObj.class, Feature.AllowISO8601DateFormat);
System.out.println(DateFormat.getDateTimeInstance().format(o.getDate()));
System.out.println(DateFormat.getDateTimeInstance().format(o2.getDate()));
// 修复之前输出
// 2015-7-22 19:13:42
// 2015-7-23 3:13:42
Reported by PMD.
Line: 29
MyObj o2 = JSON.parseObject(s2, MyObj.class, Feature.AllowISO8601DateFormat);
System.out.println(DateFormat.getDateTimeInstance().format(o.getDate()));
System.out.println(DateFormat.getDateTimeInstance().format(o2.getDate()));
// 修复之前输出
// 2015-7-22 19:13:42
// 2015-7-23 3:13:42
Reported by PMD.
Line: 29
MyObj o2 = JSON.parseObject(s2, MyObj.class, Feature.AllowISO8601DateFormat);
System.out.println(DateFormat.getDateTimeInstance().format(o.getDate()));
System.out.println(DateFormat.getDateTimeInstance().format(o2.getDate()));
// 修复之前输出
// 2015-7-22 19:13:42
// 2015-7-23 3:13:42
Reported by PMD.
src/test/java/com/alibaba/json/test/a/SpecialTest.java
8 issues
Line: 16
count++;
}
}
System.out.println(count);
}
static boolean isSpecial(char ch, int features) {
// if (ch > ']') {
// return false;
// }
Reported by PMD.
Line: 5
import com.alibaba.fastjson.serializer.SerializerFeature;
public class SpecialTest {
public static void main(String[] args) throws Exception {
int count = 0;
for (int i = 0; i < 1000; ++i) {
Reported by PMD.
Line: 7
public class SpecialTest {
public static void main(String[] args) throws Exception {
int count = 0;
for (int i = 0; i < 1000; ++i) {
char ch = (char) i;
if(isSpecial(ch, 0)) {
Reported by PMD.
Line: 23
// return false;
// }
if (ch == ' ') { // 32
return false;
}
if (ch == '/') { // 47
return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);
Reported by PMD.
Line: 27
return false;
}
if (ch == '/') { // 47
return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);
}
if (ch > '#' // 35
&& ch != '\\' // 92
Reported by PMD.
Line: 37
return false;
}
if (ch <= 0x1F // 31
|| ch == '\\' // 92
|| ch == '"' // 34
) {
return true;
}
Reported by PMD.
Line: 9
public static void main(String[] args) throws Exception {
int count = 0;
for (int i = 0; i < 1000; ++i) {
char ch = (char) i;
if(isSpecial(ch, 0)) {
count++;
}
Reported by PMD.
Line: 13
for (int i = 0; i < 1000; ++i) {
char ch = (char) i;
if(isSpecial(ch, 0)) {
count++;
}
}
System.out.println(count);
}
static boolean isSpecial(char ch, int features) {
Reported by PMD.
src/test/java/com/alibaba/json/test/dubbo/Person.java
8 issues
Line: 25
*
* @author tony.chenl
*/
public class Person implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
Reported by PMD.
Line: 25
*
* @author tony.chenl
*/
public class Person implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
Reported by PMD.
Line: 25
*
* @author tony.chenl
*/
public class Person implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
Reported by PMD.
Line: 114
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
Reported by PMD.
Line: 114
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
Reported by PMD.
Line: 114
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
Reported by PMD.
Line: 114
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
Reported by PMD.
Line: 147
return false;
} else if (!personId.equals(other.personId))
return false;
if (status != other.status)
return false;
return true;
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_List2.java
8 issues
Line: 22
A a = new A();
a.setList(Collections.singletonList(new B()));
String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
System.out.println(text);
Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_List2$A\",\"list\":[{\"id\":0}]}",
text);
A a1 = (A) JSON.parse(text);
Reported by PMD.
Line: 14
import com.alibaba.fastjson.serializer.SerializerFeature;
public class WriteClassNameTest_List2 extends TestCase {
protected void setUp() throws Exception {
ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_List2");
}
public void test_list() throws Exception {
A a = new A();
Reported by PMD.
Line: 15
public class WriteClassNameTest_List2 extends TestCase {
protected void setUp() throws Exception {
ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_List2");
}
public void test_list() throws Exception {
A a = new A();
a.setList(Collections.singletonList(new B()));
Reported by PMD.
Line: 18
ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_List2");
}
public void test_list() throws Exception {
A a = new A();
a.setList(Collections.singletonList(new B()));
String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
System.out.println(text);
Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_List2$A\",\"list\":[{\"id\":0}]}",
Reported by PMD.
Line: 28
A a1 = (A) JSON.parse(text);
Assert.assertEquals(1, a1.getList().size());
Assert.assertTrue(a1.getList().get(0) instanceof B);
}
public static class A {
Reported by PMD.
Line: 28
A a1 = (A) JSON.parse(text);
Assert.assertEquals(1, a1.getList().size());
Assert.assertTrue(a1.getList().get(0) instanceof B);
}
public static class A {
Reported by PMD.
Line: 29
A a1 = (A) JSON.parse(text);
Assert.assertEquals(1, a1.getList().size());
Assert.assertTrue(a1.getList().get(0) instanceof B);
}
public static class A {
private List<B> list;
Reported by PMD.
Line: 29
A a1 = (A) JSON.parse(text);
Assert.assertEquals(1, a1.getList().size());
Assert.assertTrue(a1.getList().get(0) instanceof B);
}
public static class A {
private List<B> list;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_float2_private.java
8 issues
Line: 13
import junit.framework.TestCase;
public class WriteAsArray_float2_private extends TestCase {
public void test_0 () throws Exception {
VO vo = new VO();
vo.setId(123F);
vo.setName("wenshao");
String text = JSON.toJSONString(vo, SerializerFeature.BeanToArray);
Reported by PMD.
Line: 26
Assert.assertEquals(vo.name, vo2.name);
}
public void test_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("[123.A,\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 36
Assert.assertNotNull(error);
}
public void test_error1() throws Exception {
Exception error = null;
try {
JSON.parseObject("[\"A\",\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 46
Assert.assertNotNull(error);
}
public void test_error2() throws Exception {
Exception error = null;
try {
JSON.parseObject("[123:\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 56
Assert.assertNotNull(error);
}
private static class VO {
private float id;
private String name;
public float getId() {
return id;
Reported by PMD.
Line: 27
}
public void test_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("[123.A,\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
Line: 37
}
public void test_error1() throws Exception {
Exception error = null;
try {
JSON.parseObject("[\"A\",\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
Line: 47
}
public void test_error2() throws Exception {
Exception error = null;
try {
JSON.parseObject("[123:\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_float2_public.java
8 issues
Line: 13
import junit.framework.TestCase;
public class WriteAsArray_float2_public extends TestCase {
public void test_0 () throws Exception {
VO vo = new VO();
vo.setId(123F);
vo.setName("wenshao");
String text = JSON.toJSONString(vo, SerializerFeature.BeanToArray);
Reported by PMD.
Line: 26
Assert.assertEquals(vo.name, vo2.name);
}
public void test_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("[123.A,\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 36
Assert.assertNotNull(error);
}
public void test_error1() throws Exception {
Exception error = null;
try {
JSON.parseObject("[\"A\",\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 46
Assert.assertNotNull(error);
}
public void test_error2() throws Exception {
Exception error = null;
try {
JSON.parseObject("[123:\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 56
Assert.assertNotNull(error);
}
public static class VO {
private float id;
private String name;
public float getId() {
return id;
Reported by PMD.
Line: 27
}
public void test_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("[123.A,\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
Line: 37
}
public void test_error1() throws Exception {
Exception error = null;
try {
JSON.parseObject("[\"A\",\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
Line: 47
}
public void test_error2() throws Exception {
Exception error = null;
try {
JSON.parseObject("[123:\"wenshao\"]", VO.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.