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成员替换成空字符串""
         
  • 相关阅读:
    SpringBoot 项目瘦身
    对比两个文本的异同
    Spring 事务不起作用的场景
    Controller 层数据校验实现思路
    Notify 类的实现思路
    backup: 使用 vim 时一定会用到的设置 --for-myself
    exercise: 反射获取指定的属性值 --CSharp
    exercise: 序列化和反序列化Xml --CSharp
    前缀
    华罗庚的数学思想
  • 原文地址:https://www.cnblogs.com/aquester/p/9891533.html
Copyright © 2011-2022 走看看