zoukankan      html  css  js  c++  java
  • java thrift返回List异常

    对于下段代码:
    public List<String> hmget(String key, List<String> fields) throws org.apache.thrift.TException
    {
        JedisCluster jedis_cluster = RedisClusterProxy.get_jedis_cluster();	
        String[] field_array = new String[fields.size()];
        fields.toArray(field_array);
        return jedis_cluster.hmget(key, field_array);
    }  



    运行时遇到如下异常,原因是由于hmget返回的List<String>含有null成员,导致thrift编码时异常:
    20160415 14:55:39 ERROR org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer.invoke(AbstractNonblockingServer.java:484) [Thread-0] Unexpected throwable while invoking!
    java.lang.NullPointerException
            at org.apache.thrift.protocol.TBinaryProtocol.writeString(TBinaryProtocol.java:185)
            at com.test.redis_cluster_proxy.RedisClusterProxyService$hmget_result$hmget_resultStandardScheme.write(RedisClusterProxyService.java:19434)
            at com.test.redis_cluster_proxy.RedisClusterProxyService$hmget_result$hmget_resultStandardScheme.write(RedisClusterProxyService.java:1)
            at com.test.redis_cluster_proxy.RedisClusterProxyService$hmget_result.write(RedisClusterProxyService.java:19337)
            at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:53)
            at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
            at org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer.invoke(AbstractNonblockingServer.java:478)
            at org.apache.thrift.server.TNonblockingServer.requestInvoke(TNonblockingServer.java:115)
            at org.apache.thrift.server.AbstractNonblockingServer$AbstractSelectThread.handleRead(AbstractNonblockingServer.java:209)
            at org.apache.thrift.server.TNonblockingServer$SelectAcceptThread.select(TNonblockingServer.java:198)
            at org.apache.thrift.server.TNonblockingServer$SelectAcceptThread.run(TNonblockingServer.java:154)
            
    当redis中没有相应的field时,hmget返回的List<String>会包含null成员。解决此问题有两个办法:
    1)保证查询的field一定存在
    2)对hmget返回值做处理,null成员替换成空字符串""
         
  • 相关阅读:
    班会记录
    CSS之伪元素
    JavaScript之返回顶部
    尝试Hexo
    GitHub之上传文件
    Git之使用
    Git之基本命令
    运行第一个Node.js程序
    go语言圣经 map 章节习题
    go语言圣经第4章JSON部分习题
  • 原文地址:https://www.cnblogs.com/aquester/p/9891533.html
Copyright © 2011-2022 走看看