equals() behaves differently with stubs and proxies. is this the right?

Roland Schwarzkopf <[email protected]> Mon, 1 May 2006 01:46:23 -0600
Newsgroups gmane.comp.java.sun.rmi
Message-ID <LISTSERV%[email protected]>
I have postet this message on the forum and was asked to post it to this
list (at least I hope this is the right list). So this is just a copy of my
post at

http://forum.java.sun.com/thread.jspa?threadID=732274&tstart=0

I just discovered that the equals Method behaves differently when based on
whether a rmic-made stub or a dynamically created proxy is used. Is this
really the way it should be?

Example code:

public interface RInt extends Remote {
  public void doSomething() throws RemoteException;
}

public class RInt_Impl extends UnicastRemoteObject implements RInt {
  public RInt_Impl() throws RemoteException {
    super();
  }

  public void doSomething() {
    // ...
  }

  public static void main(String[] args) {
    try {
      RInt_Impl impl = new RInt_Impl();
      System.out.println(impl);

      Remote implStub = RemoteObject.toStub(impl);
      System.out.println(implStub);

      System.out.println(implStub.getClass().toString());

      System.out.printf("impl.equals(implStub) = %b%n",
(impl.equals(implStub)));
      System.out.printf("implStub.equals(impl) = %b%n",
(implStub.equals(impl)));
    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}

It creates a remote object, get's the stub for it and then compares both
against each other (with some additional output).

When a dynamically created proxy is used, the program outputs the following:

RInt_Impl[UnicastServerRef [liveRef:
[endpoint:[89.50.242.172:2591](local),objID:[0]]]]
Proxy[RInt,RemoteObjectInvocationHandler[UnicastRef [liveRef:
[endpoint:[89.50.242.172:2591](local),objID:[0]]]]]
class $Proxy0
impl.equals(implStub) = false
implStub.equals(impl) = false

After creating a stub with rmic the program outputs the following:

RInt_Impl[UnicastServerRef [liveRef:
[endpoint:[89.50.242.172:2594](local),objID:[0]]]]
RInt_Impl_Stub[UnicastRef [liveRef:
[endpoint:[89.50.242.172:2594](local),objID:[0]]]]
class RInt_Impl_Stub
impl.equals(implStub) = true
implStub.equals(impl) = true

This behaviour occurs both on Java 1.5.0-b64 and Java 1.5.0_06-b05 (both on
Windows XP).

Maybe this is a bug?

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html