if (gen_hash_code_) {
indent(out) << "@Override" << endl;
indent(out) << "public int hashCode() {" << endl;
- indent(out) << " return new HashCodeBuilder().append(getSetField().getThriftFieldId()).append((getFieldValue() instanceof TEnum) ? ((TEnum)getFieldValue()).getValue() : getFieldValue()).toHashCode();" << endl;
+ indent(out) << " HashCodeBuilder hcb = new HashCodeBuilder();" << endl;
+ indent(out) << " hcb.append(this.getClass().getName());" << endl;
+ indent(out) << " TFieldIdEnum setField = getSetField();" << endl;
+ indent(out) << " if (setField != null) {" << endl;
+ indent(out) << " hcb.append(setField.getThriftFieldId());" << endl;
+ indent(out) << " Object value = getFieldValue();" << endl;
+ indent(out) << " if (value instanceof TEnum) {" << endl;
+ indent(out) << " hcb.append(((TEnum)getFieldValue()).getValue());" << endl;
+ indent(out) << " } else {" << endl;
+ indent(out) << " hcb.append(value);" << endl;
+ indent(out) << " }" << endl;
+ indent(out) << " }" << endl;
+ indent(out) << " return hcb.toHashCode();" << endl;
indent(out) << "}";
} else {
indent(out) << "/**" << endl;
System.out.println(union);
union = new TestUnion();
+
+ // should not throw an exception here
+ union.hashCode();
+
union.setI32_field(1);
if (union.getI32_field() != 1) {
throw new RuntimeException("didn't get the right value for i32 field!");