Return null from GsonHelper array getters for a non-array property#4056
Open
vasiliy-mikhailov wants to merge 1 commit into
Open
Return null from GsonHelper array getters for a non-array property#4056vasiliy-mikhailov wants to merge 1 commit into
vasiliy-mikhailov wants to merge 1 commit into
Conversation
…ray property These methods call gson JsonObject.getAsJsonArray(memberName), which casts the member to JsonArray and throws ClassCastException when the property exists but is not an array (e.g. a string or number). Pass the raw element to the null-safe getAsJsonArray(JsonElement) helper and make that helper treat a non-array element like null, so the methods return null for a non-array property just as they already do for a missing one. Adds regression tests.
Owner
|
@codex auggie review |
🤖 Augment PR SummarySummary: Makes GsonHelper’s array getters return Changes:
🤖 Was this summary useful? React with 👍 or 👎 |
Review 结论未发现需要阻塞合并的问题。该 PR 将 新增的回归用例覆盖了三个数组 getter 遇到非数组属性时返回 重点检查项
Testing
|
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.
GsonHelper.getIntArray,getStringArrayandgetLongArraycall gson'sJsonObject.getAsJsonArray(memberName), which casts the member toJsonArray. If the property exists but is not a JSON array (e.g. a string or number), this throws an uncheckedClassCastExceptioninstead of returning gracefully.This passes the raw element via
o.get(string)to the existing null-safegetAsJsonArray(JsonElement)helper, and makes that helper treat a non-array element the same as null — so the three methods returnnullfor a non-array property, matching how they already handle a missing/null property. The other caller of the helper (WxOpenAuthorizationInfoGsonAdapter) is unaffected for valid arrays and becomes null-safe for malformed input.Adds regression tests for the three methods that fail before the change (CCE) and pass after.