The following issues were found
src/test/java/com/alibaba/json/bvt/kotlin/Issue1524.java
7 issues
Line: 12
import java.lang.reflect.Constructor;
public class Issue1524 extends TestCase {
public void test_user() throws Exception {
ExtClassLoader classLoader = new ExtClassLoader();
Class clazz = classLoader.loadClass("DataClass");
Constructor constructor = clazz.getConstructor(String.class, String.class);
Object object = constructor.newInstance("ccc", "ddd");
Reported by PMD.
Line: 12
import java.lang.reflect.Constructor;
public class Issue1524 extends TestCase {
public void test_user() throws Exception {
ExtClassLoader classLoader = new ExtClassLoader();
Class clazz = classLoader.loadClass("DataClass");
Constructor constructor = clazz.getConstructor(String.class, String.class);
Object object = constructor.newInstance("ccc", "ddd");
Reported by PMD.
Line: 16
ExtClassLoader classLoader = new ExtClassLoader();
Class clazz = classLoader.loadClass("DataClass");
Constructor constructor = clazz.getConstructor(String.class, String.class);
Object object = constructor.newInstance("ccc", "ddd");
String json = JSON.toJSONString(object);
assertEquals("{\"Id\":\"ccc\",\"Name\":\"ddd\"}", json);
Object object2 = JSON.parseObject(json, clazz);
Reported by PMD.
Line: 17
Class clazz = classLoader.loadClass("DataClass");
Constructor constructor = clazz.getConstructor(String.class, String.class);
Object object = constructor.newInstance("ccc", "ddd");
String json = JSON.toJSONString(object);
assertEquals("{\"Id\":\"ccc\",\"Name\":\"ddd\"}", json);
Object object2 = JSON.parseObject(json, clazz);
String json2 = JSON.toJSONString(object2);
Reported by PMD.
Line: 19
Constructor constructor = clazz.getConstructor(String.class, String.class);
Object object = constructor.newInstance("ccc", "ddd");
String json = JSON.toJSONString(object);
assertEquals("{\"Id\":\"ccc\",\"Name\":\"ddd\"}", json);
Object object2 = JSON.parseObject(json, clazz);
String json2 = JSON.toJSONString(object2);
assertEquals("{\"Id\":\"ccc\",\"Name\":\"ddd\"}", json2);
}
Reported by PMD.
Line: 23
Object object2 = JSON.parseObject(json, clazz);
String json2 = JSON.toJSONString(object2);
assertEquals("{\"Id\":\"ccc\",\"Name\":\"ddd\"}", json2);
}
public static class ExtClassLoader extends ClassLoader {
public ExtClassLoader() throws IOException {
Reported by PMD.
Line: 33
{
byte[] bytes;
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/issue1526/DataClass.clazz");
bytes = IOUtils.toByteArray(is);
is.close();
super.defineClass("DataClass", bytes, 0, bytes.length);
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/BigDecimalKeyFieldTest.java
7 issues
Line: 14
import junit.framework.TestCase;
public class BigDecimalKeyFieldTest extends TestCase {
public void test_for_bigdecimal_key() throws Exception {
Map<?, ?> obj = JSON.parseObject("{1234.56:\"abc\"}", HashMap.class);
Map.Entry<?, ?> entry = obj.entrySet().iterator().next();
Assert.assertEquals("abc", entry.getValue());
Assert.assertEquals(new BigDecimal("1234.56"), entry.getKey());
}
Reported by PMD.
Line: 15
public class BigDecimalKeyFieldTest extends TestCase {
public void test_for_bigdecimal_key() throws Exception {
Map<?, ?> obj = JSON.parseObject("{1234.56:\"abc\"}", HashMap.class);
Map.Entry<?, ?> entry = obj.entrySet().iterator().next();
Assert.assertEquals("abc", entry.getValue());
Assert.assertEquals(new BigDecimal("1234.56"), entry.getKey());
}
}
Reported by PMD.
Line: 16
public class BigDecimalKeyFieldTest extends TestCase {
public void test_for_bigdecimal_key() throws Exception {
Map<?, ?> obj = JSON.parseObject("{1234.56:\"abc\"}", HashMap.class);
Map.Entry<?, ?> entry = obj.entrySet().iterator().next();
Assert.assertEquals("abc", entry.getValue());
Assert.assertEquals(new BigDecimal("1234.56"), entry.getKey());
}
}
Reported by PMD.
Line: 16
public class BigDecimalKeyFieldTest extends TestCase {
public void test_for_bigdecimal_key() throws Exception {
Map<?, ?> obj = JSON.parseObject("{1234.56:\"abc\"}", HashMap.class);
Map.Entry<?, ?> entry = obj.entrySet().iterator().next();
Assert.assertEquals("abc", entry.getValue());
Assert.assertEquals(new BigDecimal("1234.56"), entry.getKey());
}
}
Reported by PMD.
Line: 16
public class BigDecimalKeyFieldTest extends TestCase {
public void test_for_bigdecimal_key() throws Exception {
Map<?, ?> obj = JSON.parseObject("{1234.56:\"abc\"}", HashMap.class);
Map.Entry<?, ?> entry = obj.entrySet().iterator().next();
Assert.assertEquals("abc", entry.getValue());
Assert.assertEquals(new BigDecimal("1234.56"), entry.getKey());
}
}
Reported by PMD.
Line: 17
public void test_for_bigdecimal_key() throws Exception {
Map<?, ?> obj = JSON.parseObject("{1234.56:\"abc\"}", HashMap.class);
Map.Entry<?, ?> entry = obj.entrySet().iterator().next();
Assert.assertEquals("abc", entry.getValue());
Assert.assertEquals(new BigDecimal("1234.56"), entry.getKey());
}
}
Reported by PMD.
Line: 18
Map<?, ?> obj = JSON.parseObject("{1234.56:\"abc\"}", HashMap.class);
Map.Entry<?, ?> entry = obj.entrySet().iterator().next();
Assert.assertEquals("abc", entry.getValue());
Assert.assertEquals(new BigDecimal("1234.56"), entry.getKey());
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/ClassConstructorTest1.java
7 issues
Line: 9
import org.springframework.util.Assert;
public class ClassConstructorTest1 extends TestCase {
public void test_error() throws Exception {
String modelJSON = "{\"age\":12, \"name\":\"nanqi\"}";
Model model = JSON.parseObject(modelJSON, Model.class);
// Assert.notNull(model.getName());
//skip
}
Reported by PMD.
Line: 9
import org.springframework.util.Assert;
public class ClassConstructorTest1 extends TestCase {
public void test_error() throws Exception {
String modelJSON = "{\"age\":12, \"name\":\"nanqi\"}";
Model model = JSON.parseObject(modelJSON, Model.class);
// Assert.notNull(model.getName());
//skip
}
Reported by PMD.
Line: 11
public class ClassConstructorTest1 extends TestCase {
public void test_error() throws Exception {
String modelJSON = "{\"age\":12, \"name\":\"nanqi\"}";
Model model = JSON.parseObject(modelJSON, Model.class);
// Assert.notNull(model.getName());
//skip
}
public static class Model {
Reported by PMD.
Line: 16
//skip
}
public static class Model {
public Model(int age) {
this.age = age;
}
private String name;
Reported by PMD.
Line: 5
import com.alibaba.fastjson.JSON;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.util.Assert;
public class ClassConstructorTest1 extends TestCase {
public void test_error() throws Exception {
String modelJSON = "{\"age\":12, \"name\":\"nanqi\"}";
Reported by PMD.
Line: 6
import com.alibaba.fastjson.JSON;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.util.Assert;
public class ClassConstructorTest1 extends TestCase {
public void test_error() throws Exception {
String modelJSON = "{\"age\":12, \"name\":\"nanqi\"}";
Model model = JSON.parseObject(modelJSON, Model.class);
Reported by PMD.
Line: 11
public class ClassConstructorTest1 extends TestCase {
public void test_error() throws Exception {
String modelJSON = "{\"age\":12, \"name\":\"nanqi\"}";
Model model = JSON.parseObject(modelJSON, Model.class);
// Assert.notNull(model.getName());
//skip
}
public static class Model {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/DefaultExtJSONParserTest_7.java
7 issues
Line: 16
public class DefaultExtJSONParserTest_7 extends TestCase {
public void test_parse() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("1");
Assert.assertEquals(Integer.valueOf(1), parser.parse());
Exception error = null;
try {
Reported by PMD.
Line: 23
Exception error = null;
try {
parser.parse();
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
Reported by PMD.
Line: 29
Assert.assertNotNull(error);
}
public void test_parse_str() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("\"1\"");
parser.config(Feature.AllowISO8601DateFormat, true);
Assert.assertEquals("1", parser.parse());
}
Reported by PMD.
Line: 36
}
public void test_parseArray() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("[1]");
parser.config(Feature.AllowArbitraryCommas, false);
List<String> list = new ArrayList<String>();
parser.parseArray(String.class, list);
Assert.assertEquals(1, list.size());
Reported by PMD.
Line: 44
Assert.assertEquals(1, list.size());
}
public void test_parseArray_error() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("[1,2}");
parser.config(Feature.AllowArbitraryCommas, false);
List<String> list = new ArrayList<String>();
Exception error = null;
Reported by PMD.
Line: 20
DefaultJSONParser parser = new DefaultJSONParser("1");
Assert.assertEquals(Integer.valueOf(1), parser.parse());
Exception error = null;
try {
parser.parse();
} catch (Exception ex) {
error = ex;
}
Reported by PMD.
Line: 49
parser.config(Feature.AllowArbitraryCommas, false);
List<String> list = new ArrayList<String>();
Exception error = null;
try {
parser.parseArray(String.class, list);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/FastMatchCheckTest.java
7 issues
Line: 16
import junit.framework.TestCase;
public class FastMatchCheckTest extends TestCase {
public void test_match() throws Exception {
Assert.assertEquals(JSONToken.LBRACKET, AtomicCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, NumberDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, SqlDateDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LBRACKET, ObjectArrayCodec.instance.getFastMatchToken());
Reported by PMD.
Line: 17
public class FastMatchCheckTest extends TestCase {
public void test_match() throws Exception {
Assert.assertEquals(JSONToken.LBRACKET, AtomicCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, NumberDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, SqlDateDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LBRACKET, ObjectArrayCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, CharacterCodec.instance.getFastMatchToken());
Reported by PMD.
Line: 18
public class FastMatchCheckTest extends TestCase {
public void test_match() throws Exception {
Assert.assertEquals(JSONToken.LBRACKET, AtomicCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, NumberDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, SqlDateDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LBRACKET, ObjectArrayCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, CharacterCodec.instance.getFastMatchToken());
}
Reported by PMD.
Line: 19
public void test_match() throws Exception {
Assert.assertEquals(JSONToken.LBRACKET, AtomicCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, NumberDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, SqlDateDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LBRACKET, ObjectArrayCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, CharacterCodec.instance.getFastMatchToken());
}
}
Reported by PMD.
Line: 20
Assert.assertEquals(JSONToken.LBRACKET, AtomicCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, NumberDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, SqlDateDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LBRACKET, ObjectArrayCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, CharacterCodec.instance.getFastMatchToken());
}
}
Reported by PMD.
Line: 21
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, NumberDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, SqlDateDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LBRACKET, ObjectArrayCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, CharacterCodec.instance.getFastMatchToken());
}
}
Reported by PMD.
Line: 22
Assert.assertEquals(JSONToken.LITERAL_INT, NumberDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_INT, SqlDateDeserializer.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LBRACKET, ObjectArrayCodec.instance.getFastMatchToken());
Assert.assertEquals(JSONToken.LITERAL_STRING, CharacterCodec.instance.getFastMatchToken());
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/JSONLexerTest_14.java
7 issues
Line: 11
public class JSONLexerTest_14 extends TestCase {
public void test_e() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append("{\"type\":'");
for (int i = 0; i < 100; ++i) {
buf.append('a');
}
Reported by PMD.
Line: 12
public class JSONLexerTest_14 extends TestCase {
public void test_e() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append("{\"type\":'");
for (int i = 0; i < 100; ++i) {
buf.append('a');
}
buf.append("\\t");
Reported by PMD.
Line: 17
for (int i = 0; i < 100; ++i) {
buf.append('a');
}
buf.append("\\t");
buf.append("'}");
VO vo = JSON.parseObject(buf.toString(), VO.class);
String type = vo.getType();
for (int i = 0; i < 100; ++i) {
Assert.assertEquals('a', type.charAt(i));
Reported by PMD.
Line: 17
for (int i = 0; i < 100; ++i) {
buf.append('a');
}
buf.append("\\t");
buf.append("'}");
VO vo = JSON.parseObject(buf.toString(), VO.class);
String type = vo.getType();
for (int i = 0; i < 100; ++i) {
Assert.assertEquals('a', type.charAt(i));
Reported by PMD.
Line: 20
buf.append("\\t");
buf.append("'}");
VO vo = JSON.parseObject(buf.toString(), VO.class);
String type = vo.getType();
for (int i = 0; i < 100; ++i) {
Assert.assertEquals('a', type.charAt(i));
}
Assert.assertEquals('\t', type.charAt(100));
Assert.assertEquals(101, type.length());
Reported by PMD.
Line: 24
for (int i = 0; i < 100; ++i) {
Assert.assertEquals('a', type.charAt(i));
}
Assert.assertEquals('\t', type.charAt(100));
Assert.assertEquals(101, type.length());
}
public static class VO {
Reported by PMD.
Line: 25
Assert.assertEquals('a', type.charAt(i));
}
Assert.assertEquals('\t', type.charAt(100));
Assert.assertEquals(101, type.length());
}
public static class VO {
public VO(){
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/JSONReaderTest_array_array_2.java
7 issues
Line: 14
public class JSONReaderTest_array_array_2 extends TestCase {
String text = "[[],[],[],[],[], [],[],[],[],[]]";
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
Reported by PMD.
Line: 16
String text = "[[],[],[],[],[], [],[],[],[],[]]";
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
int count = 0;
Reported by PMD.
Line: 33
reader.close();
}
public void test_read_1() throws Exception {
JSONReader reader = new JSONReader(new JSONScanner(text));
reader.startArray();
int count = 0;
while (reader.hasNext()) {
Reported by PMD.
Line: 21
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
int count = 0;
while (reader.hasNext()) {
reader.startArray();
reader.endArray();
count++;
}
Reported by PMD.
Line: 25
while (reader.hasNext()) {
reader.startArray();
reader.endArray();
count++;
}
Assert.assertEquals(10, count);
reader.endArray();
reader.close();
Reported by PMD.
Line: 37
JSONReader reader = new JSONReader(new JSONScanner(text));
reader.startArray();
int count = 0;
while (reader.hasNext()) {
reader.startArray();
reader.endArray();
count++;
}
Reported by PMD.
Line: 41
while (reader.hasNext()) {
reader.startArray();
reader.endArray();
count++;
}
Assert.assertEquals(10, count);
reader.endArray();
reader.close();
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/JSONReaderTest_array_object_2.java
7 issues
Line: 14
public class JSONReaderTest_array_object_2 extends TestCase {
String text = "[{},{},{},{},{} ,{},{},{},{},{}]";
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
Reported by PMD.
Line: 16
String text = "[{},{},{},{},{} ,{},{},{},{},{}]";
public void test_read() throws Exception {
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
int count = 0;
Reported by PMD.
Line: 33
reader.close();
}
public void test_read_1() throws Exception {
JSONReader reader = new JSONReader(new JSONScanner(text));
reader.startArray();
int count = 0;
while (reader.hasNext()) {
Reported by PMD.
Line: 21
JSONReader reader = new JSONReader(new StringReader(text));
reader.startArray();
int count = 0;
while (reader.hasNext()) {
reader.startObject();
reader.endObject();
count++;
}
Reported by PMD.
Line: 25
while (reader.hasNext()) {
reader.startObject();
reader.endObject();
count++;
}
Assert.assertEquals(10, count);
reader.endArray();
reader.close();
Reported by PMD.
Line: 37
JSONReader reader = new JSONReader(new JSONScanner(text));
reader.startArray();
int count = 0;
while (reader.hasNext()) {
reader.startObject();
reader.endObject();
count++;
}
Reported by PMD.
Line: 41
while (reader.hasNext()) {
reader.startObject();
reader.endObject();
count++;
}
Assert.assertEquals(10, count);
reader.endArray();
reader.close();
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/array/BeanToArrayTest2.java
7 issues
Line: 13
public class BeanToArrayTest2 extends TestCase {
public void test_bool() throws Exception {
Model model = JSON.parseObject("[true,false]", Model.class, Feature.SupportArrayToBean);
Assert.assertEquals(true, model.v1);
Assert.assertEquals(false, model.v2);
}
Reported by PMD.
Line: 19
Assert.assertEquals(false, model.v2);
}
public void test_bool_space() throws Exception {
Model model = JSON.parseObject("[true ,false ]", Model.class, Feature.SupportArrayToBean);
Assert.assertEquals(true, model.v1);
Assert.assertEquals(false, model.v2);
}
Reported by PMD.
Line: 25
Assert.assertEquals(false, model.v2);
}
public void test_bool_num() throws Exception {
Model model = JSON.parseObject("[1,0]", Model.class, Feature.SupportArrayToBean);
Assert.assertEquals(true, model.v1);
Assert.assertEquals(false, model.v2);
}
Reported by PMD.
Line: 31
Assert.assertEquals(false, model.v2);
}
public void test_bool_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("[t,0]", Model.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 43
public static class Model {
public boolean v1;
public boolean v2;
}
}
Reported by PMD.
Line: 44
public static class Model {
public boolean v1;
public boolean v2;
}
}
Reported by PMD.
Line: 32
}
public void test_bool_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("[t,0]", Model.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/parser/array/BeanToArrayTest_enum.java
7 issues
Line: 13
public class BeanToArrayTest_enum extends TestCase {
public void test_enum() throws Exception {
Model model = JSON.parseObject("[\"A\",\"B\"]", Model.class, Feature.SupportArrayToBean);
Assert.assertEquals(Type.A, model.v1);
Assert.assertEquals(Type.B, model.v2);
}
Reported by PMD.
Line: 19
Assert.assertEquals(Type.B, model.v2);
}
public void test_enum_space() throws Exception {
Model model = JSON.parseObject("[\"A\" ,\"B\" ]", Model.class, Feature.SupportArrayToBean);
Assert.assertEquals(Type.A, model.v1);
Assert.assertEquals(Type.B, model.v2);
}
Reported by PMD.
Line: 25
Assert.assertEquals(Type.B, model.v2);
}
public void test_enum_num() throws Exception {
Model model = JSON.parseObject("[1,0]", Model.class, Feature.SupportArrayToBean);
Assert.assertEquals(Type.B, model.v1);
Assert.assertEquals(Type.A, model.v2);
}
Reported by PMD.
Line: 31
Assert.assertEquals(Type.A, model.v2);
}
public void test_enum_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("[t,0]", Model.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
Reported by PMD.
Line: 43
public static class Model {
public Type v1;
public Type v2;
}
public static enum Type {
A, B, C
Reported by PMD.
Line: 44
public static class Model {
public Type v1;
public Type v2;
}
public static enum Type {
A, B, C
}
Reported by PMD.
Line: 32
}
public void test_enum_error() throws Exception {
Exception error = null;
try {
JSON.parseObject("[t,0]", Model.class, Feature.SupportArrayToBean);
} catch (JSONException ex) {
error = ex;
}
Reported by PMD.