Team_RPCtester created THRIFT-5806:
--------------------------------------

             Summary: Inconsistent Handling of Unset Union Fields in Structs 
Across Languages
                 Key: THRIFT-5806
                 URL: https://issues.apache.org/jira/browse/THRIFT-5806
             Project: Thrift
          Issue Type: Bug
            Reporter: Team_RPCtester


Hi,

We discover an inconsistent behavior regarding unset values in unions within 
structs. Specifically, when a union field in a struct is not explicitly set, Go 
will report an error. In contrast, other languages pass a null value, allowing 
for smooth transmission. This inconsistency can be illustrated with the 
following example: 

Thrift Definition:

 
{code:java}
namespace go commonResource
union Union_1 {
 1: bool uitem_1;
 2: i16 uitem_2=1;
}
struct StructClass_0 {
 1: required bool f_1=1,
 2: Union_1 f_2
} 
service DataService {
   StructClass_0 Method_1(1: StructClass_0 agr_method_1)
}
{code}
The Go client side, when it passes the agr_method_1_0 to method_1, it will 
prompt “panic: runtime error: invalid memory address or nil pointer 
dereference”. 
{code:java}
 agr_method_1_0 := commonResource.NewStructClass_0()
   fmt.Println("Method_1 sends ", agr_method_1_0, " end")
   method_1_re_agr_method_1_0, err := 
dataserviceclient.Method_1(context.Background(),agr_method_1_0)
{code}
 

The Node.js client does not check whether the union field is set or not and 
successfully passes the arg_Method_1 to the server.

 
{code:java}
const arg_Method_1  = new StructClass_0();
console.log("Method_1 sends ", arg_Method_1, " end");
// arg_Method_1   {"f_1":true,"f_2":null}
try {
 const res_Method_1 = await client.Method_1(arg_Method_1);
 console.log("Method_1 receives ", JSON.stringify(res_Method_1, replacer), " 
back");
} catch (error) {
 console.log("Method_1 receives error ", error, " back");
}
{code}
 

The Python client behaves similarly to the Node.js client, not checking whether 
the union field is set and successfully passing the arg_Method_1 to the server.

 
{code:java}
agr_method_1 = StructClass_0()
print("Method_1 sends ",agr_method_1, " end")
try:
   method_1_re_agr_method_1 = client.Method_1(agr_method_1)
   print("Method_1 receives ",method_1_re_agr_method_1," back")
except Exception as ex:
   print(f"Method_1 receives error {ex} back")
{code}
 

Can you help check this issue? Thank you.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to