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

Enum Serialization over IIOP is broken

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 6u21
    • other-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Serialization of enums using RMI-IIOP is impossible

      This worked in 1.6.0_18 at least.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Sep 29, 2010 6:15:39 PM com.sun.corba.se.impl.encoding.CDRInputStream_1_0 read_value
      WARNING: "IOP00810211: (MARSHAL) Exception from readValue on ValueHandler in CDRInputStream"
      org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 211 completed: Maybe
              at com.sun.corba.se.impl.logging.ORBUtilSystemException.valuehandlerReadException(ORBUtilSystemException.java:7004)
              at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1045)
              at com.sun.corba.se.impl.encoding.CDRInputStream.read_value(CDRInputStream.java:253)
              at _RServer_Stub.get(Unknown Source)
              at EnumIIOPBreakage.main(EnumIIOPBreakage.java:25)
      Caused by: java.lang.IllegalArgumentException
              at java.nio.Buffer.position(Buffer.java:218)
              at com.sun.corba.se.impl.encoding.ByteBufferWithInfo.position(ByteBufferWithInfo.java:158)
              at com.sun.corba.se.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:77)
              at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_long(CDRInputStream_1_0.java:478)
              at com.sun.corba.se.impl.encoding.CDRInputStream.read_long(CDRInputStream.java:133)
              at com.sun.corba.se.impl.io.IIOPInputStream.inputObject(IIOPInputStream.java:1002)
              at com.sun.corba.se.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:400)
              at com.sun.corba.se.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:327)
              at com.sun.corba.se.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:293)
              at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1034)
              ... 3 more
      Exception in thread "main" java.rmi.MarshalException: CORBA MARSHAL 1398079699 Maybe; nested exception is:
              org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 211 completed: Maybe
              at com.sun.corba.se.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:197)
              at javax.rmi.CORBA.Util.mapSystemException(Util.java:67)
              at _RServer_Stub.get(Unknown Source)
              at EnumIIOPBreakage.main(EnumIIOPBreakage.java:25)
      Caused by: org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 211 completed: Maybe
              at com.sun.corba.se.impl.logging.ORBUtilSystemException.valuehandlerReadException(ORBUtilSystemException.java:7004)
              at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1045)
              at com.sun.corba.se.impl.encoding.CDRInputStream.read_value(CDRInputStream.java:253)
              ... 2 more
      Caused by: java.lang.IllegalArgumentException
              at java.nio.Buffer.position(Buffer.java:218)
              at com.sun.corba.se.impl.encoding.ByteBufferWithInfo.position(ByteBufferWithInfo.java:158)
              at com.sun.corba.se.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:77)
              at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_long(CDRInputStream_1_0.java:478)
              at com.sun.corba.se.impl.encoding.CDRInputStream.read_long(CDRInputStream.java:133)
              at com.sun.corba.se.impl.io.IIOPInputStream.inputObject(IIOPInputStream.java:1002)
              at com.sun.corba.se.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:400)
              at com.sun.corba.se.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:327)
              at com.sun.corba.se.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:293)
              at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1034)
              ... 3 more


      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 ----------

      CUSTOMER SUBMITTED WORKAROUND :
      A) Don't use Enum types. This is a bad workaround

      B) Change Remote interfaces to use Strings instead of proper enum types. This is a horrible workaround.

            robm Robert Mckenna
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: