Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DELTASPIKE-1207: fix exception handling in DynamicMBeanWrapper.invoke() #66

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -28,9 +28,11 @@

/**
* 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.
*/
Expand Down
Expand Up @@ -59,7 +59,6 @@
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;

/**
Expand Down Expand Up @@ -396,17 +395,33 @@ public Object invoke(final String actionName, final Object[] params, final Strin
{
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()
Expand Down