Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6277781

Serialization of Enums over IIOP is broke.

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b07
    • CPU:
      generic, x86
    • OS:
      generic, linux

      Backports

        Description

        FULL PRODUCT VERSION :
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
        Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode)


        A DESCRIPTION OF THE PROBLEM :
        When Enums are passed over RMI IIOP, they are not serialized/deserialized correctly.

        They fail the equals() test. This is quite major.

        I have an application that serializes an enumeration across a socket connection. When I read one and do an equals against one of the local Enum objects, it fails. However, enum.name().equals(deserializedEnum.name()) returns true and so does enum.getClass().equals(deserializedEnum.name()).

        I am doing an import static com.foo.bar.MyEnum.* when I set my items to be serialized, I don't know if that causes a problem or not.

        However, I can't reproduce the error simply. Creating a local ByteArrayOutput/Input streams works ok. This seems to be happening over a socket connection.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        javac EnumIIOPBreakage.java
        rmic -classpath . -iiop Server
        java -classpath . EnumIIOPBreakage


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        equal? true
        classes equal? true
        names equal? true
        ACTUAL -
        equal? false
        classes equal? true
        names equal? true

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.rmi.*;
        import java.util.*;

        import javax.rmi.*;
        import javax.naming.*;

        enum MyEnum { ONE, TWO, THREE };

        public class EnumIIOPBreakage
        {
          public static void main(String[] args)
            throws Throwable
          {
            Hashtable properties = new Hashtable();
            properties.put("java.naming.factory.initial",
                           "com.sun.jndi.cosnaming.CNCtxFactory");
            properties.put("java.naming.provider.url", "iiop://localhost:1099");

            new Server(properties);

            Context context = new InitialContext(properties);
            Object ref = context.lookup("server");
            RServer server = (RServer) PortableRemoteObject.narrow(ref, RServer.class);

            System.out.println("equal? " +
                               MyEnum.ONE.equals(server.get(MyEnum.ONE.name())));
            System.out.println("classes equal? " +
                               MyEnum.ONE.getClass().equals(
                                   server.get(MyEnum.ONE.name()).getClass()));
            System.out.println("names equal? " +
                               MyEnum.ONE.name().equals(
                                   server.get(MyEnum.ONE.name()).name()));
          }
        }

        class Server
          implements RServer
        {
          public Server(Hashtable properties)
            throws Throwable
          {
            PortableRemoteObject.exportObject(this);

            Context context = new InitialContext(properties);
            context.rebind("server", this);
          }

          public MyEnum get(String name)
          {
            return MyEnum.valueOf(name);
          }
        }


        interface RServer
          extends Remote
        {
          MyEnum get(String name)
            throws RemoteException;
        }

        ---------- END SOURCE ----------
        ###@###.### 2005-05-30 05:28:17 GMT

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                kcavanauorcl Ken Cavanaugh (Inactive)
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: