Skip to content

Add MustCall annotations to JDBC Statement and ResultSet#258

Open
parameshn wants to merge 2 commits intotypetools:masterfrom
parameshn:mustcall-sql-close
Open

Add MustCall annotations to JDBC Statement and ResultSet#258
parameshn wants to merge 2 commits intotypetools:masterfrom
parameshn:mustcall-sql-close

Conversation

@parameshn
Copy link
Copy Markdown

This PR adds @InheritableMustCall("close") annotations to the JDBC interfaces Statement and ResultSet.

These types represent database-backed resources whose lifecycle already requires callers to invoke close(). Adding MustCall annotations enables the MustCall Checker to detect resource leaks in common JDBC usage patterns while refining the existing AutoCloseable contract.

This PR contributes to typetools/checker-framework#6354
by annotating additional JDK subtypes of AutoCloseable that own external resources.

Related tests are provided in typetools/checker-framework#7480
.

This PR intentionally includes only JDBC types. Audio/MIDI annotations from the original PR are being handled separately because their lifecycle semantics are more complex.

All ResultSet and RowSet implementations, both connected and disconnected, should be explicitly closed. Connected types release live database resources such as connections and cursors, while disconnected types still hold internal resources that should not be left to garbage collection, especially in long running applications.
Statement owns independent JDBC resources and must be explicitly closed. Relying on Connection.close() is unsafe (e.g., with connection pooling) and not clearly guaranteed by the JDBC specification. Annotating Statement enables sound resource-leak detection and reflects recommended JDBC usage.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 15, 2026

📝 Walkthrough

Walkthrough

This change adds must-call checker semantics to the ResultSet and Statement interfaces in the java.sql module. The ResultSet interface imports InheritableMustCall and updates its @AnnotatedFor annotation to include both "nullness" and "mustcall" checkers, while adding @InheritableMustCall("close"). The Statement interface adds both InheritableMustCall and AnnotatedFor imports, and applies @AnnotatedFor({"mustcall"}) and @InheritableMustCall("close") annotations. These changes enforce that implementers of these interfaces must ensure their close() method is called.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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