fastjson 复用构造函数中的map可能导致UnsupportedOperationException

xzabzqsa  于 2022-11-13  发布在  其他
关注(0)|答案(4)|浏览(178)

如图:

因为构造函数中的map是只读的,无法put。

建议构建函数中new一个HashMap,并将map中的内容复制进去。

版本:1.2.75

dw1jzc5e

dw1jzc5e1#

我用的kotlin。 mapof会创建一个只读的Map,类似jdk里的Collections.unmodifiablemap。 haojie ***@***.***> 于2021年8月6日周五 下午11:43写道:…

请问一下,你这mapof是什么函数呀? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#3861 (comment)>, or unsubscribe < https://github.com/notifications/unsubscribe-auth/ADGEYHTZGCIAYTGD33IT3NDT3P7JBANCNFSM5BONPHCQ > .

tag5nh1u

tag5nh1u2#

我用的kotlin。 mapof会创建一个只读的Map,类似jdk里的Collections.unmodifiablemap。 haojie ***@***.***> 于2021年8月6日周五 下午11:43写道:

请问一下,你这mapof是什么函数呀? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#3861 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGEYHTZGCIAYTGD33IT3NDT3P7JBANCNFSM5BONPHCQ .

嗯嗯,查到了!以前没有用过Kotlin。

ha5z0ras

ha5z0ras3#

研究了一下,你用mapOf新建出来的map就是不支持修改的呀。用JSONObject构造函数传进去赋值给它的成员变量map可以正常赋值,但是你不能修改它。如果你需要修改为啥不用mutableMapOf呢?

mspsb9vt

mspsb9vt4#

我觉得框架不应该信任传入的map吧,直接用传入的map进行修改难免出问题。

相关问题