Hi,

There are some failing tests in the SCR integration tests; for example:

test_component_factory_newInstance_failure:ComponentFactoryTest.test_component_factory_newInstance_failure:org.ops4j.pax.exam.forked.ForkedTestContainer@4a9c05(org.apache.felix.scr.integration.ComponentFactoryTest):
Cannot get m_componentInstances from Component: factory.component (1):
java.lang.NoSuchFieldException: m_componentInstances

Mainly, I think the problem comes from the ComponentTestBase.getField()
method, which is using Field.getDeclaredField(String);

So in the case of the ConfigurationComponentFactoryImpl class, this is a
problem because the field "m_componentInstances" is declared in the parent
class (ComponentFactoryImpl); and Field.getDeclaredField(String) does not
introspect parent.

So, I have committed the following patch in the scr integration test (I did
not create a jira issue, since the problem is only in the test, let me know
if I should have created one):

-------------------------------------------------------------------------------------
class ComponentTestBase {
    ...

    protected static Field getField( Class<?> type, String fieldName )
throws NoSuchFieldException
    {
        Class<?> clazz = type;
        while (clazz != null)
        {
            Field[] fields = clazz.getDeclaredFields();
            for (int i = 0; i < fields.length; i++)
            {
                Field field = fields[i];
                if (field.getName().equals(fieldName))
                {
                    field.setAccessible( true );
                    return field;
                }
            }
            clazz = clazz.getSuperclass();
        }
        throw new NoSuchFieldException(fieldName);
    }
-------------------------------------------------------------------------------------

best regards;
/pierre

Reply via email to