zoukankan      html  css  js  c++  java
  • 使用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或是异常,那么就可以返回一个空的集合对象。
     

  • 相关阅读:
    centos6.5+mono+nginx跑asp.net
    YYHS-手机信号
    NOIP2017提高组初赛
    BZOJ-4915-简单的数字题
    BZOJ-5055-膜法师(离散化+树状数组)
    YYHS-Super Big Stupid Cross(二分+扫描线+平衡树)
    BZOJ-1008-[HNOI2008]越狱(快速幂)
    BZOJ-1192-[HNOI2006]鬼谷子的钱袋
    POJ-2417-Discrete Logging(BSGS)
    BZOJ-1010-[HNOI2008]玩具装箱toy(斜率优化)
  • 原文地址:https://www.cnblogs.com/cuizhf/p/2221071.html
Copyright © 2011-2022 走看看