<html>
    <head>
      <base href="http://www.jacorb.org/bugzilla/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - ORB interception mechanism doesn't transfer ServiceContexts properly in local invocations when application interceptors raise exceptions"
   href="http://www.jacorb.org/bugzilla/show_bug.cgi?id=960">960</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ORB interception mechanism doesn't transfer ServiceContexts properly in local invocations when application interceptors raise exceptions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>JacORB
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.1
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>major
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P5
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>ORB
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>jacorb-bugs@lists.spline.inf.fu-berlin.de
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>amadeu@tecgraf.puc-rio.br
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=422" name="attach_422" title="Sample code that manifest the bug">attachment 422</a> <a href="attachment.cgi?id=422&action=edit" title="Sample code that manifest the bug">[details]</a></span>
Sample code that manifest the bug

I observed a bug in org.jacorb.orb.Delegate.servant_preinvoke method when both
server and client side are the same process using the same ORB. The client
interceptors don't have access to reply ServiceContexts in receive_exception
interception point as should be (conform to CORBA spec). The problem doesn't
occur in remote invocation cenario.

I attached a sample code that manifest this bug. The mainclass
demo.InterceptorSameORBServerAndClient manifest this bug. Another classes like
demo.InterceptorServer and demo.InterceptorClient show that this bug doesn't
affect the remote cenario (when the invocation is remote). Probably when the
server side use a differente ORB than the client side the problem probably
doesn't occur also.

Explanation about my test: The demo.ServerRequestInterceptorImpl implements
receive_request and put a ServiceContext with 1234 ID in the ServerRequestInfo
and raises a NO_PERMISSION exception. After that, the
demo.ClientRequestInterceptorImpl implements receive_exception and try to get
the reply ServiceContext with 1234 ID to extract some the information that I
put there previously but I got a BAD_PARAM exception as showed in the
stacktrace:

SEVERE: unexpected exception during servant_preinvoke
org.omg.CORBA.BAD_PARAM: No ServiceContext with id 1234
    at
org.jacorb.orb.portableInterceptor.RequestInfoImpl.get_reply_service_context(RequestInfoImpl.java:192)
    at
org.jacorb.orb.portableInterceptor.ClientRequestInfoImpl.get_reply_service_context(ClientRequestInfoImpl.java:394)
    at
demo.ClientRequestInterceptorImpl.receive_exception(ClientRequestInterceptorImpl.java:26)
    at
org.jacorb.orb.portableInterceptor.ClientInterceptorIterator.invoke(ClientInterceptorIterator.java:138)
    at
org.jacorb.orb.portableInterceptor.AbstractInterceptorIterator.iterate(AbstractInterceptorIterator.java:66)
    at
org.jacorb.orb.portableInterceptor.ClientInterceptorIterator.iterate(ClientInterceptorIterator.java:87)
    at
org.jacorb.orb.DefaultClientInterceptorHandler.invokeInterceptors(DefaultClientInterceptorHandler.java:328)
    at
org.jacorb.orb.DefaultClientInterceptorHandler.handle_receive_exception(DefaultClientInterceptorHandler.java:261)
    at
org.jacorb.orb.DefaultClientInterceptorHandler.handle_receive_exception(DefaultClientInterceptorHandler.java:231)
    at org.jacorb.orb.Delegate.servant_preinvoke(Delegate.java:2755)
    at
org.omg.CORBA.portable.ObjectImpl._servant_preinvoke(ObjectImpl.java:135)
    at demo._HelloStub.sayHello(_HelloStub.java:73)
    at
demo.InterceptorSameORBServerAndClient.main(InterceptorSameORBServerAndClient.java:33)
Exception in thread "main" org.omg.CORBA.BAD_PARAM: No ServiceContext with id
1234
    at
org.jacorb.orb.portableInterceptor.RequestInfoImpl.get_reply_service_context(RequestInfoImpl.java:192)
    at
org.jacorb.orb.portableInterceptor.ClientRequestInfoImpl.get_reply_service_context(ClientRequestInfoImpl.java:394)
    at
demo.ClientRequestInterceptorImpl.receive_exception(ClientRequestInterceptorImpl.java:26)
    at
org.jacorb.orb.portableInterceptor.ClientInterceptorIterator.invoke(ClientInterceptorIterator.java:138)
    at
org.jacorb.orb.portableInterceptor.AbstractInterceptorIterator.iterate(AbstractInterceptorIterator.java:66)
    at
org.jacorb.orb.portableInterceptor.ClientInterceptorIterator.iterate(ClientInterceptorIterator.java:87)
    at
org.jacorb.orb.DefaultClientInterceptorHandler.invokeInterceptors(DefaultClientInterceptorHandler.java:328)
    at
org.jacorb.orb.DefaultClientInterceptorHandler.handle_receive_exception(DefaultClientInterceptorHandler.java:261)
    at
org.jacorb.orb.DefaultClientInterceptorHandler.handle_receive_exception(DefaultClientInterceptorHandler.java:231)
    at org.jacorb.orb.Delegate.servant_preinvoke(Delegate.java:2755)
    at
org.omg.CORBA.portable.ObjectImpl._servant_preinvoke(ObjectImpl.java:135)
    at demo._HelloStub.sayHello(_HelloStub.java:73)
    at
demo.InterceptorSameORBServerAndClient.main(InterceptorSameORBServerAndClient.java:33)

I studied the JacORB ORB code and I tried a very simple patch that seems to
resolve this issue. I'd like to ask you to analyse it:

--- jacorb-3.1-sources-upstream/src/org/jacorb/orb/Delegate.java    2012-08-19
14:26:54.000000000 -0300
+++ jacorb-3.1-sources-bugfix/src/org/jacorb/orb/Delegate.java    2013-07-30
16:05:57.000000000 -0300
@@ -2748,6 +2748,8 @@ public final class Delegate
                {
                    if (interceptors != null && orb.hasRequestInterceptors())
                    {
+                       Collection<ServiceContext> ctx =
sinfo.getReplyServiceContexts();
+                       interceptors.getInfo ().setReplyServiceContexts
(ctx.toArray (new ServiceContext[ctx.size ()]));
                        try
                        {
                            if (ex instanceof SystemException)

This bug was observed in JacORB 3.1 but it happens also in master branch code
hosted in github also. 
In master branch of github the patch is:
diff --git a/src/org/jacorb/orb/Delegate.java
b/src/org/jacorb/orb/Delegate.java
index a4b4166..3c80ffd 100644
--- a/src/org/jacorb/orb/Delegate.java
+++ b/src/org/jacorb/orb/Delegate.java
@@ -2885,6 +2885,8 @@ public final class Delegate
                     {
                         try
                         {
+                            Collection<ServiceContext> ctx =
sinfo.getReplyServiceContexts();
+                            interceptors.getInfo ().setReplyServiceContexts
(ctx.toArray (new ServiceContext[ctx.size ()]));
                             if (ex instanceof SystemException)
                             {
                                 interceptors.handle_receive_exception (
(SystemException) ex);</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>