The following issues were found
src/test/java/com/alibaba/json/bvt/parser/deser/FieldDeserializerTest10.java
7 issues
Line: 9
public class FieldDeserializerTest10 extends TestCase {
public void test_0 () throws Exception {
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}\n\t", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n\t", V1.class).id);
Reported by PMD.
Line: 10
public class FieldDeserializerTest10 extends TestCase {
public void test_0 () throws Exception {
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}\n\t", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n\t", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\n}", V1.class).id);
Reported by PMD.
Line: 11
public class FieldDeserializerTest10 extends TestCase {
public void test_0 () throws Exception {
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}\n\t", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n\t", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\n}", V1.class).id);
}
Reported by PMD.
Line: 12
public void test_0 () throws Exception {
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}\n\t", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n\t", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\n}", V1.class).id);
}
Reported by PMD.
Line: 13
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}\n\t", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n\t", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\n}", V1.class).id);
}
public static class VO {
Reported by PMD.
Line: 14
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\t}\n\t", VO.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n\t", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\n}", V1.class).id);
}
public static class VO {
public Type id;
Reported by PMD.
Line: 15
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\" }\n\t", V1.class).id);
Assert.assertEquals(Type.Big, JSON.parseObject("{\"id\":\"Big\"\n}", V1.class).id);
}
public static class VO {
public Type id;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/deser/GetOnlyCollectionTest.java
7 issues
Line: 13
public class GetOnlyCollectionTest extends TestCase {
public void test_getOnly() throws Exception {
VO vo = JSON.parseObject("{\"items\":[\"a\",\"b\"]}", VO.class);
Assert.assertEquals(2, vo.getItems().size());
Assert.assertEquals("a", vo.getItems().get(0));
Assert.assertEquals("b", vo.getItems().get(1));
}
Reported by PMD.
Line: 15
public void test_getOnly() throws Exception {
VO vo = JSON.parseObject("{\"items\":[\"a\",\"b\"]}", VO.class);
Assert.assertEquals(2, vo.getItems().size());
Assert.assertEquals("a", vo.getItems().get(0));
Assert.assertEquals("b", vo.getItems().get(1));
}
public static class VO {
Reported by PMD.
Line: 15
public void test_getOnly() throws Exception {
VO vo = JSON.parseObject("{\"items\":[\"a\",\"b\"]}", VO.class);
Assert.assertEquals(2, vo.getItems().size());
Assert.assertEquals("a", vo.getItems().get(0));
Assert.assertEquals("b", vo.getItems().get(1));
}
public static class VO {
Reported by PMD.
Line: 16
public void test_getOnly() throws Exception {
VO vo = JSON.parseObject("{\"items\":[\"a\",\"b\"]}", VO.class);
Assert.assertEquals(2, vo.getItems().size());
Assert.assertEquals("a", vo.getItems().get(0));
Assert.assertEquals("b", vo.getItems().get(1));
}
public static class VO {
private final List<String> items = new ArrayList<String>();
Reported by PMD.
Line: 16
public void test_getOnly() throws Exception {
VO vo = JSON.parseObject("{\"items\":[\"a\",\"b\"]}", VO.class);
Assert.assertEquals(2, vo.getItems().size());
Assert.assertEquals("a", vo.getItems().get(0));
Assert.assertEquals("b", vo.getItems().get(1));
}
public static class VO {
private final List<String> items = new ArrayList<String>();
Reported by PMD.
Line: 17
VO vo = JSON.parseObject("{\"items\":[\"a\",\"b\"]}", VO.class);
Assert.assertEquals(2, vo.getItems().size());
Assert.assertEquals("a", vo.getItems().get(0));
Assert.assertEquals("b", vo.getItems().get(1));
}
public static class VO {
private final List<String> items = new ArrayList<String>();
Reported by PMD.
Line: 17
VO vo = JSON.parseObject("{\"items\":[\"a\",\"b\"]}", VO.class);
Assert.assertEquals(2, vo.getItems().size());
Assert.assertEquals("a", vo.getItems().get(0));
Assert.assertEquals("b", vo.getItems().get(1));
}
public static class VO {
private final List<String> items = new ArrayList<String>();
Reported by PMD.
src/test/java/com/alibaba/json/bvt/serializer/filters/PropertyPathTest2.java
7 issues
Line: 15
public class PropertyPathTest2 extends TestCase {
public void test_path() throws Exception {
Person p1 = new Person();
p1.setId(100);
Person c1 = new Person();
c1.setId(1000);
Reported by PMD.
Line: 25
Person c2 = new Person();
c2.setId(2000);
p1.getChildren().add(c1);
p1.getChildren().add(c2);
Assert.assertEquals("{\"children\":[{\"id\":1000},{\"id\":2000}],\"id\":100}", JSON.toJSONString(p1, new MyPropertyPreFilter()));
}
Reported by PMD.
Line: 26
c2.setId(2000);
p1.getChildren().add(c1);
p1.getChildren().add(c2);
Assert.assertEquals("{\"children\":[{\"id\":1000},{\"id\":2000}],\"id\":100}", JSON.toJSONString(p1, new MyPropertyPreFilter()));
}
public static class MyPropertyPreFilter implements PropertyPreFilter {
Reported by PMD.
Line: 34
public static class MyPropertyPreFilter implements PropertyPreFilter {
public boolean apply(JSONSerializer serializer, Object source, String name) {
String path = serializer.getContext().toString() + "." + name;
if (path.endsWith("].children")) {
return false;
}
Reported by PMD.
Line: 36
public boolean apply(JSONSerializer serializer, Object source, String name) {
String path = serializer.getContext().toString() + "." + name;
if (path.endsWith("].children")) {
return false;
}
return true;
}
Reported by PMD.
Line: 36
public boolean apply(JSONSerializer serializer, Object source, String name) {
String path = serializer.getContext().toString() + "." + name;
if (path.endsWith("].children")) {
return false;
}
return true;
}
Reported by PMD.
Line: 45
}
public static class Person {
private int id;
private List<Person> children = new ArrayList<Person>();
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/deser/deny/DenyTest4.java
7 issues
Line: 14
public class DenyTest4 extends TestCase {
public void test_0() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest4$MyClassLoader\"}", Object.class);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 21
} catch (JSONException ex) {
error = ex;
}
assertNotNull(error);
}
public static class MyClassLoader extends ClassLoader {
}
Reported by PMD.
Line: 5
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.json.bvtVO.deny.A;
import junit.framework.TestCase;
import org.junit.Assert;
import java.util.Properties;
Reported by PMD.
Line: 6
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.json.bvtVO.deny.A;
import junit.framework.TestCase;
import org.junit.Assert;
import java.util.Properties;
Reported by PMD.
Line: 8
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.json.bvtVO.deny.A;
import junit.framework.TestCase;
import org.junit.Assert;
import java.util.Properties;
public class DenyTest4 extends TestCase {
Reported by PMD.
Line: 10
import junit.framework.TestCase;
import org.junit.Assert;
import java.util.Properties;
public class DenyTest4 extends TestCase {
public void test_0() throws Exception {
Exception error = null;
Reported by PMD.
Line: 15
public class DenyTest4 extends TestCase {
public void test_0() throws Exception {
Exception error = null;
try {
JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest4$MyClassLoader\"}", Object.class);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/bug/Issue780.java
7 issues
Line: 11
* Created by wenshao on 16/8/25.
*/
public class Issue780 extends TestCase {
public void test_for_issue() throws Exception {
JSONObject json = new JSONObject();
json.put("robj", "{abc: 123}");
JSONObject robj = json.getJSONObject("robj");
assertEquals(123, robj.get("abc"));
}
Reported by PMD.
Line: 13
public class Issue780 extends TestCase {
public void test_for_issue() throws Exception {
JSONObject json = new JSONObject();
json.put("robj", "{abc: 123}");
JSONObject robj = json.getJSONObject("robj");
assertEquals(123, robj.get("abc"));
}
public void test_for_issue_array() throws Exception {
Reported by PMD.
Line: 15
JSONObject json = new JSONObject();
json.put("robj", "{abc: 123}");
JSONObject robj = json.getJSONObject("robj");
assertEquals(123, robj.get("abc"));
}
public void test_for_issue_array() throws Exception {
JSONObject json = new JSONObject();
json.put("robj", "[123]");
Reported by PMD.
Line: 15
JSONObject json = new JSONObject();
json.put("robj", "{abc: 123}");
JSONObject robj = json.getJSONObject("robj");
assertEquals(123, robj.get("abc"));
}
public void test_for_issue_array() throws Exception {
JSONObject json = new JSONObject();
json.put("robj", "[123]");
Reported by PMD.
Line: 18
assertEquals(123, robj.get("abc"));
}
public void test_for_issue_array() throws Exception {
JSONObject json = new JSONObject();
json.put("robj", "[123]");
JSONArray robj = json.getJSONArray("robj");
assertEquals(123, robj.get(0));
}
Reported by PMD.
Line: 22
JSONObject json = new JSONObject();
json.put("robj", "[123]");
JSONArray robj = json.getJSONArray("robj");
assertEquals(123, robj.get(0));
}
}
Reported by PMD.
Line: 22
JSONObject json = new JSONObject();
json.put("robj", "[123]");
JSONArray robj = json.getJSONArray("robj");
assertEquals(123, robj.get(0));
}
}
Reported by PMD.
src/main/java/com/alibaba/fastjson/serializer/IntegerCodec.java
7 issues
Line: 54
out.writeInt(value.intValue());
}
if (out.isEnabled(SerializerFeature.WriteClassName)) {
Class<?> clazz = value.getClass();
if (clazz == Byte.class) {
out.write('B');
} else if (clazz == Short.class) {
out.write('S');
Reported by PMD.
Line: 68
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
final JSONLexer lexer = parser.lexer;
final int token = lexer.token();
if (token == JSONToken.NULL) {
lexer.nextToken(JSONToken.COMMA);
return null;
}
Reported by PMD.
Line: 96
intObj = TypeUtils.castToInt(value);
}
}
} catch (Exception ex) {
String message = "parseInt error";
if (fieldName != null) {
message += (", field : " + fieldName);
}
throw new JSONException(message, ex);
Reported by PMD.
Line: 81
if (token == JSONToken.LITERAL_INT) {
int val = lexer.intValue();
lexer.nextToken(JSONToken.COMMA);
intObj = Integer.valueOf(val);
} else if (token == JSONToken.LITERAL_FLOAT) {
BigDecimal number = lexer.decimalValue();
intObj = TypeUtils.intValue(number);
lexer.nextToken(JSONToken.COMMA);
} else {
Reported by PMD.
Line: 84
intObj = Integer.valueOf(val);
} else if (token == JSONToken.LITERAL_FLOAT) {
BigDecimal number = lexer.decimalValue();
intObj = TypeUtils.intValue(number);
lexer.nextToken(JSONToken.COMMA);
} else {
if (token == JSONToken.LBRACE) {
JSONObject jsonObject = new JSONObject(true);
parser.parseObject(jsonObject);
Reported by PMD.
Line: 90
if (token == JSONToken.LBRACE) {
JSONObject jsonObject = new JSONObject(true);
parser.parseObject(jsonObject);
intObj = TypeUtils.castToInt(jsonObject);
} else {
Object value = parser.parse();
intObj = TypeUtils.castToInt(value);
}
}
Reported by PMD.
Line: 93
intObj = TypeUtils.castToInt(jsonObject);
} else {
Object value = parser.parse();
intObj = TypeUtils.castToInt(value);
}
}
} catch (Exception ex) {
String message = "parseInt error";
if (fieldName != null) {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/StringFieldTest_special_3.java
7 issues
Line: 13
import junit.framework.TestCase;
public class StringFieldTest_special_3 extends TestCase {
public void test_special() throws Exception {
Model model = new Model();
StringBuilder buf = new StringBuilder();
for (int i = Character.MIN_VALUE; i < Character.MAX_VALUE; ++i) {
buf.append((char) i);
}
Reported by PMD.
Line: 29
Assert.assertEquals(model.name, model2.name);
}
public void test_special_browsecue() throws Exception {
Model model = new Model();
StringBuilder buf = new StringBuilder();
for (int i = Character.MIN_VALUE; i < Character.MAX_VALUE; ++i) {
buf.append((char) i);
}
Reported by PMD.
Line: 42
String text = writer.toString();
text = text.replaceAll("<", "<");
text = text.replaceAll(">", ">");
Model model2 = JSON.parseObject(text, Model.class);
assertEquals(model.name, model2.name);
}
Reported by PMD.
Line: 43
String text = writer.toString();
text = text.replaceAll("<", "<");
text = text.replaceAll(">", ">");
Model model2 = JSON.parseObject(text, Model.class);
assertEquals(model.name, model2.name);
}
Reported by PMD.
Line: 46
text = text.replaceAll(">", ">");
Model model2 = JSON.parseObject(text, Model.class);
assertEquals(model.name, model2.name);
}
public void test_special_browsecompatible() throws Exception {
Model model = new Model();
StringBuilder buf = new StringBuilder();
Reported by PMD.
Line: 49
assertEquals(model.name, model2.name);
}
public void test_special_browsecompatible() throws Exception {
Model model = new Model();
StringBuilder buf = new StringBuilder();
for (int i = Character.MIN_VALUE; i < Character.MAX_VALUE; ++i) {
buf.append((char) i);
}
Reported by PMD.
Line: 66
private static class Model {
public String name;
}
}
Reported by PMD.
src/main/java/com/alibaba/fastjson/parser/SymbolTable.java
7 issues
Line: 25
*/
public class SymbolTable {
private final String[] symbols;
private final int indexMask;
public SymbolTable(int tableSize){
this.indexMask = tableSize - 1;
this.symbols = new String[tableSize];
Reported by PMD.
Line: 26
public class SymbolTable {
private final String[] symbols;
private final int indexMask;
public SymbolTable(int tableSize){
this.indexMask = tableSize - 1;
this.symbols = new String[tableSize];
Reported by PMD.
Line: 108
symbol = len == buffer.length() //
? buffer //
: subString(buffer, offset, len);
symbol = symbol.intern();
symbols[bucket] = symbol;
return symbol;
}
private static String subString(String src, int offset, int len) {
Reported by PMD.
Line: 56
String symbol = symbols[bucket];
if (symbol != null) {
boolean eq = true;
if (hash == symbol.hashCode() //
&& len == symbol.length()) {
for (int i = 0; i < len; i++) {
if (buffer[offset + i] != symbol.charAt(i)) {
eq = false;
Reported by PMD.
Line: 56
String symbol = symbols[bucket];
if (symbol != null) {
boolean eq = true;
if (hash == symbol.hashCode() //
&& len == symbol.length()) {
for (int i = 0; i < len; i++) {
if (buffer[offset + i] != symbol.charAt(i)) {
eq = false;
Reported by PMD.
Line: 61
&& len == symbol.length()) {
for (int i = 0; i < len; i++) {
if (buffer[offset + i] != symbol.charAt(i)) {
eq = false;
break;
}
}
} else {
eq = false;
Reported by PMD.
Line: 121
public static int hash(char[] buffer, int offset, int len) {
int h = 0;
int off = offset;
for (int i = 0; i < len; i++) {
h = 31 * h + buffer[off++];
}
return h;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/builder/BuilderTest0.java
7 issues
Line: 12
public class BuilderTest0 extends TestCase {
public void test_0() throws Exception {
VO vo = JSON.parseObject("{\"id\":12304,\"name\":\"ljw\"}", VO.class);
Assert.assertEquals(12304, vo.getId());
Assert.assertEquals("ljw", vo.getName());
}
Reported by PMD.
Line: 15
public void test_0() throws Exception {
VO vo = JSON.parseObject("{\"id\":12304,\"name\":\"ljw\"}", VO.class);
Assert.assertEquals(12304, vo.getId());
Assert.assertEquals("ljw", vo.getName());
}
@JSONType(builder=VOBuilder.class)
public static class VO {
Reported by PMD.
Line: 16
VO vo = JSON.parseObject("{\"id\":12304,\"name\":\"ljw\"}", VO.class);
Assert.assertEquals(12304, vo.getId());
Assert.assertEquals("ljw", vo.getName());
}
@JSONType(builder=VOBuilder.class)
public static class VO {
private int id;
Reported by PMD.
Line: 21
@JSONType(builder=VOBuilder.class)
public static class VO {
private int id;
private String name;
public int getId() {
return id;
}
Reported by PMD.
Line: 22
@JSONType(builder=VOBuilder.class)
public static class VO {
private int id;
private String name;
public int getId() {
return id;
}
Reported by PMD.
Line: 35
public static class VOBuilder {
private VO vo = new VO();
public VO build() {
return vo;
}
Reported by PMD.
Line: 35
public static class VOBuilder {
private VO vo = new VO();
public VO build() {
return vo;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/InetSocketAddressFieldTest.java
7 issues
Line: 14
public class InetSocketAddressFieldTest extends TestCase {
public void test_codec() throws Exception {
User user = new User();
user.setValue(new InetSocketAddress(33));
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
Reported by PMD.
Line: 24
User user1 = JSON.parseObject(text, User.class);
Assert.assertEquals(user1.getValue(), user.getValue());
}
public void test_codec_null() throws Exception {
User user = new User();
user.setValue(null);
Reported by PMD.
Line: 27
Assert.assertEquals(user1.getValue(), user.getValue());
}
public void test_codec_null() throws Exception {
User user = new User();
user.setValue(null);
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
Reported by PMD.
Line: 37
User user1 = JSON.parseObject(text, User.class);
Assert.assertEquals(user1.getValue(), user.getValue());
}
public void test_codec_null_2() throws Exception {
User user = JSON.parseObject("{\"value\":{\"address\":null,\"port\":33}}", User.class);
Reported by PMD.
Line: 40
Assert.assertEquals(user1.getValue(), user.getValue());
}
public void test_codec_null_2() throws Exception {
User user = JSON.parseObject("{\"value\":{\"address\":null,\"port\":33}}", User.class);
Assert.assertEquals(33, user.getValue().getPort());
}
Reported by PMD.
Line: 43
public void test_codec_null_2() throws Exception {
User user = JSON.parseObject("{\"value\":{\"address\":null,\"port\":33}}", User.class);
Assert.assertEquals(33, user.getValue().getPort());
}
public static class User {
private InetSocketAddress value;
Reported by PMD.
Line: 43
public void test_codec_null_2() throws Exception {
User user = JSON.parseObject("{\"value\":{\"address\":null,\"port\":33}}", User.class);
Assert.assertEquals(33, user.getValue().getPort());
}
public static class User {
private InetSocketAddress value;
Reported by PMD.