openfga / openfga/dotnet-sdk

Add null-safe comparisons in model Equals methods

Open
#124 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
85
Forks
18
Avg merge
23h 28m
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the Equals methods in WriteRequestWrites and WriteRequestDeletes first, focusing on OnDuplicate and OnMissing, then audit other model classes for the same nullable-property pattern. Confirm that comparisons where either property is null no longer throw a NullReferenceException and that existing equality behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
authorization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.