使用Collections.emptyMap()引起的一个奇怪的问题

以下是控制台信息:

Line 820 net.jxta.impl.resolver.ResolverServiceImpl.processQuery()
Uncaught Throwable from handler for : urn:jxta:cbid-DC007D31BB964091A351ABE04C5FE39C05java.lang.UnsupportedOperationException
Line 203 java.util.AbstractMap.put()
Line 89 jxmessenger.jxse.api.queryservice.QueryMessage.addOptionalAdvParam()
Line 70 jxmessenger.ui.chat.ChatQueryListener.queryRequested()
Line 181 jxmessenger.jxse.queryservice.QueryServiceImpl.processQuery()
Line 809 net.jxta.impl.resolver.ResolverServiceImpl.processQuery()
Line 119 net.jxta.impl.resolver.ResolverServiceImpl.access$600()
Line 1173 net.jxta.impl.resolver.ResolverServiceImpl$DemuxQuery.processIncomingMessage()
Line 1024 net.jxta.impl.endpoint.EndpointServiceImpl.processIncomingMessage()
Line 199 net.jxta.impl.endpoint.LoopbackMessenger$1.run()
Line 17 net.jxta.impl.util.threads.RunnableAsCallableWrapper.call()
Line 50 net.jxta.impl.util.threads.RunMetricsWrapper.call()
Line 34 net.jxta.impl.util.threads.QueueTimeRunMetricsWrapper.call()
Line 93 net.jxta.impl.util.threads.RunMetricsWrapper.run()
Line 9 net.jxta.impl.util.threads.QueueTimeRunMetricsWrapper.run()
Line 1110 java.util.concurrent.ThreadPoolExecutor.runWorker()
Line 603 java.util.concurrent.ThreadPoolExecutor$Worker.run()
Line 722 java.lang.Thread.run()
Line 115 net.jxta.impl.pipe.InputPipeImpl.<init>()
Creating InputPipe for urn:jxta:cbid-750F8348B41141428333E7CED90D4ABF2A91D71ED6E04519972BA61A9CFE5B5F04 of type JxtaUnicast with listener
QueryServiceImpl processQuery: Thread[JxtaWorker-2,5,IDE Main]
queryRequested ===<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QueryMessage>
<QueryMessage>
    <PeerId>
        urn:jxta:cbid-59616261646162614A787461503250337F8876DF012F52B6216118C00CC7253D03
    </PeerId>
    <Name>
        cuizhf
    </Name>
    <ListenerClassName>
        jxmessenger.ui.chat.ChatQueryListener
    </ListenerClassName>
    <OptionalStrParams/>
    <OptionalAdvParams/>
</QueryMessage>
 ————————————————————————————————————————————————————————————————————

第二行是很不起眼的一条异常信息,不知为何没有把整个错误堆栈输出。

一开始没有注意到这条异常信息,于是设断点,调试,结果每次执行几句就莫名其妙地转入ThreadPoolExecutor中执行。

 最后注意到上面的异常信息后,发现对一个类型为Map的成员变量初始化有问题:

protected Map<String, String> optionalStrParams = Collections.emptyMap();

 如此修改:

protected Map<String, String> optionalStrParams = new HashMap<String, String>();
————————————

我的本意是初始化为一个空的Map,EmptyMap在此场景下不合适。

————————————

EmptyMap的背景:
在某些情况下,我们经常需要发挥一个空的集合对象,比如说在数据查询时,并不需要发挥一个NULL或是异常,那么就可以返回一个空的集合对象。
 

转载于:https://www.cnblogs.com/cuizhf/archive/2011/10/22/2221071.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值