thrift tutorial --version 0.8 by java上InvalidOperation异常未被client抛出

走thrift tutorial得例子:

发现一个问题,在client发送 (1 DIVIDE 0):{
     work.op = Operation.DIVIDE;
     work.num1 = 1;
     work.num2 = 0;
     } 这种请求得时候,server本来应该返回InvalidOperation异常,client捕获。但是Server确实返回了,但是client并没有得到异常,而是success。

跟踪代码,发现server确实write 了异常到struct中,但是client read得时候,也read成功,不过在Calculator.java得2523行得“struct.setSuccessIsSet(true);”这行代码执行后,read返回得结果会根据isSuccessIsSet来返回结果,所以因此虽然server返回了异常InvalidOperation,但是因为isSuccessIsSet=true,所以client得“int quotient = client.calculate(1, work);” 不会抛出异常,直接返回success得默认值0.

见代码:
     public void read(org.apache.thrift.protocol.TProtocol iprot, calculate_result struct) throws org.apache.thrift.TException {
        System.out.println("calculate_resultStandardScheme read start!!!!!!!!");
        org.apache.thrift.protocol.TField schemeField;
        iprot.readStructBegin();
        while (true)
        {
          schemeField = iprot.readFieldBegin();
          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
            break;
          }
          switch (schemeField.id) {
            case 0: // SUCCESS
              System.out.println("calculate_resultStandardScheme read SUCCESS!!!!!!!!");
              if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                struct.success = iprot.readI32();
                // struct.setSuccessIsSet(true);   // 这里默认是没有注释得。我注释了,异常就正常抛出了。
              } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            case 1: // OUCH
              System.out.println("calculate_resultStandardScheme read OUCH!!!!!!!!");
              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
                struct.ouch = new InvalidOperation();
                struct.ouch.read(iprot);
                struct.setOuchIsSet(true);
                System.out.println("calculate_resultStandardScheme read OUCH111111");
              } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
              }
              break;
            default:
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
          }
          iprot.readFieldEnd();
        }
        iprot.readStructEnd();
        
          System.out.println("calculate_resultStandardScheme struct:" + struct);
        // check for required fields of primitive type, which can't be checked in the validate method
        struct.validate();
      }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值