1

I am trying to write an RPC with Thrift, the client seems to be communicating to the server just fine, and the server creates a list to return to the client (proper format). But then the client somehow cannot recognize the packet as I get this error:

org.apache.thrift.TApplicationException: getEntityByIP failed: unknown result

This is what my thrift file looks like:

struct EntityLookupMessage{
1: list<i32> entityIDs;
}
service EntityJoinService {
   list<i32> getEntityByIP(1:string IPval,2:i32 date);  
}

And the ServerImpl is the following method:

public List<Integer> getEntityByIP(String IPval, int date) throws TException {
    try{
        System.out.println("Checking..."+IPval);
        List<Integer> response=EntityJoinStandalone.getEntityByIP(entityLookup,IPval, date);
        System.out.println(response);
        return response;
    }finally{
        // TODO Auto-generated method stub
    return null
    }

Which is called by a client like so:

List<Integer> entity = client.getEntityByIP(IPval, date); 

Any ideas why this is the case?

1 Answer 1

3

Cause

Thrift by design doesn't allow for null results. This is the code of the generated recv_Xxx() function:

public List<Integer> recv_getEntityByIP() throws org.apache.thrift.TException
{
  getEntityByIP_result result = new getEntityByIP_result();
  receiveBase(result, "getEntityByIP");
  if (result.isSetSuccess()) {
    return result.success;
  }
  throw new org.apache.thrift.TApplicationException(  
        org.apache.thrift.TApplicationException.MISSING_RESULT, 
        "getEntityByIP failed: unknown result");
}

You have to return a valid result, which is ...

  • a valid list, which may be empty, but must not be null
  • an exception thrown on the server

Solution

Remove the return null from your finally clause.

Best practice

Put the result into an object, similar to what you already did with the args:

struct EntityByIP_result {
  1: list<i32> data;
}

This way you also leave room for further improvements down the road, you can add new fields to the struct at any time.

Sign up to request clarification or add additional context in comments.

3 Comments

But the list isn't null. I print it before returning, and it is not null. It's [1002].
No wonder. What do you think happens in your finally branch? It doesn't matter what you print() before you return. What really matters is what you return, finally (pun intended).
Ahhh, ok, too rusty with my exception catching in Java.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.