Add MustCall annotations to JDBC Statement and ResultSet#258
Add MustCall annotations to JDBC Statement and ResultSet#258parameshn wants to merge 2 commits intotypetools:masterfrom
Conversation
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.
📝 WalkthroughWalkthroughThis 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 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
This PR adds
@InheritableMustCall("close")annotations to the JDBC interfacesStatementandResultSet.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.