You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by "Thiago Soares (JIRA)" <ji...@apache.org> on 2013/01/28 22:49:12 UTC

[jira] [Created] (OWB-771) Invocation​ContextImpl cleans target field if occurs an exception

Thiago Soares created OWB-771:
---------------------------------

             Summary: Invocation​ContextImpl cleans target field if occurs an exception
                 Key: OWB-771
                 URL: https://issues.apache.org/jira/browse/OWB-771
             Project: OpenWebBeans
          Issue Type: Bug
          Components: Core, Interceptor and Decorators
    Affects Versions: 1.1.7, 1.1.6, 1.1.5, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1.0
            Reporter: Thiago Soares
            Priority: Trivial


I've done some tests using ApacheOpenWebBeans 1.1.x as the CDI implementation.
I am using a Framework (frameworkdemoiselle.gov.br) that offers an
interceptor that handles exceptions thrown by the target bean.

A summary of this interceptor is written bellow:

=========================
@AroundInvoke
public Object manage(final InvocationContext ic) throws Exception {
        Object result = null;

        try {
                result = ic.proceed();

        } catch (Exception cause) {
                // Handle Exception here
                target = ic.getTarget();
                ...

        }
        return result;
}
=========================

The "Handle Exception" logic uses the target bean. The problem is that
the "ic.getTarget()" method returns null and i get a
NullPointerException.
I've done the same test using WELD and ic.getTarget() does not returns null.

Analyzing the source code of the class
"org.apache.webbeans.intercept.InvocationContextImpl" I see that it
destroys the target instance when it catches an exception.

=========================
public Object proceed() throws Exception
{
        try
        {
            if (type.equals(InterceptionType.AROUND_INVOKE))
            {
                return proceedAroundInvokes(interceptorDatas);
            }
            else if (type.equals(InterceptionType.AROUND_TIMEOUT))
            {
                return proceedAroundTimeouts(interceptorDatas);
            }
            return proceedCommonAnnots(interceptorDatas, type);

        }
        catch (InvocationTargetException ite)
        {
            target = null; // destroy target instance    <<=================

            // Try to provide the original exception to the interceptor stack,
            // not the InvocationTargetException from Method.invoke
            Throwable t = ite.getCause();
            if (t instanceof Exception)
            {
                throw (Exception) t;
            }
            throw ite;
        }
        catch (Exception e)
        {
            target = null; // destroy target instance <<=================

            throw e;
        }
}
=========================

My question is: Why we need to destroy the target instance when occurs
an Exception? Doing it so, the interceptor cannot get the target after
invoking proceed() method.

--
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