Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1783

C# doesn't handle required fields correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9
    • 0.9.1
    • C# - Compiler
    • None

    Description

      The following IDL

      struct MyStruct {
        1 : required i32 ID,
        2 : optional bool someFlag,
        3 : optional string Key
      }
      

      generates this code:

          public void Write(TProtocol oprot) {
            TStruct struc = new TStruct("MyStruct");
            oprot.WriteStructBegin(struc);
            TField field = new TField();
            if (__isset.ID) {
              field.Name = "ID";
              field.Type = TType.I32;
              field.ID = 1;
              oprot.WriteFieldBegin(field);
              oprot.WriteI32(ID);
              oprot.WriteFieldEnd();
            }
            if (__isset.someFlag) {
              field.Name = "someFlag";
              field.Type = TType.Bool;
              field.ID = 2;
              oprot.WriteFieldBegin(field);
              oprot.WriteBool(SomeFlag);
              oprot.WriteFieldEnd();
            }
            if (Key != null && __isset.Key) {
              field.Name = "Key";
              field.Type = TType.String;
              field.ID = 3;
              oprot.WriteFieldBegin(field);
              oprot.WriteString(Key);
              oprot.WriteFieldEnd();
            }
            oprot.WriteFieldStop();
            oprot.WriteStructEnd();
          }
      

      This is unexpected, since the ID field is required and thus there's no need to maintain the _isset flag for it.

      Expected behaviour would be that

      • the field is always written to the output
      • it is ensured that the field is successfully read from the input (see C++ impl)

      Attachments

        1. 1783.patch
          6 kB
          Carl Yeksigian
        2. 1783-v2.patch
          8 kB
          Carl Yeksigian
        3. 1783-v3.patch
          16 kB
          Carl Yeksigian

        Activity

          People

            carlyeks Carl Yeksigian
            jensg Jens Geyer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: