The following issues were found
src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_630.java
19 issues
Line: 14
public class Bug_for_issue_630 extends TestCase {
public void test_for_issue_null() throws Exception {
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
Reported by PMD.
Line: 14
public class Bug_for_issue_630 extends TestCase {
public void test_for_issue_null() throws Exception {
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
Reported by PMD.
Line: 17
public void test_for_issue_null() throws Exception {
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
// model.persons = new ArrayList<Person>();
// model.persons.add(new Person());
Reported by PMD.
Line: 18
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
// model.persons = new ArrayList<Person>();
// model.persons.add(new Person());
String str = JSON.toJSONString(model, SerializerFeature.BeanToArray);
Reported by PMD.
Line: 28
JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
}
public void test_for_issue_empty() throws Exception {
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
Reported by PMD.
Line: 28
JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
}
public void test_for_issue_empty() throws Exception {
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
Reported by PMD.
Line: 31
public void test_for_issue_empty() throws Exception {
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
model.persons = new ArrayList<Person>();
// model.persons.add(new Person());
Reported by PMD.
Line: 32
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
model.persons = new ArrayList<Person>();
// model.persons.add(new Person());
String str = JSON.toJSONString(model, SerializerFeature.BeanToArray);
Reported by PMD.
Line: 42
JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
}
public void test_for_issue_one() throws Exception {
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
Reported by PMD.
Line: 42
JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
}
public void test_for_issue_one() throws Exception {
Model model = new Model();
model.id = 123;
model.name = null;
model.modelName = null;
model.isFlay = false;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_scanSymbol.java
19 issues
Line: 19
*
* @author wenshao[szujobs@hotmail.com]
*/
public class JSONScannerTest_scanSymbol extends TestCase {
public void test_0() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\\n\"");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
assertEquals(0, hashCode);
Reported by PMD.
Line: 21
*/
public class JSONScannerTest_scanSymbol extends TestCase {
public void test_0() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\\n\"");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
assertEquals(0, hashCode);
Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
}
Reported by PMD.
Line: 23
public void test_0() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\\n\"");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
assertEquals(0, hashCode);
Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
}
public void test_1() throws Exception {
Reported by PMD.
Line: 24
public void test_0() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\\n\"");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
assertEquals(0, hashCode);
Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
}
public void test_1() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\"},");
Reported by PMD.
Line: 28
Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
}
public void test_1() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\"},");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
Assert.assertEquals(fnv_hash("aa"), hashCode);
Assert.assertEquals(JSONScanner.END, lexer.matchStat());
Assert.assertEquals(JSONToken.COMMA, lexer.token());
Reported by PMD.
Line: 36
Assert.assertEquals(JSONToken.COMMA, lexer.token());
}
public void test_2() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\"}]");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
Assert.assertEquals(fnv_hash("aa"), hashCode);
Assert.assertEquals(JSONScanner.END, lexer.matchStat());
Assert.assertEquals(JSONToken.RBRACKET, lexer.token());
Reported by PMD.
Line: 44
Assert.assertEquals(JSONToken.RBRACKET, lexer.token());
}
public void test_3() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\"}}");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
Assert.assertEquals(fnv_hash("aa"), hashCode);
Assert.assertEquals(JSONScanner.END, lexer.matchStat());
Assert.assertEquals(JSONToken.RBRACE, lexer.token());
Reported by PMD.
Line: 52
Assert.assertEquals(JSONToken.RBRACE, lexer.token());
}
public void test_4() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\"}");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
Assert.assertEquals(fnv_hash("aa"), hashCode);
Assert.assertEquals(JSONScanner.END, lexer.matchStat());
Assert.assertEquals(JSONToken.EOF, lexer.token());
Reported by PMD.
Line: 60
Assert.assertEquals(JSONToken.EOF, lexer.token());
}
public void test_6() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\"}{");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
Assert.assertEquals(0, hashCode);
Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
}
Reported by PMD.
Line: 67
Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
}
public void test_7() throws Exception {
JSONScanner lexer = new JSONScanner("\"value\":\"aa\"");
long hashCode = lexer.scanFieldSymbol("\"value\":".toCharArray());
Assert.assertEquals(0, hashCode);
Assert.assertEquals(JSONScanner.NOT_MATCH, lexer.matchStat());
}
Reported by PMD.
src/main/java/com/alibaba/fastjson/JSONPatch.java
19 issues
Line: 73
if (JSONScanner.isWhitespace(ch)) {
continue;
}
return ch == '{';
}
return false;
}
Reported by PMD.
Line: 8
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.JSONScanner;
public class JSONPatch {
public static String apply(String original, String patch) {
Object object
= apply(
JSON.parse(original, Feature.OrderedField), patch);
return JSON.toJSONString(object);
Reported by PMD.
Line: 8
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.JSONScanner;
public class JSONPatch {
public static String apply(String original, String patch) {
Object object
= apply(
JSON.parse(original, Feature.OrderedField), patch);
return JSON.toJSONString(object);
Reported by PMD.
Line: 16
return JSON.toJSONString(object);
}
public static Object apply(Object object, String patch) {
Operation[] operations;
if (isObject(patch)) {
operations = new Operation[] {
JSON.parseObject(patch, Operation.class)};
} else {
Reported by PMD.
Line: 16
return JSON.toJSONString(object);
}
public static Object apply(Object object, String patch) {
Operation[] operations;
if (isObject(patch)) {
operations = new Operation[] {
JSON.parseObject(patch, Operation.class)};
} else {
Reported by PMD.
Line: 29
JSONPath path = JSONPath.compile(op.path);
switch (op.type) {
case add:
path.patchAdd(object, op.value, false);
break;
case replace:
path.patchAdd(object, op.value, true);
break;
case remove:
Reported by PMD.
Line: 32
path.patchAdd(object, op.value, false);
break;
case replace:
path.patchAdd(object, op.value, true);
break;
case remove:
path.remove(object);
break;
case copy:
Reported by PMD.
Line: 35
path.patchAdd(object, op.value, true);
break;
case remove:
path.remove(object);
break;
case copy:
case move:
JSONPath from = JSONPath.compile(op.from);
Object fromValue = from.eval(object);
Reported by PMD.
Line: 40
case copy:
case move:
JSONPath from = JSONPath.compile(op.from);
Object fromValue = from.eval(object);
if (op.type == OperationType.move) {
boolean success = from.remove(object);
if (!success) {
throw new JSONException("json patch move error : " + op.from + " -> " + op.path);
}
Reported by PMD.
Line: 42
JSONPath from = JSONPath.compile(op.from);
Object fromValue = from.eval(object);
if (op.type == OperationType.move) {
boolean success = from.remove(object);
if (!success) {
throw new JSONException("json patch move error : " + op.from + " -> " + op.path);
}
}
path.set(object, fromValue);
Reported by PMD.
src/test/java/com/alibaba/json/test/codec/Jackson2AfterBurnCodec.java
19 issues
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.
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.
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.
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.
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.
Line: 19
public class Jackson2AfterBurnCodec implements Codec {
private ObjectMapper mapper = new ObjectMapper();
public Jackson2AfterBurnCodec() {
mapper.registerModule(new AfterburnerModule());
}
Reported by PMD.
Line: 19
public class Jackson2AfterBurnCodec implements Codec {
private ObjectMapper mapper = new ObjectMapper();
public Jackson2AfterBurnCodec() {
mapper.registerModule(new AfterburnerModule());
}
Reported by PMD.
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.
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.
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/util/ServiceLoader.java
19 issues
Line: 13
import java.util.HashSet;
import java.util.Set;
public class ServiceLoader {
private static final String PREFIX = "META-INF/services/";
private static final Set<String> loadedUrls = new HashSet<String>();
Reported by PMD.
Line: 34
try {
Enumeration<URL> urls = classLoader.getResources(path);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (loadedUrls.contains(url.toString())) {
continue;
}
load(url, serviceNames);
Reported by PMD.
Line: 35
try {
Enumeration<URL> urls = classLoader.getResources(path);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (loadedUrls.contains(url.toString())) {
continue;
}
load(url, serviceNames);
loadedUrls.add(url.toString());
Reported by PMD.
Line: 36
Enumeration<URL> urls = classLoader.getResources(path);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (loadedUrls.contains(url.toString())) {
continue;
}
load(url, serviceNames);
loadedUrls.add(url.toString());
}
Reported by PMD.
Line: 40
continue;
}
load(url, serviceNames);
loadedUrls.add(url.toString());
}
} catch (Throwable ex) {
// skip
}
Reported by PMD.
Line: 42
load(url, serviceNames);
loadedUrls.add(url.toString());
}
} catch (Throwable ex) {
// skip
}
for (String serviceName : serviceNames) {
try {
Reported by PMD.
Line: 42
load(url, serviceNames);
loadedUrls.add(url.toString());
}
} catch (Throwable ex) {
// skip
}
for (String serviceName : serviceNames) {
try {
Reported by PMD.
Line: 49
for (String serviceName : serviceNames) {
try {
Class<?> serviceClass = classLoader.loadClass(serviceName);
T service = (T) serviceClass.newInstance();
services.add(service);
} catch (Exception e) {
// skip
}
}
Reported by PMD.
Line: 51
Class<?> serviceClass = classLoader.loadClass(serviceName);
T service = (T) serviceClass.newInstance();
services.add(service);
} catch (Exception e) {
// skip
}
}
return services;
Reported by PMD.
Line: 51
Class<?> serviceClass = classLoader.loadClass(serviceName);
T service = (T) serviceClass.newInstance();
services.add(service);
} catch (Exception e) {
// skip
}
}
return services;
Reported by PMD.
src/test/java/com/alibaba/json/test/UTF8Test.java
19 issues
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.
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.
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.
Line: 72
charset.newEncoder().encode(CharBuffer.wrap(chars));
}
long millis = System.currentTimeMillis() - start;
System.out.println("f2 millis : " + millis);
}
}
Reported by PMD.
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.
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.
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.
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.
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.
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/parser/deser/list/ListStringFieldTest_stream_array_2.java
19 issues
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
src/test/java/com/alibaba/json/bvt/parser/JSONReaderTest_object_string.java
19 issues
Line: 14
public class JSONReaderTest_object_string extends TestCase {
String text = "{\"f0\":\"0\",\"f1\":\"1\",\"f2\":\"2\",\"f3\":\"3\",\"f4\":\"4\", " + //
"\"f5\":\"5\",\"f6\":\"6\",\"f7\":\"7\",\"f8\":\"8\",\"f9\":\"9\"}";
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
Reported by PMD.
Line: 17
String text = "{\"f0\":\"0\",\"f1\":\"1\",\"f2\":\"2\",\"f3\":\"3\",\"f4\":\"4\", " + //
"\"f5\":\"5\",\"f6\":\"6\",\"f7\":\"7\",\"f8\":\"8\",\"f9\":\"9\"}";
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
reader.startObject();
Reported by PMD.
Line: 25
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
String value = reader.readString();
count++;
}
Assert.assertEquals(10, count);
Reported by PMD.
Line: 26
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
String value = reader.readString();
count++;
}
Assert.assertEquals(10, count);
reader.endObject();
Reported by PMD.
Line: 35
reader.close();
}
public void test_read_1() throws Exception {
JSONReader reader = new JSONReader(new JSONScanner(text));
reader.startObject();
int count = 0;
Reported by PMD.
Line: 42
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
Long value = reader.readLong();
count++;
}
Assert.assertEquals(10, count);
Reported by PMD.
Line: 43
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
Long value = reader.readLong();
count++;
}
Assert.assertEquals(10, count);
reader.endObject();
Reported by PMD.
Line: 23
reader.startObject();
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
String value = reader.readString();
count++;
}
Reported by PMD.
Line: 25
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
String value = reader.readString();
count++;
}
Assert.assertEquals(10, count);
Reported by PMD.
Line: 25
int count = 0;
while (reader.hasNext()) {
String key = (String) reader.readObject();
String value = reader.readString();
count++;
}
Assert.assertEquals(10, count);
Reported by PMD.
src/main/java/com/alibaba/fastjson/serializer/CharArrayCodec.java
19 issues
Line: 14
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
public class CharArrayCodec implements ObjectDeserializer {
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
return (T) deserialze(parser);
}
Reported by PMD.
Line: 14
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
public class CharArrayCodec implements ObjectDeserializer {
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
return (T) deserialze(parser);
}
Reported by PMD.
Line: 22
}
@SuppressWarnings("unchecked")
public static <T> T deserialze(DefaultJSONParser parser) {
final JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.LITERAL_STRING) {
String val = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toCharArray();
Reported by PMD.
Line: 22
}
@SuppressWarnings("unchecked")
public static <T> T deserialze(DefaultJSONParser parser) {
final JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.LITERAL_STRING) {
String val = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toCharArray();
Reported by PMD.
Line: 22
}
@SuppressWarnings("unchecked")
public static <T> T deserialze(DefaultJSONParser parser) {
final JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.LITERAL_STRING) {
String val = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toCharArray();
Reported by PMD.
Line: 22
}
@SuppressWarnings("unchecked")
public static <T> T deserialze(DefaultJSONParser parser) {
final JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.LITERAL_STRING) {
String val = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toCharArray();
Reported by PMD.
Line: 24
@SuppressWarnings("unchecked")
public static <T> T deserialze(DefaultJSONParser parser) {
final JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.LITERAL_STRING) {
String val = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toCharArray();
}
Reported by PMD.
Line: 27
if (lexer.token() == JSONToken.LITERAL_STRING) {
String val = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toCharArray();
}
if (lexer.token() == JSONToken.LITERAL_INT) {
Number val = lexer.integerValue();
lexer.nextToken(JSONToken.COMMA);
Reported by PMD.
Line: 30
return (T) val.toCharArray();
}
if (lexer.token() == JSONToken.LITERAL_INT) {
Number val = lexer.integerValue();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toString().toCharArray();
}
Reported by PMD.
Line: 33
if (lexer.token() == JSONToken.LITERAL_INT) {
Number val = lexer.integerValue();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toString().toCharArray();
}
Object value = parser.parse();
if (value instanceof String) {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/basicType/FloatTest3_random.java
19 issues
Line: 13
import java.util.Random;
public class FloatTest3_random extends TestCase {
public void test_ran() throws Exception {
Random rand = new Random();
for (int i = 0; i < 1000 * 1000 * 1; ++i) {
float val = rand.nextFloat();
Reported by PMD.
Line: 19
for (int i = 0; i < 1000 * 1000 * 1; ++i) {
float val = rand.nextFloat();
String str = JSON.toJSONString(new Model(val));
Model m = JSON.parseObject(str, Model.class);
assertEquals(val, m.value);
}
}
Reported by PMD.
Line: 22
String str = JSON.toJSONString(new Model(val));
Model m = JSON.parseObject(str, Model.class);
assertEquals(val, m.value);
}
}
public void test_ran_2() throws Exception {
Random rand = new Random();
Reported by PMD.
Line: 26
}
}
public void test_ran_2() throws Exception {
Random rand = new Random();
for (int i = 0; i < 1000 * 1000 * 1; ++i) {
float val = rand.nextFloat();
Reported by PMD.
Line: 32
for (int i = 0; i < 1000 * 1000 * 1; ++i) {
float val = rand.nextFloat();
String str = JSON.toJSONString(new Model(val), SerializerFeature.BeanToArray);
Model m = JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
assertEquals(val, m.value);
}
}
Reported by PMD.
Line: 35
String str = JSON.toJSONString(new Model(val), SerializerFeature.BeanToArray);
Model m = JSON.parseObject(str, Model.class, Feature.SupportArrayToBean);
assertEquals(val, m.value);
}
}
public void test_ran_3() throws Exception {
Random rand = new Random();
Reported by PMD.
Line: 39
}
}
public void test_ran_3() throws Exception {
Random rand = new Random();
for (int i = 0; i < 1000 * 1000 * 1; ++i) {
float val = rand.nextFloat();
Reported by PMD.
Line: 45
for (int i = 0; i < 1000 * 1000 * 1; ++i) {
float val = rand.nextFloat();
String str = JSON.toJSONString(Collections.singletonMap("val", val));
float val2 = JSON.parseObject(str).getFloatValue("val");
assertEquals(val, val2);
}
}
Reported by PMD.
Line: 46
float val = rand.nextFloat();
String str = JSON.toJSONString(Collections.singletonMap("val", val));
float val2 = JSON.parseObject(str).getFloatValue("val");
assertEquals(val, val2);
}
}
Reported by PMD.
Line: 48
String str = JSON.toJSONString(Collections.singletonMap("val", val));
float val2 = JSON.parseObject(str).getFloatValue("val");
assertEquals(val, val2);
}
}
public void test_ran_4() throws Exception {
Random rand = new Random();
Reported by PMD.