[
https://issues.apache.org/jira/browse/THRIFT-735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12845719#action_12845719
]
Bryan Duxbury commented on THRIFT-735:
--------------------------------------
I think the example you've laid out perfectly describes my desired behavior.
You have to think of a union as a struct with exactly one required field that
can take on many different values/types/names. Cast that way, it would be as
though your Contained struct had a required field with an unset value for any
reason. I think we can all agree in that case it should fail validation.
As long as we continue to define a valid union as containing exactly one field,
I don't see any other options that make it behave consistently. We could
discuss making unions contain zero or one field, but as previously mentioned,
that essentially puts a literal null into the thrift vocabulary, which I'm
against. I'm also not crazy about a parameter to change this semantic, since
it's probably a more context-specific thing than a global thing.
I do think that existing required/optional semantics apply just fine to these
situations and give the schema designer the flexibility to say what they need.
If you think about how we treat enums in the same kind of situation, then the
behavior would be exactly the same.
> 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.