[
https://issues.apache.org/jira/browse/OWB-771?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mark Struberg resolved OWB-771.
-------------------------------
Resolution: Fixed
Fix Version/s: 1.6.0
should be fixed since 1.2.x actually
> InvocationContextImpl 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.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.1.7
> Reporter: Thiago Soares
> Priority: Trivial
> Fix For: 1.6.0
>
>
> 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 was sent by Atlassian JIRA
(v6.3.4#6332)