You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Koji Hisano (Updated) (JIRA)" <ji...@apache.org> on 2011/12/21 09:45:30 UTC

[jira] [Updated] (THRIFT-1474) Not throw user defined exception when a defined method returns boolean result

     [ https://issues.apache.org/jira/browse/THRIFT-1474?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Koji Hisano updated THRIFT-1474:
--------------------------------

    Description: 
A boolean result method always returns result value and exception value when a user defined exception is thrown.
So, client handles the result as having a result value and ignore the exception.

{code:title=Sample thrift definition|borderStyle=solid}
bool createAccount(1:string userName, 2:string password, 3:string mailAddress) throws (1: Exception.ServiceException serviceException);
{code}

{code:title=Current generated code in createAccount_resultStandardScheme class|borderStyle=solid}
public void write(org.apache.thrift.protocol.TProtocol oprot, createAccount_result struct) throws org.apache.thrift.TException {
	struct.validate();

	oprot.writeStructBegin(STRUCT_DESC);
	oprot.writeFieldBegin(SUCCESS_FIELD_DESC); // <- Problem because the value existence is not checked
	oprot.writeBool(struct.success);
	oprot.writeFieldEnd();
	if (struct.serviceException != null) { // <- I think it is better to use #isSetServiceException
		oprot.writeFieldBegin(SERVICE_EXCEPTION_FIELD_DESC);
		struct.serviceException.write(oprot);
		oprot.writeFieldEnd();
	}
	oprot.writeFieldStop();
	oprot.writeStructEnd();
}
{code}

{code:title=Correct generated code (Maybe)|borderStyle=solid}
public void write(org.apache.thrift.protocol.TProtocol oprot, createAccount_result struct) throws org.apache.thrift.TException {
	struct.validate();

	oprot.writeStructBegin(STRUCT_DESC);
	if (struct.isSetSuccess()) {
		oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
		oprot.writeBool(struct.success);
		oprot.writeFieldEnd();
	}
	if (struct.isSetServiceException()) {
		oprot.writeFieldBegin(SERVICE_EXCEPTION_FIELD_DESC);
		struct.serviceException.write(oprot);
		oprot.writeFieldEnd();
	}
	oprot.writeFieldStop();
	oprot.writeStructEnd();
}
{code}


  was:
A boolean result method always returns result value and exception value when a user defined exception is thrown.
So, client handles the result as having a result value and ignore the exception.

Sample thrift definition:
      bool createAccount(1:string userName, 2:string password, 3:string mailAddress) throws (1: Exception.ServiceException serviceException);

Current generated code in createAccount_resultStandardScheme class:
      public void write(org.apache.thrift.protocol.TProtocol oprot, createAccount_result struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        oprot.writeFieldBegin(SUCCESS_FIELD_DESC); // <- Problem because the value existence is not checked
        oprot.writeBool(struct.success);
        oprot.writeFieldEnd();
        if (struct.serviceException != null) { // <- I think it is better to use #isSetServiceException
          oprot.writeFieldBegin(SERVICE_EXCEPTION_FIELD_DESC);
          struct.serviceException.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }

Correct generated code (Maybe):
      public void write(org.apache.thrift.protocol.TProtocol oprot, createAccount_result struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        if (struct.isSetSuccess()) {
            oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
            oprot.writeBool(struct.success);
            oprot.writeFieldEnd();
        }
        if (struct.isSetServiceException()) {
          oprot.writeFieldBegin(SERVICE_EXCEPTION_FIELD_DESC);
          struct.serviceException.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }


    
> Not throw user defined exception when a defined method returns boolean result
> -----------------------------------------------------------------------------
>
>                 Key: THRIFT-1474
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1474
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler
>    Affects Versions: 0.8
>            Reporter: Koji Hisano
>
> A boolean result method always returns result value and exception value when a user defined exception is thrown.
> So, client handles the result as having a result value and ignore the exception.
> {code:title=Sample thrift definition|borderStyle=solid}
> bool createAccount(1:string userName, 2:string password, 3:string mailAddress) throws (1: Exception.ServiceException serviceException);
> {code}
> {code:title=Current generated code in createAccount_resultStandardScheme class|borderStyle=solid}
> public void write(org.apache.thrift.protocol.TProtocol oprot, createAccount_result struct) throws org.apache.thrift.TException {
> 	struct.validate();
> 	oprot.writeStructBegin(STRUCT_DESC);
> 	oprot.writeFieldBegin(SUCCESS_FIELD_DESC); // <- Problem because the value existence is not checked
> 	oprot.writeBool(struct.success);
> 	oprot.writeFieldEnd();
> 	if (struct.serviceException != null) { // <- I think it is better to use #isSetServiceException
> 		oprot.writeFieldBegin(SERVICE_EXCEPTION_FIELD_DESC);
> 		struct.serviceException.write(oprot);
> 		oprot.writeFieldEnd();
> 	}
> 	oprot.writeFieldStop();
> 	oprot.writeStructEnd();
> }
> {code}
> {code:title=Correct generated code (Maybe)|borderStyle=solid}
> public void write(org.apache.thrift.protocol.TProtocol oprot, createAccount_result struct) throws org.apache.thrift.TException {
> 	struct.validate();
> 	oprot.writeStructBegin(STRUCT_DESC);
> 	if (struct.isSetSuccess()) {
> 		oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
> 		oprot.writeBool(struct.success);
> 		oprot.writeFieldEnd();
> 	}
> 	if (struct.isSetServiceException()) {
> 		oprot.writeFieldBegin(SERVICE_EXCEPTION_FIELD_DESC);
> 		struct.serviceException.write(oprot);
> 		oprot.writeFieldEnd();
> 	}
> 	oprot.writeFieldStop();
> 	oprot.writeStructEnd();
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira