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

Inconsistent behavior in isSet mechanism

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.9
    • None
    • Java - Compiler
    • None

    Description

      This issue was mentioned previously in THRIFT-1394. The reporter suggested a fix at that time which would have resolved it. Instead, the fix that was actually applied did not fix the real issue.

      The issue is that code relies on 2 different mechanisms to determine "isSet" state. On the one hand, bit fields are kept for primitivies, on the other "isSet" is determined if the value is null or not. The latter part is incorrect considering one may wish to set a value to null.

      Consider the use case where a Thrift payload is used to send delta's of changed information. A client can determine which fields were "set" by using the "isSet" mechanism. This will not work for String / Struct types due to the inconsistent behavior. Client code will be unable to determine if a String type was: a) just not provided b) or was explicitly set to null.

      Also, it makes methods like set_IsSet and get_IsSet inconsistent. For example:

      user.setName(null);
      user.setNameIsSet(true);
      boolean isNameSet = user.getNameIsSet() //false!

      My proposal to fix is the same as the original proposal in THRIFT-1394:

      We already use a BitSet to track primitive types in Java. The compiler should extend the bit vector to also guard nullable types, to be consistent with C++.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jclawson Jason Clawson
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: