Source:
<code>FactoryMethod( ConstructorOrMethod com, Object instance, IAnnotationFinder annotationFinder, ITestContext testContext, ITestObjectFactory objectFactory, DataProviderHolder holder) { super(com.getName(), com, annotationFinder, instance); this.holder = holder; init(instance, annotationFinder, com); Utils.checkInstanceOrStatic(instance, com.getMethod()); Utils.checkReturnType(com.getMethod(), Object[].class, IInstanceInfo[].class); Class<?> declaringClass = com.getDeclaringClass(); if (instance != null && !declaringClass.isAssignableFrom(instance.getClass())) { <START> Class<?> cls = instance.getClass(); <END> if (instance instanceof IParameterInfo) { cls = ((IParameterInfo) instance).getInstance().getClass(); } String msg = "Found a default constructor and also a Factory method when working with " + declaringClass.getName() + ". Root cause: Mismatch between instance/method classes:[" + cls.getName() + "] [" + declaringClass.getName() + "]"; throw new TestNGException(msg); } if (instance == null && com.getMethod() != null && !Modifier.isStatic(com.getMethod().getModifiers())) { throw new TestNGException( "An inner factory method MUST be static. But '" + com.getMethod().getName() + "' from '" + declaringClass.getName() + "' is not."); } if (com.getMethod() != null && !Modifier.isPublic(com.getMethod().getModifiers())) { try { com.getMethod().setAccessible(true); } catch (SecurityException e) { throw new TestNGException(com.getMethod().getName() + " must be public", e); } } factoryAnnotation = annotationFinder.findAnnotation(com, IFactoryAnnotation.class); m_instance = instance; m_testContext = testContext; NoOpTestClass tc = new NoOpTestClass(); tc.setTestClass(declaringClass); m_testClass = tc; this.objectFactory = objectFactory; m_groups = getAllGroups(declaringClass, testContext.getCurrentXmlTest(), annotationFinder); }</code><technical_language>I is a bit more readable: java if (instance instanceof IParameterInfo) { instance = ((IParameterInfo) instance).getInstance(); } Class<?> cls = instance.getClass();</technical_language>

Target:
FactoryMethod( ConstructorOrMethod com, Object instance, IAnnotationFinder annotationFinder, ITestContext testContext, ITestObjectFactory objectFactory, DataProviderHolder holder) { super(com.getName(), com, annotationFinder, instance); this.holder = holder; init(instance, annotationFinder, com); Utils.checkInstanceOrStatic(instance, com.getMethod()); Utils.checkReturnType(com.getMethod(), Object[].class, IInstanceInfo[].class); Class<?> declaringClass = com.getDeclaringClass(); if (instance != null && !declaringClass.isAssignableFrom(instance.getClass())) { if (instance instanceof IParameterInfo) { instance = ((IParameterInfo) instance).getInstance(); } Class<?> cls = instance.getClass(); String msg = "Found a default constructor and also a Factory method when working with " + declaringClass.getName() + ". Root cause: Mismatch between instance/method classes:[" + cls.getName() + "] [" + declaringClass.getName() + "]"; throw new TestNGException(msg); } if (instance == null && com.getMethod() != null && !Modifier.isStatic(com.getMethod().getModifiers())) { throw new TestNGException( "An inner factory method MUST be static. But '" + com.getMethod().getName() + "' from '" + declaringClass.getName() + "' is not."); } if (com.getMethod() != null && !Modifier.isPublic(com.getMethod().getModifiers())) { try { com.getMethod().setAccessible(true); } catch (SecurityException e) { throw new TestNGException(com.getMethod().getName() + " must be public", e); } } factoryAnnotation = annotationFinder.findAnnotation(com, IFactoryAnnotation.class); m_instance = instance; m_testContext = testContext; NoOpTestClass tc = new NoOpTestClass(); tc.setTestClass(declaringClass); m_testClass = tc; this.objectFactory = objectFactory; m_groups = getAllGroups(declaringClass, testContext.getCurrentXmlTest(), annotationFinder); }