Skip to content

Commit

Permalink
add testcase for issue #661
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Aug 9, 2022
1 parent db4b4bf commit 988697d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions core/src/test/java/com/alibaba/fastjson2/issues/Issue661.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.alibaba.fastjson2.issues;

import com.alibaba.fastjson2.JSON;
import lombok.Data;
import org.junit.jupiter.api.RepeatedTest;

import java.util.Collections;

public class Issue661 {
@Data
static class Response<T> {
T data;

Response(T data) {
this.data = data;
}
}

@Data
static class A {
// 没有属性不会异常
int a;
}

@RepeatedTest(100)
void testB() {
for (int i = 0; i < 1000; i++) {
JSON.toJSONString(new Response<>(new A()));
}
}

@RepeatedTest(100)
void testList() {
for (int i = 0; i < 1000; i++) {
// Collections.singletonList(0)改成0也会异常,异常概率小一些
JSON.toJSONString(new Response<>(Collections.singletonList(0)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.alibaba.fastjson.v2issues;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.junit.jupiter.api.RepeatedTest;

import java.util.Collections;

public class Issue661 {
@Data
static class Response<T> {
T data;

Response(T data) {
this.data = data;
}
}

@Data
static class A {
// 没有属性不会异常
int a;
}

@RepeatedTest(100)
void testB() {
for (int i = 0; i < 1000; i++) {
JSON.toJSONString(new Response<>(new A()));
}
}

@RepeatedTest(100)
void testList() {
for (int i = 0; i < 1000; i++) {
// Collections.singletonList(0)改成0也会异常,异常概率小一些
JSON.toJSONString(new Response<>(Collections.singletonList(0)));
}
}
}

0 comments on commit 988697d

Please sign in to comment.