Fix NPE in EntPayRequest#storeMap when brandId is null#3909
Merged
binarywang merged 2 commits intodevelopfrom Mar 7, 2026
Merged
Fix NPE in EntPayRequest#storeMap when brandId is null#3909binarywang merged 2 commits intodevelopfrom
binarywang merged 2 commits intodevelopfrom
Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix NullPointerException in storeMap for brandId
Fix NPE in EntPayRequest#storeMap when brandId is null
Mar 7, 2026
There was a problem hiding this comment.
Pull request overview
该 PR 修复了微信支付“企业付款到零钱”请求对象 EntPayRequest 在序列化/签名参数组装过程中因 brandId(可选字段)为空而触发的空指针异常问题,提升了 SDK 在可选参数未设置时的健壮性(对应 issue #3908 的场景:Jackson 序列化触发 getSignParams())。
Changes:
- 在
EntPayRequest#storeMap中为brandId增加空值判断,为空时不再写入brand_id,避免brandId.toString()NPE - 新增单测覆盖
brandId = null(不包含brand_id且不抛异常)与brandId非空(包含正确键值)两种情况
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequest.java | storeMap 中对可选字段 brandId 做 null guard,避免 NPE 并在为空时省略 brand_id |
| weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequestTest.java | 补充 getSignParams() 在 brandId 为空/非空场景下的回归测试 |
🤖 Augment PR SummarySummary: 修复企业付款请求对象在序列化/取签名参数时因 Changes:
Technical Notes: 🤖 Was this summary useful? React with 👍 or 👎 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
EntPayRequest.storeMap()unconditionally calledbrandId.toString(), butbrand_idis an optional field — causing NPE whenever the request was serialized (e.g. via Jackson) withoutbrandIdset.Changes
EntPayRequest.java: Guardbrand_idmap insertion with a null check; the key is omitted entirely whenbrandIdisnullEntPayRequestTest.java: Add tests coveringbrandId = null(key absent, no NPE) andbrandIdset (correct value present)Original prompt
💡 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.