package com.xiaomi.infra.galaxy.emq.client;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Copyright 2015, Xiaomi.
 * All rights reserved.
 * Author: shenyuannan@xiaomi.com
 */

public class EMQClient {
  private static class EMQClientHandler<T> implements InvocationHandler {
    private final Object instance;

    public EMQClientHandler(Class<T> interfaceClass, Object instance) {
      this.instance = instance;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
      EMQRequestCheckUtils.checkRequest(args);
      try {
        return method.invoke(instance, args);
      } catch (InvocationTargetException e) {
        throw e.getCause();
      }
    }
  }

  /**
   * Create client wrapper which validate parameters of client.
   */
  @SuppressWarnings("unchecked")
  public static <T> T getClient(Class<T> interfaceClass, Object instance) {
    return (T) Proxy.newProxyInstance(EMQClient.class.getClassLoader(),
        new Class[]{interfaceClass},
        new EMQClientHandler(interfaceClass, instance));
  }
}

@@ -198,16 +198,41 @@
 t.Proxy;
+%0Aimport java.util.Arrays;
 %0A%0A/**%0A *
@@ -675,16 +675,90 @@
 wable %7B%0A
+      if (!Arrays.asList(Object.class.getMethods()).contains(method)) %7B%0A  
       EM
@@ -792,24 +792,32 @@
 uest(args);%0A
+      %7D%0A
       try %7B%0A

Fix SDK check methods NPE.