Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
0.13.0
-
None
-
OS: Windows 10 Pro Version 1903 Build 18362.900
Description
Thrift generates a setter for each field like this:
public string WebhooksSecret { get { return _WebhooksSecret; } set { __isset.WebhooksSecret = true; this._WebhooksSecret = value; } }
But if you set the field to null, it will be marked as set in the isset dictionary. Thrift also overrides GetHashCode() like this:
public override int GetHashCode() { int hashcode = 157; unchecked { if(__isset.Url) hashcode = (hashcode * 397) + Url.GetHashCode(); if(__isset.WebhooksSecret) hashcode = (hashcode * 397) + WebhooksSecret.GetHashCode(); if(__isset.Username) hashcode = (hashcode * 397) + Username.GetHashCode(); if(__isset.WebhooksTypes) hashcode = (hashcode * 397) + TCollections.GetHashCode(WebhooksTypes); } return hashcode; }
Note that it doesn't protect against null, where other overrides like ToString() do:
public override string ToString() { //... if (WebhooksSecret != null && __isset.WebhooksSecret) { if(!__first) { sb.Append(", "); } __first = false; sb.Append("WebhooksSecret: "); sb.Append(WebhooksSecret); } //... }
This can result in the field being set to null then throwing a NullReferenceException if a consumer calls GetHashCode().
I've attached a repro in the form of a unit test library. There are instructions to run this in the README of the zip.
Attachments
Attachments
Issue Links
- links to