JDK-4780678 : CORBA: _this() returns wrong object id
  • Type: Bug
  • Component: other-libs
  • Sub-Component: corba:idl
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2002-11-18
  • Updated: 2004-01-19
  • Resolved: 2004-01-19
Description

Name: nt126004			Date: 11/18/2002


FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

FULL OPERATING SYSTEM VERSION :
SuSE Linux 8.0 running Linux Kernel 2.4.18

ADDITIONAL OPERATING SYSTEMS :
Windows NT 4.0 SP5, Windows 2000


A DESCRIPTION OF THE PROBLEM :
Class DelegateImpl.this_object():
When this method is called from a POATie's _this() method
and you are in an invocation context, it returns always the
object id of the currently invoked object (independent from
the passed Servant Self parameter).


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a servant
2. Invoke a method of the servant from a client. Retrieve a
object reference of another servant using
other_servant._this(orb).
3. The returned object reference contains the wrong object
key. Its not possible to call any method of the other servant.

With the provided source code:
Put the code in the named files (all in one directory)
idlj test.idl
javac *.java
tnameserv -ORBInitRef:12345 &
java Server -ORBInitRef
NameService=corbaloc:iiop:localhost:12345/NameService &
java Client -ORBInitRef
NameService=corbaloc:iiop:localhost:12345/NameService

-> Client crashes with a org.omg.CORBA.BAD_OPERATION

EXPECTED VERSUS ACTUAL BEHAVIOR :
The returned object reference must contain the correct
object id.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
test.idl
----------
interface Helper
{
    void help();
};

interface Creator
{
    Helper getHelp( in boolean direct);
};


HelperImpl.java
---------------
public class HelperImpl implements HelperOperations
{
    public void help()
    {
        System.out.println("No help available");
    }
}

CreatorImpl.java
----------------
public class CreatorImpl implements CreatorOperations
{
    private HelperPOATie helper = null;
    private Helper       helperRef = null;
    private org.omg.CORBA.ORB orb = null;


    public void setORB(org.omg.CORBA.ORB anOrb)
    {
        orb = anOrb;
        HelperImpl impl = new HelperImpl();
	helper = new HelperPOATie(impl);
	// Here i create an object reference outside of an corba invocation
	// This reference seems to be correct.
	helperRef = helper._this(orb);
    }
    
    public Helper getHelp(boolean direct)
    {
        if(direct == true)
	    // return the working reference.
	    return helperRef;
	else
	    // this returns a wrong object reference!
	    return helper._this();
    }
}

Server.java
-----------
import org.omg.CosNaming.*;
// The package containing special exceptions
// thrown by the name service.
import org.omg.CosNaming.NamingContextPackage.*;
// All CORBA applications need these classes.
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

public class Server
{
  public static void main(String args[])
  {
    try{
    
      // Create and initialize the ORB
      ORB orb = ORB.init(args, null);
      
      // Get reference to rootpoa & activate the POAManager
      POA rootpoa = (POA)orb.resolve_initial_references("RootPOA");
      rootpoa.the_POAManager().activate();

      // Create the servants and register it with the ORB
      CreatorImpl creatorImpl = new CreatorImpl();

      creatorImpl.setORB(orb);

      // create a tie, with servant being the delegate.
      CreatorPOATie creatorPoaTie = new CreatorPOATie(creatorImpl, rootpoa);

      // obtain the objectRef for the tie
      Creator creatorRef = creatorPoaTie._this(orb);
      
      // Get the root naming context
      boolean	nsFound = false;
      org.omg.CORBA.Object objRef = null;
      
      while(!nsFound)
      {
          try
	  {
              objRef = orb.resolve_initial_references("NameService");
	      nsFound = true;
	  }
	  catch(Exception nsException)
	  {
	      try
	      {
	          java.lang.Thread.sleep(2000);
	      }
	      catch(Exception sleepException)
	      {
	      }
	  }
      }
      NamingContext ncRef = NamingContextHelper.narrow(objRef);
      
      
      // Bind the object references in naming
      NameComponent ncCreator = new NameComponent("theCreator", "");
      NameComponent creatorPath[] = {ncCreator};
      ncRef.rebind(creatorPath, creatorRef);
      
      // Wait for invocations from clients
      orb.run();
      
    }
    catch(Exception e)
    {
        System.err.println("ERROR: " + e);
        e.printStackTrace(System.out);
    }
  }
}


Client.java
-----------
// will use the naming service.
import org.omg.CosNaming.*;
// The package containing special exceptions
// thrown by the name service.
import org.omg.CosNaming.NamingContextPackage.*;
// All CORBA applications need these classes.
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

public class Client
{ 
  public static void main(String args[])
  {
    try
    {
      // Create and initialize the ORB
      ORB orb = ORB.init(args, null);
      
      // Get reference to rootpoa & activate the POAManager
      POA rootpoa = (POA)orb.resolve_initial_references("RootPOA");
      rootpoa.the_POAManager().activate();

      // 1. Get the root naming context
      boolean	nsFound = false;
      org.omg.CORBA.Object objRef = null;
      
      while(!nsFound)
      {
          try
	  {
              objRef = orb.resolve_initial_references("NameService");
	      nsFound = true;
	  }
	  catch(Exception nsException)
	  {
	      try
	      {
	          java.lang.Thread.sleep(2000);
	      }
	      catch(Exception sleepException)
	      {
	      }
	  }
      }
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
      
      // 2. get a reference to the servant object.
      // this servant will return a reference to a helper object in
      // two different ways.
      Creator	theCreator = null;
      
      try
      {
	  theCreator = CreatorHelper.narrow(ncRef.resolve_str("theCreator"));
      }
      catch(Exception immException)
      {
	  System.out.println("Could not find Creator!");
      }

      // 3. Get reference to the helper.
      // See Creator.java for the two different ways the reference is
      // returned.
      Helper		helperDirect = theCreator.getHelp(true);
      Helper		helperIndirect = theCreator.getHelp(false);

      System.out.println(orb.object_to_string(helperDirect));
      System.out.println(orb.object_to_string(helperIndirect));
      // both calls should do the same thing. But the second one crashes!!
      helperDirect.help();
      helperIndirect.help();
    }
    catch(Exception e)
    {
        System.err.println("ERROR: " + e);
        e.printStackTrace(System.out);
    }
  }
}


---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Use instead of _this() the following:
xxxHelper.narrow(poa.servant_to_reference(xxxTie));
(Review ID: 166707) 
======================================================================

Comments
EVALUATION Will try to fix it in Tiger. ###@###.### 2002-11-20
20-11-2002