Repository navigation
fix(bean): 避免泛型键转换复用不兼容的 TreeMap 比较器 - #387
Merged
Merged
Conversation
按实际键域创建目标 Map,键转换或缺少有效样本时保留遍历顺序。 兼容的可空键保留原比较器,Object 键保持既有浅复制语义。 补充 record Map 键转换、可空键和无样本边界回归。
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.
使用 String 专用比较器的 TreeMap 转为 Map<Integer, Item> 时,原实现会保留旧比较器并放入转换后的 Integer 键,导致 ClassCastException。
现在按实际键域创建目标 Map:键类型兼容时保留原比较器(null 键不影响兼容性判断);键发生转换,或声明具体键类型但没有非空样本时,使用 LinkedHashMap 保留源遍历顺序。目标键类型为 Object 时不转换键,继续保留比较器。源 Map 和既有浅复制语义保持不变,README 同步说明边界。
验证:
兼容边界:声明了具体键类型的空 TreeMap 或仅含 null 键的 TreeMap 会返回 LinkedHashMap,避免继承无法确认键域的比较器。