Skip to content

demo(12-missing-null-guard): 12 — New public method takes a nullable string with no guard#161

Open
EricCogen wants to merge 1 commit intomainfrom
demo/12-missing-null-guard
Open

demo(12-missing-null-guard): 12 — New public method takes a nullable string with no guard#161
EricCogen wants to merge 1 commit intomainfrom
demo/12-missing-null-guard

Conversation

@EricCogen
Copy link
Copy Markdown
Owner

12 — New public method takes a nullable string with no guard

Expected verdict: ❌ Fails — GauntletCI should fire GCI0006 (edge case handling).

What changed

A new CustomerNoteFormatter exposes a public method that accepts a
nullable string? and immediately dereferences it without any
runtime check:

public sealed class CustomerNoteFormatter
{
    public string Format(string? note)
    {
        return note!.Trim().ToUpperInvariant();
    }
}

The compiler is silenced with ! (so the build still succeeds), but
the runtime behaviour is unchanged — calling Format(null) throws
NullReferenceException deep inside Trim.

Why this is risky

  • The signature openly accepts null (string?), so callers are
    entitled to pass it. Nothing in the body translates that into a
    documented ArgumentNullException or a sensible default.
  • NullReferenceException thrown from a transitive callee is one of
    the worst error shapes to debug: the stack trace points at Trim,
    not at the caller that handed in null.
  • A single ArgumentNullException.ThrowIfNull(note) (or a ??
    fallback) makes the contract explicit.

What GauntletCI catches

GCI0006 Edge Case Handling — a public method whose signature
declares a nullable reference parameter (string? / object?) and
whose first few lines contain no null check, throw, or
ArgumentNullException guard.

…string with no guard

See scenarios/12-missing-null-guard/README.md for the expected verdict.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GauntletCI found issues in this PR. See inline comments for details.


public sealed class CustomerNoteFormatter
{
public string Format(string? note)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCI0006 — Edge Case Handling

New method parameter(s) added without apparent null/range validation in src/OrderService/Pricing/CustomerNoteFormatter.cs

Evidence:

Line 5: public string Format(string? note)

⚠️ Why it matters: Unvalidated parameters can lead to NullReferenceException or incorrect behaviour deeper in the call stack.

💡 Suggested action: Add ArgumentNullException.ThrowIfNull() or similar guard at the top of the method.

Confidence: Medium | Severity: Warn

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0613fdb15

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

{
public string Format(string? note)
{
return note!.Trim().ToUpperInvariant();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Guard nullable note before calling Trim

Format declares note as nullable (string?) but immediately dereferences it via note! and calls Trim, so Format(null) will throw a NullReferenceException from inside Trim instead of failing fast with a clear argument validation error. Since this is a public method, callers are allowed by the signature to pass null; add an explicit null guard (or fallback behavior) at the method boundary.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant