You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Marcus Herou <ma...@tailsweep.com> on 2008/06/08 09:52:12 UTC

Null ret val

Hi guys.

How do I handle null ret vals ? I just get
com.facebook.thrift.TApplicationException: get failed: unknown result when
returning null which I need to do sometimes.

Kindly

//Marcus

-- 
Marcus Herou CTO and co-founder Tailsweep AB
+46702561312
marcus.herou@tailsweep.com
http://www.tailsweep.com/
http://blogg.tailsweep.com/

Re: Null ret val

Posted by Marcus Herou <ma...@tailsweep.com>.
OK... Then my app just ignores the TException and returns null itself then
:) Or on the server side I return a zero length byte[]

/M


On Sun, Jun 8, 2008 at 2:27 PM, Mark Slee <mc...@facebook.com> wrote:

> Re: Null ret valThe issue with this (and reason it has not been done) is
> that it is not compatible with other programming languages. It's fine in an
> all-Java world, but would break if you have a C++ client calling your Java
> service. Since a thrift definition like this:
> StructType myMethod()
>
> Turns into a C++ definition of:
> void myMethod(StructType& ret)
>
> (or direct return for primitive types)
>
> Since there is no way to assign null to an object in C++, we decided
> against implementing nulls for Thrift objects.
>
> Two Thrift-compatible ways of doing this are:
> 1/ Make a wrapper object, or add a field to struct to signify null/non-null
> status (kind of ugly)
> 2/ Define an exception and throw it to signify the null result (also works
> in C++)
>
> Cheers,
> Mark
>
>  ----- Original Message -----
>  From: Johan Stuyts
>  To: thrift-user@incubator.apache.org
>  Sent: Sunday, June 08, 2008 4:20 AM
>  Subject: Re: Null ret val
>
>
>   > How do I handle null ret vals ? I just get
>  > com.facebook.thrift.TApplicationException: get failed: unknown result
>  > when
>  > returning null which I need to do sometimes.
>
>  This is not supported at the moment. The generated (Java) code checks if a
>  result value has been returned. In case of 'null' it obviously has not
>  been. Although this is required for Java primitive types because 'null'
>  cannot be returned in this case, for strings, containers and structs
>  'null' could be returned.
>
>  The changes required to return 'null' instead of throwing an exception are
>  trivial. I can create an issue and add a patch for the Java compiler to it
>  if nobody objects.
>
>  --
>  Kind regards,
>
>  Johan Stuyts
>
>


-- 
Marcus Herou CTO and co-founder Tailsweep AB
+46702561312
marcus.herou@tailsweep.com
http://www.tailsweep.com/
http://blogg.tailsweep.com/

Re: Null ret val

Posted by Mark Slee <mc...@facebook.com>.
Re: Null ret valThe issue with this (and reason it has not been done) is that it is not compatible with other programming languages. It's fine in an all-Java world, but would break if you have a C++ client calling your Java service. Since a thrift definition like this:
StructType myMethod()

Turns into a C++ definition of:
void myMethod(StructType& ret)

(or direct return for primitive types)

Since there is no way to assign null to an object in C++, we decided against implementing nulls for Thrift objects.

Two Thrift-compatible ways of doing this are:
1/ Make a wrapper object, or add a field to struct to signify null/non-null status (kind of ugly)
2/ Define an exception and throw it to signify the null result (also works in C++)

Cheers,
Mark

  ----- Original Message ----- 
  From: Johan Stuyts 
  To: thrift-user@incubator.apache.org 
  Sent: Sunday, June 08, 2008 4:20 AM
  Subject: Re: Null ret val


  > How do I handle null ret vals ? I just get
  > com.facebook.thrift.TApplicationException: get failed: unknown result 
  > when
  > returning null which I need to do sometimes.

  This is not supported at the moment. The generated (Java) code checks if a 
  result value has been returned. In case of 'null' it obviously has not 
  been. Although this is required for Java primitive types because 'null' 
  cannot be returned in this case, for strings, containers and structs 
  'null' could be returned.

  The changes required to return 'null' instead of throwing an exception are 
  trivial. I can create an issue and add a patch for the Java compiler to it 
  if nobody objects.

  --
  Kind regards,

  Johan Stuyts


Re: Null ret val

Posted by Mark Slee <mc...@facebook.com>.
Re: Null ret valThe issue with this (and reason it has not been done) is that it is not compatible with other programming languages. It's fine in an all-Java world, but would break if you have a C++ client calling your Java service. Since a thrift definition like this:
StructType myMethod()

Turns into a C++ definition of:
void myMethod(StructType& ret)

(or direct return for primitive types)

Since there is no way to assign null to an object in C++, we decided against implementing nulls for Thrift objects.

Two Thrift-compatible ways of doing this are:
1/ Make a wrapper object, or add a field to struct to signify null/non-null status (kind of ugly)
2/ Define an exception and throw it to signify the null result (also works in C++)

Cheers,
Mark

  ----- Original Message ----- 
  From: Johan Stuyts 
  To: thrift-user@incubator.apache.org 
  Sent: Sunday, June 08, 2008 4:20 AM
  Subject: Re: Null ret val


  > How do I handle null ret vals ? I just get
  > com.facebook.thrift.TApplicationException: get failed: unknown result 
  > when
  > returning null which I need to do sometimes.

  This is not supported at the moment. The generated (Java) code checks if a 
  result value has been returned. In case of 'null' it obviously has not 
  been. Although this is required for Java primitive types because 'null' 
  cannot be returned in this case, for strings, containers and structs 
  'null' could be returned.

  The changes required to return 'null' instead of throwing an exception are 
  trivial. I can create an issue and add a patch for the Java compiler to it 
  if nobody objects.

  --
  Kind regards,

  Johan Stuyts


Re: Null ret val

Posted by Johan Stuyts <j....@zybber.nl>.
> How do I handle null ret vals ? I just get
> com.facebook.thrift.TApplicationException: get failed: unknown result  
> when
> returning null which I need to do sometimes.

This is not supported at the moment. The generated (Java) code checks if a  
result value has been returned. In case of 'null' it obviously has not  
been. Although this is required for Java primitive types because 'null'  
cannot be returned in this case, for strings, containers and structs  
'null' could be returned.

The changes required to return 'null' instead of throwing an exception are  
trivial. I can create an issue and add a patch for the Java compiler to it  
if nobody objects.

-- 
Kind regards,

Johan Stuyts