Invokes a method using reflection, in an accessible manner (by using {@link Method#setAccessible(boolean)}

@param instance   instance on which to execute the method
@param method     method to execute
@param parameters parameters
967643
public static Object invokeAccessibly(Object instance, Method method, Object[] parameters) {
        try {
            method.setAccessible(true);
            return method.invoke(instance, parameters);
        } catch (Exception e) {
            throw new RuntimeException("Unable to invoke method " + method + " on object of type " + (instance == null ?
                                                                                                      "null" :
                                                                                                      instance.getClass().getSimpleName()) +
                                       (parameters != null ? " with parameters " + Arrays.asList(parameters) : ""), e);
        }
    }
1116391
private static void setMethodAccessible(Method method) {
        try {
            //
            // XXX Default access superclass workaround
            //
            // When a public class has a default access superclass
            // with public methods, these methods are accessible.
            // Calling them from compiled code works fine.
            //
            // Unfortunately, using reflection to invoke these methods
            // seems to (wrongly) to prevent access even when the method
            // modifer is public.
            //
            // The following workaround solves the problem but will only
            // work from sufficiently privilages code.
            //
            // Better workarounds would be greatfully accepted.
            //
            if (!method.isAccessible()) {
                method.setAccessible(true);
            }

        } catch (SecurityException se) {
            // log but continue just in case the method.invoke works anyway
            // Log log = LogFactory.getLog(MethodUtils.class);
            if (!loggedAccessibleWarning) {
                boolean vulnerableJVM = false;
                try {
                    String specVersion = System.getProperty("java.specification.version");
                    if (specVersion.charAt(0) == '1' &&
                            (specVersion.charAt(2) == '0' ||
                             specVersion.charAt(2) == '1' ||
                             specVersion.charAt(2) == '2' ||
                             specVersion.charAt(2) == '3')) {

                        vulnerableJVM = true;
                    }
                } catch (SecurityException e) {
                    // don't know - so display warning
                    vulnerableJVM = true;
                }
                if (vulnerableJVM) {
                    log.warn(
                        "Current Security Manager restricts use of workarounds for reflection bugs "
                        + " in pre-1.4 JVMs.");
                }
                loggedAccessibleWarning = true;
            }
            log.debug("Cannot setAccessible on method. Therefore cannot use jvm access bug workaround.", se);
        }
    }
557323
@Override
    public void invoke(String method, IPendingServiceCallback callback) {
        log.debug("invoke method: {} params {} callback {}", new Object[] { method, callback });
        // get it from the conn manager
        if (conn != null) {
            conn.invoke(method, callback);
        } else {
            log.info("Connection was null");
            PendingCall result = new PendingCall(method);
            result.setStatus(Call.STATUS_NOT_CONNECTED);
            callback.resultReceived(result);
        }
    }
1132629
public static Object invokeMethod(Object object, String methodName, Class<?>[] parameterTypes,
                                      Object[] parameters) throws NoSuchMethodException, InvocationTargetException,
            IllegalAccessException {
        if (Checker.isEmpty(parameters)) {
            return object.getClass().getMethod(methodName).invoke(object);
        } else {
            return object.getClass().getMethod(methodName, parameterTypes).invoke(object, parameters);
        }
    }
844402
protected Object invoke(Method method)
    {
        try
        {
            return method.invoke(target);
        }
        catch (Exception e)
        {
            return null;
        }
    }
903972
private function callMethod($instance, $method)
    {
        if (!method_exists($instance, $method) || !is_callable([$instance, $method])) {
            return false;
        }

        return call_user_func([$instance, $method]);
    }
60763
public <X> X invoke(Object instance, Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        return cast(annotatedMethod.getJavaMember().invoke(instance, parameters));
    }
574221
public Object invokeStaticMethod(Object object, String methodName, Object[] arguments) {
        if (invokeStaticMethodMethod != null) {
            MetaClassHelper.unwrap(arguments);
            return invokeStaticMethodMethod.invoke(object, new Object[]{methodName, arguments});
        }
        return super.invokeStaticMethod(object, methodName, arguments);
    }
600990
public void setMethodParam(String method) {
		if(isModifiable == ModifiableRule.NotModifiable) {
			throw new IllegalArgumentException("method param of the URI is not modifiable and must not be set by the application");
		}
		try {
			getSipURI().setMethodParam(method);
			super.parameters.put(METHOD, method);
		} catch (ParseException e) {
			logger.error("parse exception occured", e);
			throw new IllegalArgumentException("Bad arg " + method, e);
		}
	}
247552
public static void assertNoParameters(final Method method, Class<? extends Annotation> annotation) 
   {
      if (method.getParameterTypes().length != 0)
      {
         throw annotation == null ? MESSAGES.methodHasToHaveNoParameters(method) : MESSAGES.methodHasToHaveNoParameters2(method, annotation);
      }
   }
1327226
private Object invokeMethod(final Object obj, final Method method, final Object... args) {
        // turn method to accessible. otherwise, we won't be able to callback to methods
        // on non-public classes.
        boolean accessibility = method.isAccessible();
        method.setAccessible(true);

        try {
            try {
                return method.invoke(obj, args);
            } catch (Exception e) {
                this.log("Error while invoking %s with %s: %s", method, Arrays.toString(args), Throwables.getStackTraceAsString(e));
                throw e;
            }
        } catch (InvocationTargetException e) {
            throw new JsiiException(e.getTargetException());
        } catch (IllegalAccessException e) {
            throw new JsiiException(e);
        } finally {
            // revert accessibility.
            method.setAccessible(accessibility);
        }
    }
569816
public static <R, T> R invokeMethod(T instance, Method method, Object... arguments) {
        try {
            return (R) method.invoke(instance, arguments);
        } catch (IllegalAccessException e) {
            throw new InvocationException("Illegal access invoking method [" + method + "]: " + e.getMessage(), e);
        } catch (InvocationTargetException e) {
            throw new InvocationException("Exception occurred invoking method [" + method + "]: " + e.getMessage(), e);
        }
    }
174777
public static Object invokeMethod(Object target, String method, Object... args) {
		Class<?>[] types = new Class[args.length];
		for(int index = args.length - 1; index >= 0; index--) {
			types[index] = args[index].getClass();
		}
		try {
			return target.getClass().getMethod(method, types).invoke(target, args);
		} catch(Throwable t) {
			throw new MethodInvocationException(t);
		}
	}
640216
public void invokevirtual(ExecutableElement method) throws IOException
    {
        if (method.getEnclosingElement().getKind() == ElementKind.INTERFACE)
        {
            int index = subClass.resolveInterfaceMethodIndex(method);
            invokeinterface(index, argumentCount(method.getParameters()));
        }
        else
        {
            int index = subClass.resolveMethodIndex(method);
            invokevirtual(index);
        }
    }
121222
@UnstableApi
    public final void setPrivateKeyMethod(OpenSslPrivateKeyMethod method) {
        ObjectUtil.checkNotNull(method, "method");
        Lock writerLock = ctxLock.writeLock();
        writerLock.lock();
        try {
            SSLContext.setPrivateKeyMethod(ctx, new PrivateKeyMethod(engineMap, method));
        } finally {
            writerLock.unlock();
        }
    }
870042
public static Object invokeMethod(Class<?> type,Object instance,String methodName,Class<?>[] inputTypes,Object[] input)
    {
        Method method=null;
        try
        {
            //get method
            method=type.getDeclaredMethod(methodName,inputTypes);
        }
        catch(Exception exception)
        {
            throw new FaxException("Unable to extract method: "+methodName+" from type: "+type,exception);
        }

        //set accessible
        method.setAccessible(true);

        Object output=null;
        try
        {
            //invoke method
            output=method.invoke(instance,input);
        }
        catch(Exception exception)
        {
            throw new FaxException("Unable to invoke method: "+methodName+" of type: "+type,exception);
        }
        
        return output;
    }
730198
public static MethodHandle defaultInvoker( Method method )
    {
        if ( !method.isDefault() )
        {
            throw new IllegalArgumentException( "Not a default method: " + method );
        }
        try
        {
            return LOOKUP.unreflectSpecial( method, method.getDeclaringClass() );
        }
        catch ( IllegalAccessException e )
        {
            throw new RuntimeException( "Reflection failed.", e );
        }
    }