Author: not Date: Fri May 13 19:08:16 2011 New Revision: 1102870 URL: http://svn.apache.org/viewvc?rev=1102870&view=rev Log: ARIES-613 Improvements to the exception messages for problems calling the destroy method.
1) Use LOGGER.error rather than info 2) When the destroy method does not exist do not treat it as an exception condition 3) When the destroy method throws an exception output a nice error message. Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java?rev=1102870&r1=1102869&r2=1102870&view=diff ============================================================================== --- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java (original) +++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java Fri May 13 19:08:16 2011 @@ -21,6 +21,7 @@ package org.apache.aries.blueprint.conta import static org.apache.aries.blueprint.utils.ReflectionUtils.getRealCause; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; @@ -45,6 +46,7 @@ import org.apache.aries.blueprint.proxy. import org.apache.aries.blueprint.utils.ReflectionUtils; import org.apache.aries.blueprint.utils.ReflectionUtils.PropertyDescriptor; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.service.blueprint.container.ComponentDefinitionException; import org.osgi.service.blueprint.container.ReifiedType; @@ -740,8 +742,20 @@ public class BeanRecipe extends Abstract if (method != null) { invoke(method, obj, (Object[]) null); } + } catch (ComponentDefinitionException e) { + // This exception occurs if the destroy method does not exist, so we just output the exception message. + LOGGER.error(e.getMessage()); + } catch (InvocationTargetException ite) { + Throwable t = ite.getTargetException(); + BundleContext ctx = blueprintContainer.getBundleContext(); + Bundle b = ctx.getBundle(); + String bundleIdentifier = b.getSymbolicName() + '/' + b.getVersion(); + LOGGER.error("The blueprint bean " + getName() + " in bundle " + bundleIdentifier + " incorrectly threw an exception from its destroy method.", t); } catch (Exception e) { - LOGGER.info("Error invoking destroy method", getRealCause(e)); + BundleContext ctx = blueprintContainer.getBundleContext(); + Bundle b = ctx.getBundle(); + String bundleIdentifier = b.getSymbolicName() + '/' + b.getVersion(); + LOGGER.error("An exception occurred while calling the destroy method of the blueprint bean " + getName() + " in bundle " + bundleIdentifier + ".", getRealCause(e)); } for (BeanProcessor processor : blueprintContainer.getProcessors(BeanProcessor.class)) { processor.afterDestroy(obj, getName());