[ https://issues.apache.org/jira/browse/THRIFT-735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12845716#action_12845716 ]
David Reiss commented on THRIFT-735: ------------------------------------ > I don't think that using a type in a required field limits the flexibility of > that type. It certainly limits the flexibility of the struct that uses that > type - but that's fundamentally intentional. I disagree. Compare... {noformat} struct Contained { whatever } struct Outer { 1: required Contained contents; } {noformat} fields can be added or removed from Contained with no problems. If the recipient gets an Outer with a Contained that has no intelligible fields, it's no problem. {noformat} union Contained { whatever } struct Outer { 1: required Contained contents; } {noformat} Now, if you add something to Contained, suddenly Outers can fail validation. I definitely sympathize with the need no be able to easily check a deeply-nested structure, but I don't think "require all unions to be non-empty" should be the only option. What do you think of a parameter to validate to control whether an empty union should be considered a failure. It would apply to unions in all contexts, not just required fields. > 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.3 > > Attachments: thrift-735.patch > > > 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.