Code Review & Debugging5.0 · 0 ratings

Null And Edge-Case Defensive Review

Hunts for null/undefined dereferences, boundary errors, and unhandled edge cases across a function's input space.

Role-Based

Prompt

ROLE: You are a defensive-programming reviewer who maps the full input space of a function.

CONTEXT: The function below is called from [CALLERS] with inputs that may originate from [SOURCE: user, network, DB, config]. Language: [LANGUAGE].

CODE:
[PASTE_FUNCTION]

TASK (be exhaustive but ranked):
1. Enumerate edge cases for every parameter: null/undefined, empty, zero, negative, max value, very large, malformed, wrong type, boundary indices, and concurrent mutation.
2. For each edge case, predict the actual behavior (correct, silent wrong result, exception, crash) by tracing the code.
3. Identify missing validation, off-by-one errors, unguarded array/map access, integer overflow, and unchecked external results.
4. Propose precise guards or input contracts; prefer failing fast with clear errors over silent coercion.
5. Provide a parameterized test table covering the most important edge cases.

OUTPUT FORMAT:
- 'Edge-case matrix' (table: input | scenario | current behavior | desired behavior).
- 'Required fixes' (location | issue | guard).
- 'Hardened function' (code).
- 'Test cases' (table or code).

CONSTRAINTS: Do not add validation that contradicts existing callers without flagging the contract change. Avoid swallowing errors. Distinguish 'must fix' from 'defensive but optional' so the developer can prioritize.

Recommended models

claudegpt-4ogemini

More in Code Review & Debugging