Read only archive ; use https://github.com/JacORB/JacORB/issues for new issues

Bug 960

Summary: ORB interception mechanism doesn't transfer ServiceContexts properly in local invocations when application interceptors raise exceptions
Product: JacORB Reporter: Amadeu A. Barbosa Jr <amadeu>
Component: ORBAssignee: Mailinglist to track bugs <jacorb-bugs>
Status: RESOLVED FIXED    
Severity: major CC: jacorb
Priority: P5    
Version: 3.1   
Hardware: All   
OS: All   
Attachments: Sample code that manifest the bug

Description Amadeu A. Barbosa Jr 2013-07-31 17:12:10 UTC
Created attachment 422 [details]
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);
Comment 1 Nick Cross 2013-11-20 09:38:04 UTC
Fixed by 9659de46abb78a899381ff4f439fbfe5fd246584. Thanks for test and patch.