Author: clement
Date: Thu Jul 3 07:26:08 2008
New Revision: 673686
URL: http://svn.apache.org/viewvc?rev=673686&view=rev
Log:
Fix the issue Felix-621.
When the instance creation failed, the instance is deleted. This allows
deleting both the instance and attached handlers.
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?rev=673686&r1=673685&r2=673686&view=diff
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
Thu Jul 3 07:26:08 2008
@@ -141,12 +141,23 @@
*/
public ComponentInstance createInstance(Dictionary config, IPojoContext
context, HandlerManager[] handlers) throws
org.apache.felix.ipojo.ConfigurationException {
InstanceManager instance = new InstanceManager(this, context,
handlers);
- instance.configure(m_componentMetadata, config);
+
try {
+ instance.configure(m_componentMetadata, config);
instance.start();
return instance;
- } catch (IllegalStateException e) {
- // An exception occurs during the start method.
+ } catch (ConfigurationException e) {
+ // An exception occurs while executing the configure or start
methods.
+ if (instance != null) {
+ instance.dispose();
+ instance = null;
+ }
+ throw e;
+ } catch (Throwable e) { // All others exception are handled here.
+ if (instance != null) {
+ instance.dispose();
+ instance = null;
+ }
m_logger.log(Logger.ERROR, e.getMessage(), e);
throw new ConfigurationException(e.getMessage());
}