Don’t subclass the HBase Put

The other day I was developing a simple class hierarchy on top of the HBase Client API. I tried to create a “typed” Put operation that allowed to use proper Java types instead of raw byte[] and nasty Bytes.toBytes() conversion all around the client code.

public class TypedPut extends org.apache.hadoop.hbase.client.Put {
   //...
}

However, HBase spat a nasty stack trace:

java.util.concurrent.ExecutionException: java.io.IOException: IPC server unable to read call parameters: Error in readFields
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222) ~[na:1.6.0_31]
    at java.util.concurrent.FutureTask.get(FutureTask.java:83) ~[na:1.6.0_31]

The actual cause of the problem is deeply described on Darutk Oboegaki blog and is connected with the HBase server not being able to find the subclassed Puts in its classpath.

The solution is simple: prefer delegation over subclassing.