You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2012/05/17 17:21:59 UTC

svn commit: r1339641 - /aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java

Author: gnodet
Date: Thu May 17 15:21:58 2012
New Revision: 1339641

URL: http://svn.apache.org/viewvc?rev=1339641&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/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java

Modified: aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
URL: http://svn.apache.org/viewvc/aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java?rev=1339641&r1=1339640&r2=1339641&view=diff
==============================================================================
--- aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java (original)
+++ aries/branches/blueprint-0.3.2-fixes/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java Thu May 17 15:21:58 2012
@@ -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());