Uploaded image for project: 'OpenWebBeans'
  1. OpenWebBeans
  2. OWB-771

Invocation​ContextImpl cleans target field if occurs an exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.1.7
    • 1.6.0
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            thiago.soares Thiago Soares
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: