GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — setSerializerFeatures中添加SerializerFeature.BrowserCompatible属性,对象字段数过多时报空指针异常 · Issue #3075 · alibaba/fastjson

This repository was archived by the owner on Jul 29, 2026. It is now read-only.
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

setSerializerFeatures中添加SerializerFeature.BrowserCompatible属性,对象字段数过多时报空指针异常 #3075

Copy link
Copy link
Open
Open
setSerializerFeatures中添加SerializerFeature.BrowserCompatible属性,对象字段数过多时报空指针异常#3075
Copy link
Assignees
wenshao
Labels
bug
Milestone
1.2.77

Description

@Finchleyy
Finchleyy
opened on Mar 21, 2020
Issue body actions

setSerializerFeatures中添加SerializerFeature.BrowserCompatible属性,对象字段数过多时报空指针异常

对象中包含 List Integer Long Float等类型
截屏2020-03-21下午11 52 16

java.lang.NullPointerException: null
at com.alibaba.fastjson.serializer.ASMSerializer_17_XXXXXXBO.writeNormal(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.ASMSerializer_17_XXXXXXBO.write(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:333) ~[fastjson-1.2.58.jar:na]
at com.alibaba.fastjson.serializer.ASMSerializer_13_DefaultResult.writeNormal(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.ASMSerializer_13_DefaultResult.write(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:285) ~[fastjson-1.2.58.jar:na]
at com.alibaba.fastjson.JSON.writeJSONString(JSON.java:937) ~[fastjson-1.2.58.jar:na]
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:226) ~[spring-web-4.3.18.RELEASE.jar:4.3.18.RELEASE]
at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.write(FastJsonHttpMessageConverter.java:244) ~[fastjson-1.2.58.jar:na]

Activity

  1. wenshao
    added this to the 1.2.68 milestone on Mar 21, 2020
  2. wenshao commented on Mar 22, 2020

    @wenshao
    wenshao
    on Mar 22, 2020
    Member
    More actions

    问题没重现,需要帮忙提供一下testcase

  3. wenshao
    self-assigned this
    on Mar 22, 2020
  4. wenshao
    added
    bug
    on Mar 22, 2020
  5. Finchleyy commented on Mar 23, 2020

    @Finchleyy
    Finchleyy
    on Mar 23, 2020
    Author
    More actions

    问题没重现,需要帮忙提供一下testcase
    具体问题可以在我的这个项目中复现https://github.com/ypw384556909/fastjson-test-case.git
    详细描述请看 README.md

  6. wenshao
    modified the milestones: 1.2.68, 1.2.69 on Mar 30, 2020
  7. wenshao
    modified the milestones: 1.2.69, 1.2.72 on Jun 14, 2020
  8. wenshao
    modified the milestones: 1.2.72, 1.2.73 on Jun 27, 2020
  9. chenghaoharvey commented on Jul 26, 2020

    @chenghaoharvey
    chenghaoharvey
    on Jul 26, 2020
    More actions

    下载了你的testcase,在macbook上面没有重现,你用的os是@ypw384556909

  10. wenshao
    added a commit that references this issue on Jul 26, 2020

    add testcase for #3075

    e697d4a
  11. wenshao
    modified the milestones: 1.2.73, 1.2.74 on Jul 26, 2020
  12. wenshao commented on Jul 26, 2020

    @wenshao
    wenshao
    on Jul 26, 2020
    Member
    More actions

    问题未重现

  13. wenshao
    modified the milestones: 1.2.74, 1.2.75 on Oct 8, 2020
  14. wenshao
    modified the milestones: 1.2.75, 1.2.76 on Nov 5, 2020
  15. RussXia commented on Dec 23, 2020

    @RussXia
    RussXia
    on Dec 23, 2020
    More actions

    我在本地测试时,直接在IDEA中运行了提供的Spring Boot demo,没有复现到NullPointException,但是JVM出现了 fatal error,异常退出了。我注意到提供的demo中也有类似的JVM异常的日志文件,所以想check下是否是同一个原因,或者这个属于另外的问题。

    查阅文档后发现,在IDEA直接运行,默认会选中"Enable launch optimization",该选项会在VM参数中添加"-noverify"。

    https://www.jetbrains.com/help/idea/run-debug-configuration-spring-boot.html#configuration-tab

    正常情况下,验证字节码流程
    以温少提供的demo testcase for #3075 为例,debug后发现,在用ASM生成一个ObjectSerializer字节码后,JVM加载验证字节码 ,会抛出
    Invalid method Code length 70093 in class file com/alibaba/fastjson/serializer/ASMSerializer_2_TestBasicBO的 ClassFormatError异常,fastjson捕获异常后会重新生成一个JavaBeanSerializer完成后续的序列化。

    异常情况,不验证字节码流程
    因为带有"-noverify"参数,会跳过字节码的验证阶段。所以会拿到的是有问题的字节码,在执行writer.write(this, object, null, null, 0);时,会因此而出现A fatal error has been detected by the Java Runtime Environment,JVM异常退出。

    总结
    其实这个问题和 SerializerFeature.BrowserCompatible 只是巧合。因为只有在字段数量小于256才会可能使用动态生成的ASMSerializer。当字段属性很多但是不足256,且开启了SerializerFeature.BrowserCompatible后,生成的writeNormal方法,超过了JVM规定的method Code的限制。

    疑问
    存在某些场景下,JVM应用就是关闭了verify的,这种情况下,fastjson需要处理这种极端情况吗?

    Reacted by Norman, Shaojin Wen and cornfieldchase
  16. wenshao
    modified the milestones: 1.2.76, 1.2.77 on Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @wenshao
    wenshao

Labels

bug

Type

No type

Projects

No projects

    Milestone

    • 1.2.77No due date

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402792 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.