class JavaMethodInvoker {

    public Object invokeMethod(Object instance, Method method, boolean makeAccessible, Object... args) {
        try {
            if (makeAccessible) {
                method.setAccessible(true);
            }

            if (instance instanceof Proxy) {
                InvocationHandler handler = Proxy.getInvocationHandler(instance);
                return handler.invoke(instance, method, args);
            } else {
                return method.invoke(instance, args);
            }
        } catch (Throwable exception) {
            logger.error("", exception);
            throw new JavaFunctionInvocationException(exception, instance, method);
        }
    }

}