You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Babak Vahdat (JIRA)" <ji...@apache.org> on 2012/09/12 13:43:09 UTC

[jira] [Comment Edited] (CAMEL-5598) BeanProcessor - InvocationTargetException propagates cause instead of target

    [ https://issues.apache.org/jira/browse/CAMEL-5598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13453904#comment-13453904 ] 

Babak Vahdat edited comment on CAMEL-5598 at 9/12/12 10:41 PM:
---------------------------------------------------------------

Actually it does *not* make any difference which method you would use ({{getTargetException()}} or {{getCause()}}) as [{{Throwable.getCause()}}|http://docs.oracle.com/javase/6/docs/api/java/lang/Throwable.html#getCause()] 
is overriden by this class returning the target field (the same as {{getTargetException()}}):

{code:java}
public class InvocationTargetException extends Exception {
...
    /**
     * Get the thrown target exception.
     *
     * <p>This method predates the general-purpose exception chaining facility.
     * The {@link Throwable#getCause()} method is now the preferred means of
     * obtaining this information.
     *
     * @return the thrown target exception (cause of this exception).
     */
    public Throwable getTargetException() {
	return target;
    }

    /**
     * Returns the cause of this exception (the thrown target exception,
     * which may be <tt>null</tt>).
     *
     * @return  the cause of this exception.
     * @since   1.4
     */
    public Throwable getCause() {
        return target;
    }
}
{code}

However {{getCause()}} should be the prefered one which was introduced by Joshua Bloch in JDK 1.4. And this's what {{BeanProcessor}} already does.

                
      was (Author: bvahdat):
    Actually it does *not* make any difference which method you would use (getTargetException() or getCause()) as [Throwable.getCause()|http://docs.oracle.com/javase/6/docs/api/java/lang/Throwable.html#getCause()] 
is overriden by this class returning the target field (the same as getTargetException()):

{code:java}
public class InvocationTargetException extends Exception {
...
    /**
     * Get the thrown target exception.
     *
     * <p>This method predates the general-purpose exception chaining facility.
     * The {@link Throwable#getCause()} method is now the preferred means of
     * obtaining this information.
     *
     * @return the thrown target exception (cause of this exception).
     */
    public Throwable getTargetException() {
	return target;
    }

    /**
     * Returns the cause of this exception (the thrown target exception,
     * which may be <tt>null</tt>).
     *
     * @return  the cause of this exception.
     * @since   1.4
     */
    public Throwable getCause() {
        return target;
    }
}
{code}

However getCause() should be the prefered one which was introduced by Joshua Bloch in JDK 1.4. And this's what BeanProcessor already does.

                  
> BeanProcessor - InvocationTargetException propagates cause instead of target
> ----------------------------------------------------------------------------
>
>                 Key: CAMEL-5598
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5598
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.10.0
>            Reporter: Gilles Letare
>            Assignee: Babak Vahdat
>            Priority: Trivial
>
> In BeanProcessor.process, InvocationTargetException's are caught, but the exception set on the exchange is the cause instead of the target.
> See lines 164-180 on version 2.10.0:
> {code}
> try {
>     ...
>     value = invocation.proceed(callback, sync);
>     ...
> } catch (InvocationTargetException e) {
>     exchange.setException(e.getCause());
>     ...
> }
> {code}
> I think it should be:
> {code}
> } catch (InvocationTargetException e) {
>     exchange.setException(e.getTargetException());
>     ...
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira