Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]使用JSON.toJSONString时导致StackOverflowError #597

Closed
leblancvn opened this issue Jul 29, 2022 · 2 comments
Closed

[BUG]使用JSON.toJSONString时导致StackOverflowError #597

leblancvn opened this issue Jul 29, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@leblancvn
Copy link

leblancvn commented Jul 29, 2022

问题描述

使用JSON.toJSONString打印对象时导致StackOverflowError

环境信息

  • JDK信息: [e.g.:jdk 1.8]
  • 版本信息:[e.g.:Fastjson2 2.0.10]

重现步骤

打印类:
@slf4j
@DaTa

public class Invoker {
    private Object targer;

    private Method method;

}

测试类:

public class TestService {
    public void test(String str){
        System.out.println("测试方法");
    }
}

打印方法:

    public static void main(String[] args) throws NoSuchMethodException {
        Invoker invoker = new Invoker();
        TestService testService = new TestService();
        invoker.setTarger(testService);
        Class<? extends TestService> aClass = testService.getClass();
        Method method = aClass.getMethod("test",String.class);
        invoker.setMethod(method);
        System.out.println(JSON.toJSONString(invoker));
    }

期待的正确结果

期待不要报错

相关日志输出

Exception in thread "main" java.lang.StackOverflowError
at java.lang.Class.getEnclosingMethodInfo(Class.java:1072)
at java.lang.Class.getEnclosingClass(Class.java:1272)
at sun.reflect.annotation.AnnotatedTypeFactory.addNesting(AnnotatedTypeFactory.java:96)
at sun.reflect.annotation.AnnotatedTypeFactory.buildAnnotatedType(AnnotatedTypeFactory.java:65)
at sun.reflect.annotation.TypeAnnotationParser.buildAnnotatedTypes(TypeAnnotationParser.java:137)
at java.lang.reflect.Executable.getAnnotatedParameterTypes(Executable.java:688)
at java.lang.reflect.Parameter.getAnnotatedType(Parameter.java:237)
at com.alibaba.fastjson2.writer.ObjectWriter_3.write(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriterArray.write(ObjectWriterArray.java:85)
at com.alibaba.fastjson2.writer.ObjectWriter_2.write(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriter_3.write(Unknown Source)

@leblancvn leblancvn added the bug Something isn't working label Jul 29, 2022
@leblancvn leblancvn changed the title [BUG]使用 [BUG]使用JSON.toJSONString时导致StackOverflowError Jul 29, 2022
@wenshao wenshao added this to the 2.0.11 milestone Jul 30, 2022
@wenshao
Copy link
Member

wenshao commented Jul 30, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.11-SNAPSHOT/
问题已修复,请用2.0.11-SNAPSHOT版本帮忙验证,2.0.11版本预计在8月7日发布

@wenshao
Copy link
Member

wenshao commented Aug 7, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.11
问题已修复,请用新版本

@wenshao wenshao closed this as completed Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants