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: [email protected] 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
