You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jeff DeCew (JIRA)" <ji...@apache.org> on 2010/07/22 00:22:50 UTC

[jira] Updated: (THRIFT-735) Required field checking is broken when the field type is a Union struct

     [ https://issues.apache.org/jira/browse/THRIFT-735?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jeff DeCew updated THRIFT-735:
------------------------------

    Attachment: unknown_enum_tests.zip

I did some tests, and thought I would follow up with how unknown values for enums are treated on when reading (in Java with 0.3.0-rc4).

Bottom line: unknown enum values are interpreted as null when being deserialized, and all other code operates as you might expect it would when reading a 'null' off the wire.
Result: Objects successfully deserialize that cannot be reserailized

* In Collections
** All unknown enum values in a set will be replaced with a single 'null' entry in the set.  Size of the set may change.  
** All unknown enum keys in a map will be replaced with a single 'null' key in the map.  Size of the map may change.  The value for that key will be the last value for any unknown enum key in that map that was sent over the wire.
** All unknown enum values in a list will be replaced with 'null', but the ordering and size of the list will not change.
** All unknown enum values in a map will be replaced with 'null', but the existence of the key will be unaltered.  Size of the map won't change.  

* In Structs
** An unknown value for a standard (optional) enum field will result in a null (unset) field (even overwriting a default value)
** An unknown value for a required enum field will result in a validation failure during the read (TProtocolException)

* In Service Calls
** An unknown (to client) enum value as a return value results in a TApplicationException (like "getEnum failed: unknown result") on the client
** An unknown (to server) enum value as a standard (optional) method argument still invokes the method, but with the value of 'null' for the enum
** An unknown (to server) enum value as a required method argument results in a TApplicationException (like "Required field 'value' is unset! Struct:fromEnumRequired_args(value:null)") on the client

Based on what I gleaned from the discussion and some peeking at the code, it should be quite possible (if there were consensus to do so) to make sure Unions behave the same way.

> Required field checking is broken when the field type is a Union struct
> -----------------------------------------------------------------------
>
>                 Key: THRIFT-735
>                 URL: https://issues.apache.org/jira/browse/THRIFT-735
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java), Library (Java)
>    Affects Versions: 0.2
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.4
>
>         Attachments: thrift-735-v2.patch, thrift-735.patch, unknown_enum_tests.zip
>
>
> The validate() method on generated structs verifies that required fields are set after validation. However, if the type of the field is a Union struct, then just checking that the field isn't null is not a valid check. The value may be a non-null union, but have an unset field. (We encountered this when deserializing a type that had a union for a field, and the union's set value was an enum value that had been removed from the definition, making it a skip.)
> In order to perform the correct validation, if the value is a Union, then we must also check that the set field and value are non-null.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.