600
600
throws InvocationTargetException, IllegalAccessException
602
602
Object result = null;
603
// TESTNG-326, allow IObjectFactory to load from non-standard classloader
604
// If the instance has a different classloader, its class won't match the method's class
605
if (!thisMethod.getDeclaringClass().isAssignableFrom(instance.getClass())) {
606
// for some reason, we can't call this method on this class
608
boolean isStatic = Modifier.isStatic(thisMethod.getModifiers());
610
// not static, so grab a method with the same name and signature in this case
611
Class<?> clazz = instance.getClass();
613
thisMethod = clazz.getMethod(thisMethod.getName(), thisMethod.getParameterTypes());
614
} catch (Exception e) {
615
// ignore, the method may be private
616
boolean found = false;
617
for (; clazz != null; clazz = clazz.getSuperclass()) {
619
thisMethod = clazz.getDeclaredMethod(thisMethod.getName(), thisMethod.getParameterTypes());
622
} catch (Exception e2) {}
625
//should we assert here? Or just allow it to fail on invocation?
626
if (thisMethod.getDeclaringClass().getName().equals(instance.getClass().getName())) {
627
throw new RuntimeException("Can't invoke method " + thisMethod + ", probably due to classloader mismatch");
629
throw new RuntimeException("Can't invoke method " + thisMethod + " on this instance of " + instance.getClass()+ " due to class mismatch");
603
638
boolean isPublic = Modifier.isPublic(thisMethod.getModifiers());