[ https://issues.apache.org/jira/browse/THRIFT-735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12846056#action_12846056 ]
David Reiss commented on THRIFT-735: ------------------------------------ >> Basically, I think the decision of whether an enum or union is valid should >> only affect the enum or union itself. It should not leak up into the >> containing context. > I'm essentially saying the inverse of this. The context is what defines > whether it's OK for the field to be absent or not. But it's not absent. It's present and valid. The code just isn't equipped to understand its value. >> I think it's definitely important to distinguish between "unset" and "set, >> but I couldn't understand it" > We don't do this anywhere else, at least in Java and Ruby. If it was "set" > but got skipped, then it's just as if it was unset. The only time you would skip a set field is if the type were wrong. That's an error in the structure of the outer struct, so it makes sense that it affects the outer struct. In the case of the enum or union, its an error (not even a real error) in the internal structure of the enum/union, so I don't think that should bubble up into the outer struct. If you had something like {noformat} union U1 { whatever } union U2 { 1: U1 u1 } union U3 { 1: U2 u2 } union U4 { 1: U4 u3 } struct S { 1: U4 u4 } {noformat} and the U1 contained an unrecognized value, would you expect the top-level S to show u4 as unset? > 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.