Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Fix issue2736(JSONObject.keySet()中可能包含非String键)#2748

Merged
wenshao merged 2 commits intoalibaba:masterfrom
Omega-Ariston:fix-issue2736
Sep 19, 2019
Merged

Fix issue2736(JSONObject.keySet()中可能包含非String键)#2748
wenshao merged 2 commits intoalibaba:masterfrom
Omega-Ariston:fix-issue2736

Conversation

@Omega-Ariston
Copy link
Copy Markdown
Collaborator

@Omega-Ariston Omega-Ariston commented Sep 17, 2019

fix #2736

JSONObject.innerMap的泛型参数为<String, Object>,而DefaultJSONParser.parseObject()方法中的map没有指定泛型参数,往里put键值对也没有做类型检查,可能会put进非String类型的key。
当前的parseObject()逻辑中如果开启了NonStringKeyAsString这个特性,则会将key转为String类型。可以直接在这个判断条件后面新增一个对JSONObject的判断。

The parameterType of JSONObject.innerMap is <String, Object>, while in the method DefaultJSONParser.parseObject(), non-String key might be put into this map, resulting in unexpected outcome.
Currently, the type of key will be converted to String only when the feature NonStringKeyAsString is enabled. Therefore, an additional statement which determines whether current object is a JSONObject can be added after that to suit the case here.

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #2748 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2748      +/-   ##
============================================
- Coverage     80.12%   80.11%   -0.02%     
- Complexity     7068     7071       +3     
============================================
  Files           145      145              
  Lines         26708    26709       +1     
  Branches       6374     6374              
============================================
- Hits          21400    21398       -2     
- Misses         3473     3478       +5     
+ Partials       1835     1833       -2
Impacted Files Coverage Δ Complexity Δ
...com/alibaba/fastjson/parser/DefaultJSONParser.java 88.21% <100%> (+0.01%) 314 <0> (+1) ⬆️
...com/alibaba/fastjson/serializer/SerialContext.java 72.91% <0%> (-4.17%) 19% <0%> (ø)
...ava/com/alibaba/fastjson/serializer/DateCodec.java 87.58% <0%> (-1.97%) 37% <0%> (-1%)
...main/java/com/alibaba/fastjson/util/TypeUtils.java 79.83% <0%> (-0.12%) 625% <0%> (ø)
...ava/com/alibaba/fastjson/parser/JSONLexerBase.java 71.31% <0%> (-0.04%) 825% <0%> (-1%)
.../java/com/alibaba/fastjson/parser/JSONScanner.java 76.4% <0%> (+0.16%) 501% <0%> (+2%) ⬆️
...java/com/alibaba/fastjson/parser/ParserConfig.java 83.47% <0%> (+0.16%) 203% <0%> (+1%) ⬆️
...n/java/com/alibaba/fastjson/util/JavaBeanInfo.java 88.06% <0%> (+0.18%) 198% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 71943b3...7fb5998. Read the comment docs.

@wenshao wenshao merged commit 30824c9 into alibaba:master Sep 19, 2019
@Omega-Ariston Omega-Ariston deleted the fix-issue2736 branch September 20, 2019 08:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

3 participants