deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johndam...@apache.org
Subject [2/2] deltaspike git commit: DELTASPIKE-1207: fix exception handling in DynamicMBeanWrapper.invoke()
Date Fri, 28 Oct 2016 00:47:28 GMT
DELTASPIKE-1207: fix exception handling in DynamicMBeanWrapper.invoke()

- don't wrap MBeanException directly thrown by the MBean method
- document exception handling in @JmxManaged

This closes #66
This closes #62


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/ebb24acc
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/ebb24acc
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/ebb24acc

Branch: refs/heads/master
Commit: ebb24accd05648df3206d77149ccf182d367700f
Parents: 7215f7b
Author: famod <f.modler@gmx.net>
Authored: Sun Oct 16 22:17:47 2016 +0200
Committer: John D. Ament <johndament@apache.org>
Committed: Thu Oct 27 20:47:08 2016 -0400

----------------------------------------------------------------------
 .../deltaspike/core/api/jmx/JmxManaged.java     |  6 +++--
 .../core/impl/jmx/DynamicMBeanWrapper.java      | 25 ++++++++++++++++----
 2 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ebb24acc/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/jmx/JmxManaged.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/jmx/JmxManaged.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/jmx/JmxManaged.java
index 1b1001b..b9f28ae 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/jmx/JmxManaged.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/jmx/JmxManaged.java
@@ -28,9 +28,11 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 /**
  * Describes a JMX operation or attribute, when used on a method or a field, respectively.
- *
+ * <p>
  * Used on a method it describes a JMX operation with an optional description.
- *
+ * An exception thrown by the method will be wrapped in a {@link javax.management.MBeanException}
+ * unless it already is a {@code MBeanException}.
+ * <p>
  * Used on a field it describes a JMX attribute. This attribute is readable if a getter on
this field is available and
  * writable if a setter is found.
  */

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ebb24acc/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/jmx/DynamicMBeanWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/jmx/DynamicMBeanWrapper.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/jmx/DynamicMBeanWrapper.java
index 09166d5..9a7c1e0 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/jmx/DynamicMBeanWrapper.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/jmx/DynamicMBeanWrapper.java
@@ -59,7 +59,6 @@ import org.apache.deltaspike.core.api.jmx.MBean;
 import org.apache.deltaspike.core.api.jmx.NotificationInfo;
 import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
 import org.apache.deltaspike.core.api.provider.BeanProvider;
-import org.apache.deltaspike.core.util.ExceptionUtils;
 import org.apache.deltaspike.core.util.ParameterUtil;
 
 /**
@@ -396,17 +395,33 @@ public class DynamicMBeanWrapper extends NotificationBroadcasterSupport
implemen
             {
                 return operations.get(actionName).invoke(instance(), params);
             }
-            catch (Exception e)
+            catch (InvocationTargetException e)
+            {
+                final Throwable cause = e.getCause();
+                if (cause instanceof Error)
+                {
+                    throw (Error) cause;
+                }
+                if (cause instanceof MBeanException)
+                {
+                    throw (MBeanException) cause;
+                }
+                throw new MBeanException((Exception) cause, actionName + " failed with exception");
+            }
+            catch (IllegalAccessException e)
+            {
+                throw new ReflectionException(e, actionName + " could not be invoked");
+            }
+            catch (IllegalArgumentException e)
             {
-                LOGGER.log(Level.SEVERE, actionName + " can't be invoked", e);
-                throw ExceptionUtils.throwAsRuntimeException(e);
+                throw new ReflectionException(e, actionName + " could not be invoked");
             }
             finally
             {
                 Thread.currentThread().setContextClassLoader(oldCl);
             }
         }
-        throw new MBeanException(new IllegalArgumentException(), actionName + " doesn't exist");
+        throw new ReflectionException(new NoSuchMethodException(actionName + " doesn't exist"));
     }
 
     private synchronized Object instance()


Mime
View raw message