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

Generated javascript code doesn't properly write optional falsy values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 0.8
    • None
    • JavaScript - Compiler

    Description

      The generated javascript code doesn't write out "falsy" values, which seems to be incorrect behavior for optional fields. Falsy values such as the empty string or the number 0 should be explicitly set, so that they are read out on the other end.

      The current behavior results in serialized data where fields are left unset, when really they should have been set to 0 (or the empty string).

      For example, the generated code for a .write looks like this:

      DataRunFilter.prototype.write = function(output) {
        output.writeStructBegin('DataRunFilter');
        if (this.runType) {
          output.writeFieldBegin('runType', Thrift.Type.I32, 2);
          output.writeI32(this.runType);
          output.writeFieldEnd();
        }
        output.writeFieldStop();
        output.writeStructEnd();
        return;
      };
      
      

      If runType (an enum) happens to be 0, the field won't be set at all and readers of the data will think it wasn't specified.

      Since the constructor explicitly nulls out all fields, it should be perfectly okay to instead test for null explicitly (e.g. " if (this.runType === null) {" above).

      Attachments

        Issue Links

          Activity

            People

              henrique Henrique Mendonca
              dtay Darin Tay
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: