alibaba / alibaba/fastjson2

[BUG] JDK25字符串转对象包含非静态内部类时空指针, JDK21正常

Open
#7,654 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
JDK25字符串转对象包含非静态内部类时空指针, JDK21正常

### 环境信息
*请填写以下信息:*

- JDK信息: [e.g.:openjdk version "25.0.3" 2026-04-21 LTS]
- 版本信息:[e.g.:Fastjson2 2.0.62]

### 重现步骤
*如何操作可以重现该问题:*

1. 执行 `main` 方法
2. 出现 `java.lang.NullPointerException` 错误, Summary内部类改成静态内部类或JDK25切回JDK21运行正常

```java
import com.alibaba.fastjson2.JSON;

public class AmzListingJsonFeedResult {

public static void main(String[] args) {
String json = "{\"issues\":[],\"summary\":{\"errors\":0,\"warnings\":0,\"messagesProcessed\":7,\"messagesAccepted\":7,\"messagesInvalid\":0}}";
AmzListingJsonFeedResult result = JSON.parseObject(json, AmzListingJsonFeedResult.class);
System.out.println(result.getSummary().getMessagesAccepted());
}

private Summary summary;

public Summary getSummary() {
return summary;
}

public void setSummary(Summary summary) {
this.summary = summary;
}

public class Summary {
private Integer errors;
private Integer warnings;
private Integer messagesProcessed;
private Integer messagesAccepted;
private Integer messagesInvalid;

public Integer getErrors() {
return errors;
}

public void setErrors(Integer errors) {
this.errors = errors;
}

public Integer getWarnings() {
return warnings;
}

public void setWarnings(Integer warnings) {
this.warnings = warnings;
}

public Integer getMessagesProcessed() {
return messagesProcessed;
}

public void setMessagesProcessed(Integer messagesProcessed) {
this.messagesProcessed = messagesProcessed;
}

public Integer getMessagesAccepted() {
return messagesAccepted;
}

public void setMessagesAccepted(Integer messagesAccepted) {
this.messagesAccepted = messagesAccepted;
}

public Integer getMessagesInvalid() {
return messagesInvalid;
}

public void setMessagesInvalid(Integer messagesInvalid) {
this.messagesInvalid = messagesInvalid;
}
}
}
```

### 期待的正确结果
*无报错*

### 相关日志输出
Exception in thread "main" java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:220)
at AmzListingJsonFeedResult$Summary.(AmzListingJsonFeedResult.java:21)
at com.alibaba.fastjson2.reader.ORG_2_5_Summary.readObject(Unknown Source)
at com.alibaba.fastjson2.reader.ORG_1_1_AmzListingJsonFeedResult.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:992)
at AmzListingJsonFeedResult.main(AmzListingJsonFeedResult.java:7)

Contributor guide

Open the contributing guide

Research direction

Run the supplied main method under JDK25 and JDK21 to confirm the difference. Start with the generated reader path shown in the stack trace, com.alibaba.fastjson2.reader.ORG_2_5_Summary.readObject, and inspect how the non-static Summary class is instantiated during JSON.parseObject. Done means the JDK25 run completes without a NullPointerException and prints the accepted-message count.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.