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

Prob w/gen'd java when using non-complete case-list for union's discriminator

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0, 1.4.0
    • other-libs
    • merlin
    • generic
    • generic
    • Not verified



        Name: krC82822 Date: 01/30/2001


        29 Jan 2001, eval1127@eng -- reproducible in both 1.3.0 and 1.4 beta build 49
        ----------------------
        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
        Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

        java version "1.4.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b49)
        Java HotSpot(TM) Client VM (build 1.4beta-B49, mixed mode)
        ----------

        According to the CORBA 2.3 specification from OMG (chapter 3.10.2.2
        Discriminated Unions), it is not required to list all possible values for a
        union discriminator in the case-list. Doing so and compiling the idl-code with
        'idlj'-compiler produces java-files that restrains the user from specifying
        those values that is non-present in the case-list. It cannot send or receive
        objects with the discriminator set to a value that is missing from the
        case-list, an BAD_OPERATION exception is thrown in those cases.

        According to the specification from OMG, the value of an union is the value of
        the discriminator together with either...
        ...the value of the element associated with the case, if explicitly listed.
        ...the value of the element associated with the default case, if explicitly
        listed.
        ...or no additional value, if case is not explicity listed.

        The 'idlj' produced code violates therefor with the last possible case.

        Here follows an idl-example that produces this bug:

        <<<test.idl>>>
        module test {
            
            enum dummies { stupid, imbecile, bananas };
            
            union unionTest switch (dummies) {
                case stupid: long stupidio;
                case bananas: short banana;
            };
        };
        <<<EOF>>>

        This is the produced class together with the helper-class:

        <<<unionTest.java>>>
        package test;

        /**
        * test/unionTest.java
        * Generated by the IDL-to-Java compiler (portable), version "3.0"
        * from test.idl
        * Tuesday, April 11, 2000 2:34:25 PM GMT+02:00
        */

        public final class unionTest implements org.omg.CORBA.portable.IDLEntity
        {
          private int ___stupidio;
          private short ___banana;
          private test.dummies __discriminator;
          private boolean __uninitialized = true;

          public unionTest ()
          {
          }

          public test.dummies discriminator ()
          {
            if (__uninitialized)
              throw new org.omg.CORBA.BAD_OPERATION ();
            return __discriminator;
          }

          public int stupidio ()
          {
            if (__uninitialized)
              throw new org.omg.CORBA.BAD_OPERATION ();
            verifystupidio (__discriminator);
            return ___stupidio;
          }

          public void stupidio (int value)
          {
            __discriminator = test.dummies.stupid;
            ___stupidio = value;
            __uninitialized = false;
          }

          private void verifystupidio (test.dummies discriminator)
          {
            if (discriminator != test.dummies.stupid)
              throw new org.omg.CORBA.BAD_OPERATION ();
          }

          public short banana ()
          {
            if (__uninitialized)
              throw new org.omg.CORBA.BAD_OPERATION ();
            verifybanana (__discriminator);
            return ___banana;
          }

          public void banana (short value)
          {
            __discriminator = test.dummies.bananas;
            ___banana = value;
            __uninitialized = false;
          }

          private void verifybanana (test.dummies discriminator)
          {
            if (discriminator != test.dummies.bananas)
              throw new org.omg.CORBA.BAD_OPERATION ();
          }

          public void _default ()
          {
            __discriminator = test.dummies.imbecile;
            __uninitialized = false;
          }

        } // class unionTest
        <<<EOF>>>
        <<<unionTestHelper.java>>>
        package test;


        /**
        * test/unionTestHelper.java
        * Generated by the IDL-to-Java compiler (portable), version "3.0"
        * from test.idl
        * Tuesday, April 11, 2000 2:34:25 PM GMT+02:00
        */

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

          public static void insert (org.omg.CORBA.Any a, test.unionTest 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.unionTest 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.dummiesHelper.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 stupidio
              _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any ();
              test.dummiesHelper.insert (_anyOf_members0, test.dummies.stupid);
              _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc
        (org.omg.CORBA.TCKind.tk_long);
              _members0[0] = new org.omg.CORBA.UnionMember (
                "stupidio",
                _anyOf_members0,
                _tcOf_members0,
                null);

              // Branch for banana
              _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any ();
              test.dummiesHelper.insert (_anyOf_members0, test.dummies.bananas);
              _tcOf_members0 = org.omg.CORBA.ORB.init ().get_primitive_tc
        (org.omg.CORBA.TCKind.tk_short);
              _members0[1] = new org.omg.CORBA.UnionMember (
                "banana",
                _anyOf_members0,
                _tcOf_members0,
                null);
              __typeCode = org.omg.CORBA.ORB.init ().create_union_tc
        (test.unionTestHelper.id (), "unionTest", _disTypeCode0, _members0);
            }
            return __typeCode;
          }

          public static String id ()
          {
            return _id;
          }

          public static test.unionTest read (org.omg.CORBA.portable.InputStream istream)
          {
            test.unionTest value = new test.unionTest ();
            test.dummies _dis0 = null;
            _dis0 = test.dummiesHelper.read (istream);
            switch (_dis0.value ())
            {
              case test.dummies._stupid:
                int _stupidio = (int)0;
                _stupidio = istream.read_long ();
                value.stupidio (_stupidio);
                break;
              case test.dummies._bananas:
                short _banana = (short)0;
                _banana = istream.read_short ();
                value.banana (_banana);
                break;
              default:
                throw new org.omg.CORBA.BAD_OPERATION ();
            }
            return value;
          }

          public static void write (org.omg.CORBA.portable.OutputStream ostream,
        test.unionTest value)
          {
            test.dummiesHelper.write (ostream, value.discriminator ());
            switch (value.discriminator ().value ())
            {
              case test.dummies._stupid:
                ostream.write_long (value.stupidio ());
                break;
              case test.dummies._bananas:
                ostream.write_short (value.banana ());
                break;
              default:
                throw new org.omg.CORBA.BAD_OPERATION ();
            }
          }
        }
        <<<EOF>>>

        In the main-class, there should also exist a method called _default(test.dummies
        dis) that sets any missing disriminator value (and also tests it's valid of
        course).

        In the helper-class, the read method shouldn't throw a BAD_OPERATIOIN
        exception if any missing discriminator value were set. It should rather set it
        to the new discriminator-value using the new _default method as defined above.
        Further, the write method shouldn't either throw a BAD_OPERATION exception if
        any missing discriminator value were set. It should do nothing at all.

        I've tested two other idl-compilers, Orbacus and JacORB. Both of these compilers
        handles this problem more or less in the way described above.
        (Review ID: 103563)
        ======================================================================

              kcavanauorcl Ken Cavanaugh (Inactive)
              kryansunw Kevin Ryan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: