[ 
https://issues.apache.org/jira/browse/FELIX-4154?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Guillaume Sauthier resolved FELIX-4154.
---------------------------------------

    Resolution: Won't Fix

I though a lot about this issue and finally come to the conclusion that 
throwing an Exception in the InstanceManager.setState() method is really a bad 
idea with unmanaged consequences :'(

That said, It gave me a lot a fuel for improvements that would be present in 
iPOJO 2 :)

To conclude, just notice that if the createComponentMethod() cannot complete 
its job (without throwing an Exception, that is your use case), you can observe 
the ComponentInstance's state to see if it is STOPPED or not.

The createComponentInstance() tries to start the instance automatically. The 
normal output of this behavior is that the ComponentInstance state is either 
VALID (super, every handler is valid) or INVALID (less good, some handlers are 
invalid, but no real errors). If (for some reasons), the instance startup has 
failed, the ComponentInstance is automatically stopped (state == STOPPED).
                
> InstanceManager.setState() method should throws exception in case of failure
> ----------------------------------------------------------------------------
>
>                 Key: FELIX-4154
>                 URL: https://issues.apache.org/jira/browse/FELIX-4154
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: ipojo-runtime-1.10.1
>            Reporter: Mohammed Boukada
>            Assignee: Guillaume Sauthier
>
> In my use case, I create an instance of a component using 
> factory.createComponentInstance(props). If an error occurs in setState() 
> method, it is managed internally and does not return anything to the caller. 
> Code :
>  try {
>                     for (int i = 0; i < m_handlers.length; i++) {
>                         m_handlers[i].getHandler().stateChanged(state);
>                     }
>                 } catch (IllegalStateException e) {
>                     // When an illegal state exception happens, the instance 
> manager must be stopped immediately.
>                     stop();
>                     m_logger.log(Logger.ERROR, e.getMessage(), e);
>                     return;
>                 }
> Exception stack trace :
> java.lang.reflect.InvocationTargetException
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:601)
>       at org.apache.felix.ipojo.util.Callback.call(Callback.java:237)
>       at org.apache.felix.ipojo.util.Callback.call(Callback.java:193)
>       at 
> org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86)
>       at 
> org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:162)
>       at 
> org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)
>       at 
> org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:536)
>       at 
> org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:418)
>       at 
> org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:178)
>       at 
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:309)
>       at 
> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:236)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to