Skip to content
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.

JSONObject.parseObject 解析字符串时,遇到 [null] 时堆内存溢出 #4516

Open

Description

@liushuangSRD

属性类:
`
public class Field {

private String id;

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

}
`

转换测试类

`
public class Test {

class HeapSpace{

    private List<Field> reportOwner;

    public List<Field> getReportOwner() {
        return reportOwner;
    }

    public void setReportOwner(List<Field> reportOwner) {
        this.reportOwner = reportOwner;
    }

}

public static void main(String[] args) {
    String parseString = "{\"reportOwner\":[null]}";
    HeapSpace heapSpace = JSONObject.parseObject(parseString, HeapSpace.class);
    String aa = "";
}

}
`

执行后内存一直飙升,直到堆内存溢出,生产环境报错
Handler dispatch failed; nested exception is java.lang.OutOfMemoryError: Java heap space

Activity

  1. changed the title [-]JSONObject.parseObject 在解析字符串,在遇到 [null] 时堆内存溢出[/-] [+]JSONObject.parseObject 解析字符串时,遇到 [null] 时堆内存溢出[/+] on Jul 10, 2024
  2. kimmking commented on Jul 27, 2024

    @kimmking
    Contributor

    HeapSpace作为一个内部类,如果没有static,无法访问。
    加上static后,解析正常。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions