You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by hernan <he...@defy.org> on 2022/05/27 04:35:39 UTC

Possible Thrift compiler bug...

Hello, hope this is an okay place to reach out. I ran into an odd issue with the Thrift compiler today that I think may be a bug:

https://github.com/nanreh/thrift_struct_refs

As the README says, I have two Thrift structs, Parent and Child. Parent has a field of type Child.

When I define them in the order Child > Parent, I get the code (Java) I expect.
When I define them in the order Parent > Child, I get different Java code which looks incorrect.

Fortunately, the diff is rather small and I only noticed it recently after years of using Thrift rather heavily because I need the metadata in the generated code for a new project I'm working on. I'm not sure how to feel about the missing `validate()` call in the "bad" case here but I'm guessing that might be problematic under the right circumstances.

This issue can be worked around when you have one struct refer to another like this example (by ordering them carefully). But it's impossible to work around when you have two structs that refer to each other (a situation I encounter regularly).

The Makefile in this sample repo is a simple test. The `out` folder has the results, including the diff.

I'm happy to help address this issue. But I would need some time and hand holding to get up to speed on the compiler's implementation and what a possible fix would look like.

Thanks.
hernan

Re: Possible Thrift compiler bug...

Posted by hernan <he...@defy.org>.
I found the JIRA and an issue reporting this bug a while back. It's still open. Adding a link for future searchers:
https://issues.apache.org/jira/browse/THRIFT-4086
Thanks.
hernan

On Thu, May 26, 2022, at 9:35 PM, hernan wrote:
> Hello, hope this is an okay place to reach out. I ran into an odd issue with the Thrift compiler today that I think may be a bug:
> 
> https://github.com/nanreh/thrift_struct_refs
> 
> As the README says, I have two Thrift structs, Parent and Child. Parent has a field of type Child.
> 
> When I define them in the order Child > Parent, I get the code (Java) I expect.
> When I define them in the order Parent > Child, I get different Java code which looks incorrect.
> 
> Fortunately, the diff is rather small and I only noticed it recently after years of using Thrift rather heavily because I need the metadata in the generated code for a new project I'm working on. I'm not sure how to feel about the missing `validate()` call in the "bad" case here but I'm guessing that might be problematic under the right circumstances.
> 
> This issue can be worked around when you have one struct refer to another like this example (by ordering them carefully). But it's impossible to work around when you have two structs that refer to each other (a situation I encounter regularly).
> 
> The Makefile in this sample repo is a simple test. The `out` folder has the results, including the diff.
> 
> I'm happy to help address this issue. But I would need some time and hand holding to get up to speed on the compiler's implementation and what a possible fix would look like.
> 
> Thanks.
> hernan
>