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();
????? }