Add null check for textJsonElement in WxCpUserGsonAdapter#3632
Merged
binarywang merged 3 commits intobinarywang:developfrom Jul 4, 2025
Merged
Add null check for textJsonElement in WxCpUserGsonAdapter#3632binarywang merged 3 commits intobinarywang:developfrom
binarywang merged 3 commits intobinarywang:developfrom
Conversation
…CpUserGsonAdapter.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds a null check around the text JSON element in buildExtraAttrs to prevent a potential NPE when attrJsonElement has no "text" field.
- Introduced
textJsonElementlocal variable and guard clauses. - Wrapped
attr.setTextValue(...)in anifthat verifies the element is non-null and an object. - Removed the previous direct call to
getAsJsonObject().get("text").
Comments suppressed due to low confidence (1)
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java:130
- Add a unit test for the case where
attrJsonElementhas no"text"field to verify thatbuildExtraAttrshandles missingtextcorrectly.
JsonElement textJsonElement = attrJsonElement.getAsJsonObject().get("text");
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java
Show resolved
Hide resolved
…CpUserGsonAdapter.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
For some Enterprise Wechat endpoints,
attrJsonElement.getAsJsonObject().get("text");return null if there is no fieldtextinattrJsonElement. We need to check null value beforegetAsJsonObject.