dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

Add null-safe comparisons in model Equals methods

Open coderabbitai[bot] opened this issue 1 month ago • 0 comments
trafficstars

Description

Several model classes in the SDK contain Equals methods that may throw NullReferenceException when comparing nullable properties. The current pattern uses:

this.Property == input.Property || this.Property.Equals(input.Property)

This will throw if this.Property is null and input.Property is non-null.

Affected Classes

Known affected models:

  • WriteRequestWrites (OnDuplicate property)
  • WriteRequestDeletes (OnMissing property)

All other model classes with nullable properties should be audited for similar issues.

Proposed Fix

Replace unsafe comparisons with null-safe alternatives:

object.Equals(this.Property, input.Property)

Or:

this.Property == input.Property || (this.Property \!= null && this.Property.Equals(input.Property))

Context

Identified during review of PR #120.

Referenced by: @rhamzeh

  • PR: https://github.com/openfga/dotnet-sdk/pull/120
  • Discussion: https://github.com/openfga/dotnet-sdk/pull/120#discussion_r2380256985

coderabbitai[bot] avatar Sep 30 '25 05:09 coderabbitai[bot]