The following issues were found
src/test/java/com/alibaba/json/bvt/parser/array/BeanToArrayTest_enum_private.java
7 issues
Line: 13
public class BeanToArrayTest_enum_private 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
private static class Model {
public Type v1;
public Type v2;
}
private static enum Type {
A, B, C
Reported by PMD.
Line: 44
private static class Model {
public Type v1;
public Type v2;
}
private 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.
src/test/java/com/alibaba/json/bvt/parser/bug/Bug_for_dingzhu.java
7 issues
Line: 12
import java.util.Map;
public class Bug_for_dingzhu extends TestCase {
public void test_0() throws Exception {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("notExitAfterVid", false);
params.put("VIData", "{\"config\":{\"noTokens\":\"Y\",\"stopReport\":\"Y\"}");
StupidObject so = new StupidObject();
so.setParams(params);
Reported by PMD.
Line: 12
import java.util.Map;
public class Bug_for_dingzhu extends TestCase {
public void test_0() throws Exception {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("notExitAfterVid", false);
params.put("VIData", "{\"config\":{\"noTokens\":\"Y\",\"stopReport\":\"Y\"}");
StupidObject so = new StupidObject();
so.setParams(params);
Reported by PMD.
Line: 19
StupidObject so = new StupidObject();
so.setParams(params);
SerializeFilter[] filters = new SerializeFilter[] { new DumbValueFilter()};
String jsonString = JSON.toJSONString(so, new SerializeConfig(), filters,
SerializerFeature.NotWriteDefaultValue, SerializerFeature.IgnoreErrorGetter,
SerializerFeature.QuoteFieldNames);
}
private class DumbValueFilter implements ContextValueFilter {
Reported by PMD.
Line: 30
return object;
}
Field field = context.getField();
return value;
}
}
private class StupidObject {
Reported by PMD.
Line: 4
package com.alibaba.json.bvt.parser.bug;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.*;
import junit.framework.TestCase;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
Reported by PMD.
Line: 19
StupidObject so = new StupidObject();
so.setParams(params);
SerializeFilter[] filters = new SerializeFilter[] { new DumbValueFilter()};
String jsonString = JSON.toJSONString(so, new SerializeConfig(), filters,
SerializerFeature.NotWriteDefaultValue, SerializerFeature.IgnoreErrorGetter,
SerializerFeature.QuoteFieldNames);
}
private class DumbValueFilter implements ContextValueFilter {
Reported by PMD.
Line: 30
return object;
}
Field field = context.getField();
return value;
}
}
private class StupidObject {
Reported by PMD.
src/test/java/com/alibaba/json/test/codec/JsonSmartCodec.java
7 issues
Line: 44
}
@Override
public byte[] encodeToBytes(Object object) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
Reported by PMD.
Line: 14
return "json-smart";
}
public <T> T decodeObject(String text, Class<T> clazz) throws Exception {
throw new UnsupportedOperationException();
}
public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception {
throw new UnsupportedOperationException();
Reported by PMD.
Line: 18
throw new UnsupportedOperationException();
}
public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception {
throw new UnsupportedOperationException();
}
public Object decodeObject(String text) throws Exception {
Object value = JSONValue.parse(text);
Reported by PMD.
Line: 22
throw new UnsupportedOperationException();
}
public Object decodeObject(String text) throws Exception {
Object value = JSONValue.parse(text);
return value;
}
Reported by PMD.
Line: 28
return value;
}
public Object decode(String text) throws Exception {
Object value = JSONValue.parse(text);
return value;
}
Reported by PMD.
Line: 34
return value;
}
public String encode(Object object) throws Exception {
return JSONValue.toJSONString(object);
}
public <T> T decodeObject(byte[] input, Class<T> clazz) throws Exception {
Reported by PMD.
Line: 39
}
public <T> T decodeObject(byte[] input, Class<T> clazz) throws Exception {
throw new UnsupportedOperationException();
}
@Override
public byte[] encodeToBytes(Object object) throws Exception {
Reported by PMD.
src/test/java/com/alibaba/json/test/benchmark/RyuDoubleBenchmark.java
7 issues
Line: 11
double v = 0.5390050566444644; //new java.util.Random().nextDouble();
System.out.println(v);
for (int i = 0; i < 10; ++i) {
f0(v); // 2505, 1865
}
Reported by PMD.
Line: 30
Double.toString(v);
}
long millis = System.currentTimeMillis() - start;
System.out.println("jdk : " + millis);
}
public static void f1(double v) throws Exception {
long start = System.currentTimeMillis();
for (int i = 0; i < COUNT; ++i) {
Reported by PMD.
Line: 39
RyuDouble.toString(v);
}
long millis = System.currentTimeMillis() - start;
System.out.println("ryu : " + millis);
}
}
Reported by PMD.
Line: 5
import com.alibaba.fastjson.util.RyuDouble;
public class RyuDoubleBenchmark {
private final static int COUNT = 1000 * 1000 * 10;
public static void main(String[] args) throws Exception {
double v = 0.5390050566444644; //new java.util.Random().nextDouble();
Reported by PMD.
Line: 7
public class RyuDoubleBenchmark {
private final static int COUNT = 1000 * 1000 * 10;
public static void main(String[] args) throws Exception {
double v = 0.5390050566444644; //new java.util.Random().nextDouble();
System.out.println(v);
Reported by PMD.
Line: 24
// }
}
public static void f0(double v) throws Exception {
long start = System.currentTimeMillis();
for (int i = 0; i < COUNT; ++i) {
Double.toString(v);
}
long millis = System.currentTimeMillis() - start;
Reported by PMD.
Line: 33
System.out.println("jdk : " + millis);
}
public static void f1(double v) throws Exception {
long start = System.currentTimeMillis();
for (int i = 0; i < COUNT; ++i) {
RyuDouble.toString(v);
}
long millis = System.currentTimeMillis() - start;
Reported by PMD.
src/test/java/com/alibaba/json/test/benchmark/decode/EishayDecode2Bytes.java
7 issues
Line: 44
chars = (text + " ").toCharArray();
bytes = text.getBytes("UTF-8");
} catch (Exception e) {
throw new RuntimeException();
}
}
@Override
public void execute(Codec codec) throws Exception {
Reported by PMD.
Line: 12
import data.media.MediaContent;
public class EishayDecode2Bytes extends BenchmarkCase {
public final static EishayDecode2Bytes instance = new EishayDecode2Bytes();
private final byte[] bytes;
private final char[] chars;
Reported by PMD.
Line: 21
private final String text;
public byte[] getBytes() {
return bytes;
}
public char[] getChars() {
return chars;
}
Reported by PMD.
Line: 25
}
public char[] getChars() {
return chars;
}
public String getText() {
return text;
}
Reported by PMD.
Line: 37
try {
String resource = "data/media.2.json";
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
text = IOUtils.toString(is);
is.close();
chars = (text + " ").toCharArray();
bytes = text.getBytes("UTF-8");
Reported by PMD.
Line: 43
chars = (text + " ").toCharArray();
bytes = text.getBytes("UTF-8");
} catch (Exception e) {
throw new RuntimeException();
}
}
@Override
Reported by PMD.
Line: 44
chars = (text + " ").toCharArray();
bytes = text.getBytes("UTF-8");
} catch (Exception e) {
throw new RuntimeException();
}
}
@Override
public void execute(Codec codec) throws Exception {
Reported by PMD.
src/test/java/com/alibaba/json/demo/hibernate/data/OrderDetailId.java
7 issues
Line: 9
@SuppressWarnings("serial")
@Embeddable
public class OrderDetailId implements java.io.Serializable {
private Integer orderNumber;
private String productCode;
Reported by PMD.
Line: 49
if ( !(other instanceof OrderDetailId) ) return false;
OrderDetailId castOther = ( OrderDetailId ) other;
return ( (this.getOrderNumber()==castOther.getOrderNumber()) || ( this.getOrderNumber()!=null && castOther.getOrderNumber()!=null && this.getOrderNumber().equals(castOther.getOrderNumber()) ) )
&& ( (this.getProductCode()==castOther.getProductCode()) || ( this.getProductCode()!=null && castOther.getProductCode()!=null && this.getProductCode().equals(castOther.getProductCode()) ) );
}
@Override
public int hashCode() {
Reported by PMD.
Line: 49
if ( !(other instanceof OrderDetailId) ) return false;
OrderDetailId castOther = ( OrderDetailId ) other;
return ( (this.getOrderNumber()==castOther.getOrderNumber()) || ( this.getOrderNumber()!=null && castOther.getOrderNumber()!=null && this.getOrderNumber().equals(castOther.getOrderNumber()) ) )
&& ( (this.getProductCode()==castOther.getProductCode()) || ( this.getProductCode()!=null && castOther.getProductCode()!=null && this.getProductCode().equals(castOther.getProductCode()) ) );
}
@Override
public int hashCode() {
Reported by PMD.
Line: 49
if ( !(other instanceof OrderDetailId) ) return false;
OrderDetailId castOther = ( OrderDetailId ) other;
return ( (this.getOrderNumber()==castOther.getOrderNumber()) || ( this.getOrderNumber()!=null && castOther.getOrderNumber()!=null && this.getOrderNumber().equals(castOther.getOrderNumber()) ) )
&& ( (this.getProductCode()==castOther.getProductCode()) || ( this.getProductCode()!=null && castOther.getProductCode()!=null && this.getProductCode().equals(castOther.getProductCode()) ) );
}
@Override
public int hashCode() {
Reported by PMD.
Line: 50
OrderDetailId castOther = ( OrderDetailId ) other;
return ( (this.getOrderNumber()==castOther.getOrderNumber()) || ( this.getOrderNumber()!=null && castOther.getOrderNumber()!=null && this.getOrderNumber().equals(castOther.getOrderNumber()) ) )
&& ( (this.getProductCode()==castOther.getProductCode()) || ( this.getProductCode()!=null && castOther.getProductCode()!=null && this.getProductCode().equals(castOther.getProductCode()) ) );
}
@Override
public int hashCode() {
int result = 17;
Reported by PMD.
Line: 50
OrderDetailId castOther = ( OrderDetailId ) other;
return ( (this.getOrderNumber()==castOther.getOrderNumber()) || ( this.getOrderNumber()!=null && castOther.getOrderNumber()!=null && this.getOrderNumber().equals(castOther.getOrderNumber()) ) )
&& ( (this.getProductCode()==castOther.getProductCode()) || ( this.getProductCode()!=null && castOther.getProductCode()!=null && this.getProductCode().equals(castOther.getProductCode()) ) );
}
@Override
public int hashCode() {
int result = 17;
Reported by PMD.
Line: 50
OrderDetailId castOther = ( OrderDetailId ) other;
return ( (this.getOrderNumber()==castOther.getOrderNumber()) || ( this.getOrderNumber()!=null && castOther.getOrderNumber()!=null && this.getOrderNumber().equals(castOther.getOrderNumber()) ) )
&& ( (this.getProductCode()==castOther.getProductCode()) || ( this.getProductCode()!=null && castOther.getProductCode()!=null && this.getProductCode().equals(castOther.getProductCode()) ) );
}
@Override
public int hashCode() {
int result = 17;
Reported by PMD.
src/test/java/com/alibaba/json/test/benchmark/basic/IntBenchmark.java
7 issues
Line: 22
"}";
public static void main(String[] args) throws Exception {
System.out.println(System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
// Model model = new Model();
// model.v1 = new Random().nextInt();
// model.v2 = new Random().nextInt();
// model.v3 = new Random().nextInt();
// model.v4 = new Random().nextInt();
Reported by PMD.
Line: 46
JSON.parseObject(json, Model.class);
}
long millis = System.currentTimeMillis() - start;
System.out.println("millis : " + millis);
}
public static void perf2() {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000 * 1000 * 10; ++i) {
Reported by PMD.
Line: 55
JSON.parseObject(json2, Model.class);
}
long millis = System.currentTimeMillis() - start;
System.out.println("millis : " + millis);
}
public static void perf3() {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000 * 1000 * 10; ++i) {
Reported by PMD.
Line: 64
JSON.parseObject(json3, Model.class);
}
long millis = System.currentTimeMillis() - start;
System.out.println("millis : " + millis);
}
public static class Model {
public int v1;
public int v2;
Reported by PMD.
Line: 10
/**
* Created by wenshao on 04/08/2017.
*/
public class IntBenchmark {
static String json = "{\"v1\":-1224609302,\"v2\":379420556,\"v3\":-1098099527,\"v4\":-2018662,\"v5\":422842162}";
static String json2 = "{\"v1\":\"-1224609302\",\"v2\":\"379420556\",\"v3\":\"-1098099527\",\"v4\":\"-2018662\",\"v5\":\"422842162\"}";
static String json3 = "{\n" +
"\t\"v1\":\"-1224609302\",\n" +
"\t\"v2\":\"379420556\",\n" +
Reported by PMD.
Line: 21
"\t\"v5\":\"422842162\"\n" +
"}";
public static void main(String[] args) throws Exception {
System.out.println(System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
// Model model = new Model();
// model.v1 = new Random().nextInt();
// model.v2 = new Random().nextInt();
// model.v3 = new Random().nextInt();
Reported by PMD.
Line: 5
import com.alibaba.fastjson.JSON;
import java.util.Random;
/**
* Created by wenshao on 04/08/2017.
*/
public class IntBenchmark {
Reported by PMD.
src/test/java/com/alibaba/json/demo/hibernate/data/PaymentId.java
7 issues
Line: 9
@SuppressWarnings("serial")
@Embeddable
public class PaymentId implements java.io.Serializable
{
private Integer customerNumber;
private String checkNumber;
public PaymentId() { }
Reported by PMD.
Line: 47
if ( !(other instanceof PaymentId) ) return false;
PaymentId castOther = ( PaymentId ) other;
return ( (this.getCustomerNumber()==castOther.getCustomerNumber()) || ( this.getCustomerNumber()!=null && castOther.getCustomerNumber()!=null && this.getCustomerNumber().equals(castOther.getCustomerNumber()) ) )
&& ( (this.getCheckNumber()==castOther.getCheckNumber()) || ( this.getCheckNumber()!=null && castOther.getCheckNumber()!=null && this.getCheckNumber().equals(castOther.getCheckNumber()) ) );
}
@Override
public int hashCode() {
Reported by PMD.
Line: 47
if ( !(other instanceof PaymentId) ) return false;
PaymentId castOther = ( PaymentId ) other;
return ( (this.getCustomerNumber()==castOther.getCustomerNumber()) || ( this.getCustomerNumber()!=null && castOther.getCustomerNumber()!=null && this.getCustomerNumber().equals(castOther.getCustomerNumber()) ) )
&& ( (this.getCheckNumber()==castOther.getCheckNumber()) || ( this.getCheckNumber()!=null && castOther.getCheckNumber()!=null && this.getCheckNumber().equals(castOther.getCheckNumber()) ) );
}
@Override
public int hashCode() {
Reported by PMD.
Line: 47
if ( !(other instanceof PaymentId) ) return false;
PaymentId castOther = ( PaymentId ) other;
return ( (this.getCustomerNumber()==castOther.getCustomerNumber()) || ( this.getCustomerNumber()!=null && castOther.getCustomerNumber()!=null && this.getCustomerNumber().equals(castOther.getCustomerNumber()) ) )
&& ( (this.getCheckNumber()==castOther.getCheckNumber()) || ( this.getCheckNumber()!=null && castOther.getCheckNumber()!=null && this.getCheckNumber().equals(castOther.getCheckNumber()) ) );
}
@Override
public int hashCode() {
Reported by PMD.
Line: 48
PaymentId castOther = ( PaymentId ) other;
return ( (this.getCustomerNumber()==castOther.getCustomerNumber()) || ( this.getCustomerNumber()!=null && castOther.getCustomerNumber()!=null && this.getCustomerNumber().equals(castOther.getCustomerNumber()) ) )
&& ( (this.getCheckNumber()==castOther.getCheckNumber()) || ( this.getCheckNumber()!=null && castOther.getCheckNumber()!=null && this.getCheckNumber().equals(castOther.getCheckNumber()) ) );
}
@Override
public int hashCode() {
int result = 17;
Reported by PMD.
Line: 48
PaymentId castOther = ( PaymentId ) other;
return ( (this.getCustomerNumber()==castOther.getCustomerNumber()) || ( this.getCustomerNumber()!=null && castOther.getCustomerNumber()!=null && this.getCustomerNumber().equals(castOther.getCustomerNumber()) ) )
&& ( (this.getCheckNumber()==castOther.getCheckNumber()) || ( this.getCheckNumber()!=null && castOther.getCheckNumber()!=null && this.getCheckNumber().equals(castOther.getCheckNumber()) ) );
}
@Override
public int hashCode() {
int result = 17;
Reported by PMD.
Line: 48
PaymentId castOther = ( PaymentId ) other;
return ( (this.getCustomerNumber()==castOther.getCustomerNumber()) || ( this.getCustomerNumber()!=null && castOther.getCustomerNumber()!=null && this.getCustomerNumber().equals(castOther.getCustomerNumber()) ) )
&& ( (this.getCheckNumber()==castOther.getCheckNumber()) || ( this.getCheckNumber()!=null && castOther.getCheckNumber()!=null && this.getCheckNumber().equals(castOther.getCheckNumber()) ) );
}
@Override
public int hashCode() {
int result = 17;
Reported by PMD.
src/test/java/com/alibaba/json/test/benchmark/basic/DoubleBenchmark.java
7 issues
Line: 47
JSON.parseObject(json, Model.class);
}
long millis = System.currentTimeMillis() - start;
System.out.println("millis : " + millis);
}
public static void perf2() {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000 * 1000 * 10; ++i) {
Reported by PMD.
Line: 56
JSON.parseObject(json2, Model.class);
}
long millis = System.currentTimeMillis() - start;
System.out.println("millis : " + millis);
}
public static void perf3() {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000 * 1000 * 10; ++i) {
Reported by PMD.
Line: 65
JSON.parseObject(json3, Model.class);
}
long millis = System.currentTimeMillis() - start;
System.out.println("millis : " + millis);
}
public static class Model {
public double v1;
public double v2;
Reported by PMD.
Line: 11
/**
* Created by wenshao on 04/08/2017.
*/
public class DoubleBenchmark {
static String json = "{\"v1\":0.4430165316544028,\"v2\":0.22676692048907365,\"v3\":0.9766986818812096,\"v4\":0.3423751102308744,\"v5\":0.4262177938610565}";
static String json2 = "{\"v1\":\"0.4430165316544028\",\"v2\":\"0.22676692048907365\",\"v3\":\"0.9766986818812096\",\"v4\":\"0.3423751102308744\",\"v5\":\"0.4262177938610565\"}";
static String json3 = "{\n" +
"\t\"v1\":0.4430165316544028,\n" +
"\t\"v2\":0.22676692048907365,\n" +
Reported by PMD.
Line: 22
"\t\"v5\":0.4262177938610565\n" +
"}";
public static void main(String[] args) throws Exception {
// Model model = new Model();
// model.v1 = new Random().nextDouble();
// model.v2 = new Random().nextDouble();
// model.v3 = new Random().nextDouble();
// model.v4 = new Random().nextDouble();
Reported by PMD.
Line: 4
package com.alibaba.json.test.benchmark.basic;
import com.alibaba.fastjson.JSON;
import com.alibaba.json.bvtVO.IncomingDataPoint;
import java.util.Random;
/**
* Created by wenshao on 04/08/2017.
Reported by PMD.
Line: 6
import com.alibaba.fastjson.JSON;
import com.alibaba.json.bvtVO.IncomingDataPoint;
import java.util.Random;
/**
* Created by wenshao on 04/08/2017.
*/
public class DoubleBenchmark {
Reported by PMD.
src/test/java/com/alibaba/json/bvt/writeClassName/WriteClassNameTest_Set.java
7 issues
Line: 26
set.add(new B1());
a.setList(set);
String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
System.out.println(text);
Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set$A\",\"list\":Set[{},{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set$B1\"}]}",
text);
A a1 = (A) JSON.parse(text);
Reported by PMD.
Line: 15
import com.alibaba.fastjson.serializer.SerializerFeature;
public class WriteClassNameTest_Set extends TestCase {
protected void setUp() throws Exception {
ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set");
}
public void test_list() throws Exception {
A a = new A();
Reported by PMD.
Line: 16
public class WriteClassNameTest_Set extends TestCase {
protected void setUp() throws Exception {
ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set");
}
public void test_list() throws Exception {
A a = new A();
Set<B> set = new LinkedHashSet<B>();
Reported by PMD.
Line: 19
ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set");
}
public void test_list() throws Exception {
A a = new A();
Set<B> set = new LinkedHashSet<B>();
set.add(new B());
set.add(new B1());
a.setList(set);
Reported by PMD.
Line: 32
A a1 = (A) JSON.parse(text);
Assert.assertEquals(2, a1.getList().size());
}
public static class A {
private Set<B> list;
Reported by PMD.
Line: 32
A a1 = (A) JSON.parse(text);
Assert.assertEquals(2, a1.getList().size());
}
public static class A {
private Set<B> list;
Reported by PMD.
Line: 3
package com.alibaba.json.bvt.writeClassName;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Set;
import com.alibaba.fastjson.parser.ParserConfig;
import org.junit.Assert;
import junit.framework.TestCase;
Reported by PMD.