protected Codec getCodec() {
    // For NO CODEC, "hbase.client.rpc.codec" must be configured with empty string AND
    // "hbase.client.default.rpc.codec" also -- because default is to do cell block encoding.
    String className = conf.get(HConstants.RPC_CODEC_CONF_KEY, getDefaultCodec(this.conf));
    if (className == null || className.length() == 0) {
      return null;
    }
    try {
      return Class.forName(className).asSubclass(Codec.class).getDeclaredConstructor()
        .newInstance();
    } catch (Exception e) {
      throw new RuntimeException("Failed getting codec " + className, e);
    }
  }
Encapsulate the ugly casting and RuntimeException conversion in private method.
@return Codec to use on this client.
hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java