~ubuntu-branches/ubuntu/raring/testng/raring

« back to all changes in this revision

Viewing changes to src/main/org/testng/internal/MethodHelper.java

  • Committer: Bazaar Package Importer
  • Author(s): Marcus Better
  • Date: 2010-04-25 09:42:04 UTC
  • mfrom: (1.1.2 upstream) (2.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20100425094204-rg6mw229trcyyd63
* New upstream version.
* Switch to source format 3.0 (quilt). Thanks to Raphael
  Hertzog. (Closes: #538708)
* Disable tests that fail with qdox 1.11. Thanks to Daniel Schepler
  (Closes: #577477).
* debian/control: Bump standards-version (no changed needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
600
600
  throws InvocationTargetException, IllegalAccessException 
601
601
  {
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
 
607
      // is it static?
 
608
      boolean isStatic = Modifier.isStatic(thisMethod.getModifiers());
 
609
      if (!isStatic) {
 
610
        // not static, so grab a method with the same name and signature in this case
 
611
        Class<?> clazz = instance.getClass();
 
612
        try {
 
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()) {
 
618
            try {
 
619
              thisMethod = clazz.getDeclaredMethod(thisMethod.getName(), thisMethod.getParameterTypes());
 
620
              found = true;
 
621
              break;
 
622
            } catch (Exception e2) {}
 
623
          }
 
624
          if (!found) {
 
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");
 
628
            }
 
629
            throw new RuntimeException("Can't invoke method " + thisMethod + " on this instance of " + instance.getClass()+ " due to class mismatch");
 
630
          }
 
631
        }
 
632
      }
 
633
      
 
634
      
 
635
      
 
636
    }
 
637
 
603
638
    boolean isPublic = Modifier.isPublic(thisMethod.getModifiers());
604
639
 
605
640
    try {