Skip to content

Guard against null ResultSet in EnvironmentRepositoryImpl#134

Merged
dmccoystephenson merged 1 commit into
mainfrom
fix/environment-repository-null-guard
Jun 13, 2026
Merged

Guard against null ResultSet in EnvironmentRepositoryImpl#134
dmccoystephenson merged 1 commit into
mainfrom
fix/environment-repository-null-guard

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • Adds the missing if (rs == null) guard to the seven query methods of EnvironmentRepositoryImpl (findAll, findById, findByName, findByEntityId, findEntityIdsByEnvironmentId, findLocationIdsByEnvironmentId, findGridIdsByEnvironmentId), matching the existing pattern in GridRepositoryImpl, EntityRepositoryImpl, and LocationRepositoryImpl.
  • Before this change those methods called rs.next() directly, so a null ResultSet — the value DbInteractions.query(...) returns on failure — produced a NullPointerException instead of an empty result, diverging from every sibling repository.
  • Each guard logs with the method's existing message prefix ("... : ResultSet is null") and returns the empty result (Optional.empty() / empty list), exactly as the siblings do.

Tests

  • Adds the seven ...ReturnsEmptyWhenResultSetIsNull cases to EnvironmentRepositoryImplTest. These are the regression guard: without the new rs == null check each one throws NullPointerException at rs.next() and fails.
  • Removes the now-obsolete class-level comment that documented the omission.

Test plan

  • ./mvnw test -Dtest=EnvironmentRepositoryImplTest — 45/45 pass (JDK 21)
  • ./mvnw test (full suite) — 213/213 pass, no regressions
  • Python client — not applicable (no src/main/python change)

Notes

  • The write/delegator methods (save, deleteById, updateName, delete*) are unchanged: they delegate to DbInteractions.update, which returns a boolean and has no ResultSet to guard.

Closes #132

🤖 Generated with Claude Code

Add the missing null-ResultSet guard to the seven query methods of
EnvironmentRepositoryImpl (findAll, findById, findByName, findByEntityId,
findEntityIdsByEnvironmentId, findLocationIdsByEnvironmentId,
findGridIdsByEnvironmentId), matching the pattern already used by
GridRepositoryImpl, EntityRepositoryImpl, and LocationRepositoryImpl.

Previously these methods called rs.next() directly, so a null ResultSet
(the signal DbInteractions.query returns on failure) caused a
NullPointerException instead of an empty result. They now log and return
an empty result, consistent with the sibling repositories.

Adds the corresponding ...ReturnsEmptyWhenResultSetIsNull tests (which
fail with NPE without the guard) and removes the now-obsolete class comment
documenting the omission.

Closes #132

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@dmccoystephenson dmccoystephenson left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Self-review rubric (adversarial; anchored on green CI run 27466954846 + a direct regression demonstration):

  • Scope: PASS — only two files, both required for #132: EnvironmentRepositoryImpl.java (the guards) and its test. No unrelated edits.
  • Tests-fix: PASS — demonstrated, not asserted. Reverting just the production file to main and re-running the new null tests errors with NullPointerException: Cannot invoke "ResultSet.next()" because "rs" is null on all sampled cases; with the guard they pass. Seven ...ReturnsEmptyWhenResultSetIsNull tests, one per guarded method.
  • Tests-new: N/A — no new public methods; guards added to existing ones.
  • Sibling structure: PASS — each guard mirrors GridRepositoryImpl exactly: if (rs == null) { log.error("<method prefix>: ResultSet is null"); return <empty>; }, reusing each method's existing log-message prefix.
  • Sibling renames: N/A — no identifiers renamed.
  • Docs: N/A — the change is internal error-handling (null → empty result); no API/DTO/endpoint contract or Phase 7 doc source-of-truth row is affected.
  • Issue resolution: PASS — #132's named surface (the seven query methods lacking the guard) is fully addressed; grep confirms 7 guards + 7 null tests.
  • CI: PASS — build green on PR head.
  • DTO boundary / Spec alignment: N/A — no controller or endpoint change.
  • Java/Python parallelism: PASS — repository layer is Java-only; the Python client has no repository mirror.
  • Override correctness: PASS — git diff shows zero @Override lines added or changed in production.

Observation (not a FAIL, pre-existing & repo-wide): treating a null ResultSet (a failed query) as an empty result silently hides DB failures from callers. That is the established convention across all four repositories, so this PR conforms rather than introduces it; changing the convention is out of scope.

Summary: ready to merge — the fix is small, matches the sibling pattern, and the regression is proven by the new tests failing without the guard.

@dmccoystephenson dmccoystephenson merged commit 8a0ae9f into main Jun 13, 2026
1 check passed
@dmccoystephenson dmccoystephenson deleted the fix/environment-repository-null-guard branch June 13, 2026 12:38
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.

EnvironmentRepositoryImpl lacks null-ResultSet guard present in sibling repositories

1 participant