GeezerVison is showing github.com — 修复 Gson 在 Java 9+ 环境下反射访问 java.io.File#path 字段失败的问题 by Copilot · Pull Request #3773 · binarywang/WxJava
Conversation
Copilot
AI
commented
Nov 28, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Gson 在 Java 9+ 模块化系统下无法反射访问 java.io.File#path 私有字段,导致包含 File 或 ApacheHttpClientBuilder 字段的配置类序列化失败。
Failed making field 'java.io.File#path' accessible;
either increase its visibility or write a custom TypeAdapter for its declaring type.
修改内容
参照 WxMpGsonBuilder 已有的修复方案,为其他模块的 GsonBuilder 添加 ExclusionStrategy:
WxMaGsonBuilder (miniapp)
WxCpGsonBuilder (cp)
WxOpenGsonBuilder (open)
WxQidianGsonBuilder (qidian)
WxGsonBuilder (common)
INSTANCE.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
return false;
}
@Override
public boolean shouldSkipClass(Class<?> aClass) {
return aClass == File.class || aClass == ApacheHttpClientBuilder.class;
}
});
Original prompt
This section details on the original issue you should resolve
<issue_title>Gson问题</issue_title>
<issue_description>Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [cn.binarywang.wx.miniapp.api.WxMaService]: Factory method 'wxMaService' threw exception with message: Failed making field 'java.io.File#path' accessible; either increase its visibility or write a custom TypeAdapter for its declaring type.
See https://github.com/google/gson/blob/main/Troubleshooting.md#reflection-inaccessible</issue_description>
Comments on the Issue (you are @copilot in this section)
Custom agent used: 自定义的
需要用中文
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Copilot
AI
changed the title
[WIP] Fix Gson accessibility issue in WxMaService instantiation
修复 Gson 在 Java 9+ 环境下反射访问 java.io.File#path 字段失败的问题
Nov 28, 2025
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
binarywang
Awaiting requested review from binarywang
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully merging this pull request may close these issues.
Gson问题
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.