[
https://issues.apache.org/jira/browse/THRIFT-5056?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18112796#comment-18112796
]
Sylwester Lachiewicz edited comment on THRIFT-5056 at 9/8/26 1:44 PM:
----------------------------------------------------------------------
Still reproduces. Structs go through {{generate_netstd_struct_hashcode}}
([t_netstd_generator.cc:2247|https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_netstd_generator.cc#L2247]),
which seeds 157 and folds in only the fields that are set, each inside a null
check: {{hashcode = (hashcode * 397) + <field>.GetHashCode()}}. Field identity
never enters the hash, so for the {{Simple}} example above {{A = true}} and {{B
= true}} both yield 157 * 397 + 1 and the assertion fails. The {{Isset}} switch
is the union hash code, not the struct one. Reopening.
was (Author: slachiewicz):
Generated GetHashCode hashes the instance fields via an Isset switch
([compiler/cpp/src/thrift/generate/t_netstd_generator.cc|https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_netstd_generator.cc]
lines 1948-1962) instead of the old constant-ish implementation. Resolving as
Fixed.
> Netstd Generated GetHashCode() returns same value in many common cases
> ----------------------------------------------------------------------
>
> Key: THRIFT-5056
> URL: https://issues.apache.org/jira/browse/THRIFT-5056
> Project: Thrift
> Issue Type: Bug
> Components: netstd - Compiler
> Affects Versions: 0.13.0
> Reporter: Emi
> Priority: Major
>
> Simple Thrift example which breaks the generated GetHashCode() implementation:
> {code:java}
> struct Simple
> {
> 1: optional bool A;
> 2: optional bool B;
> }
> {code}
> The generated GetHashCode() implementation using netstd generator returns the
> same value if one only of the A,B fields is set:
> {code:java}
> Assert.NotEqual(new Simple{A = true}.GetHashCode(), new Simple{B =
> true}.GetHashCode());
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)