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

Problems with unions there two or more cases points to the same object.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.0
    • other-libs
    • merlin
    • generic
    • generic



        Name: rlT66838 Date: 04/13/2000


        java version "1.3.0rc2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
        Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, mixed mode)

        Consider following piece of idl-code:

        enum WeatherType {Rain, Snow, Sun};

        union Weather switch(WeatherType) {
          case Rain:
          case Snow:
            boolean go;
          case Sun:
            boolean stay;
        };

        This means that either if the discriminator value is Rain or Snow, the value go
        should be used. Is the discriminator Sun, then stay should be used. Compiling
        this code with idlj, information in the typecode is lost about one of the first
        two cases. Only one is produced in the typecodes list of union-members.

        Below follows an output of the produced java helper-file:

        <<<WeatherHelper.java>>>
        /**
        * test/WeatherHelper.java
        * Generated by the IDL-to-Java compiler (portable), version "3.0"
        * from test2.idl
        * Thursday, April 13, 2000 4:59:38 PM GMT+02:00
        */

        abstract public class WeatherHelper
        {
          private static String _id = "IDL:test/Weather:1.0";

          public static void insert (org.omg.CORBA.Any a, test.Weather that)
          {
            org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();
            a.type (type ());
            write (out, that);
            a.read_value (out.create_input_stream (), type ());
          }

          public static test.Weather extract (org.omg.CORBA.Any a)
          {
            return read (a.create_input_stream ());
          }

          private static org.omg.CORBA.TypeCode __typeCode = null;
          synchronized public static org.omg.CORBA.TypeCode type ()
          {
            if (__typeCode == null)
            {
              org.omg.CORBA.TypeCode _disTypeCode0;
              _disTypeCode0 = test.WeatherTypeHelper.type ();
              org.omg.CORBA.UnionMember[] _members0 = new org.omg.CORBA.UnionMember [2];
              org.omg.CORBA.TypeCode _tcOf_members0;
              org.omg.CORBA.Any _anyOf_members0;

              // Branch for go
              _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any ();
              test.WeatherTypeHelper.insert (_anyOf_members0, test.WeatherType.Rain);
              _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc
        (org.omg.CORBA.TCKind.tk_boolean);
              _members0[0] = new org.omg.CORBA.UnionMember (
                "go",
                _anyOf_members0,
                _tcOf_members0,
                null);

              // Branch for stay
              _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any ();
              test.WeatherTypeHelper.insert (_anyOf_members0, test.WeatherType.Sun);
              _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc
        (org.omg.CORBA.TCKind.tk_boolean);
              _members0[1] = new org.omg.CORBA.UnionMember (
                "stay",
                _anyOf_members0,
                _tcOf_members0,
                null);
              __typeCode = org.omg.CORBA.ORB.init ().create_union_tc
        (test.WeatherHelper.id (), "Weather", _disTypeCode0, _members0);
            }
            return __typeCode;
          }

          public static String id ()
          {
            return _id;
          }

          public static test.Weather read (org.omg.CORBA.portable.InputStream istream)
          {
            test.Weather value = new test.Weather ();
            test.WeatherType _dis0 = null;
            _dis0 = test.WeatherTypeHelper.read (istream);
            switch (_dis0.value ())
            {
              case test.WeatherType._Rain:
              case test.WeatherType._Snow:
                boolean _go = false;
                _go = istream.read_boolean ();
                value.go (_go);
                break;
              case test.WeatherType._Sun:
                boolean _stay = false;
                _stay = istream.read_boolean ();
                value.stay (_stay);
                break;
              default:
                throw new org.omg.CORBA.BAD_OPERATION ();
            }
            return value;
          }

          public static void write (org.omg.CORBA.portable.OutputStream ostream,
        test.Weather value)
          {
            test.WeatherTypeHelper.write (ostream, value.discriminator ());
            switch (value.discriminator ().value ())
            {
              case test.WeatherType._Rain:
              case test.WeatherType._Snow:
                ostream.write_boolean (value.go ());
                break;
              case test.WeatherType._Sun:
                ostream.write_boolean (value.stay ());
                break;
              default:
                throw new org.omg.CORBA.BAD_OPERATION ();
            }
          }

        }

        I've tested this code with Orbacus idl-compiler and the type-code information
        generated is far more useful than the one produced by idlj.
        (Review ID: 103646)
        ======================================================================

              kcavanauorcl Ken Cavanaugh (Inactive)
              rlewis Roger Lewis (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: