Skip to content

fix: close commit statements that fail while binding parameters - #300

Open
HuiJun wants to merge 1 commit into
developfrom
fix/commit-dao-statement-leak
Open

HuiJun wants to merge 1 commit into
developfrom
fix/commit-dao-statement-leak

Conversation

@HuiJun

@HuiJun HuiJun commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

CommitDAOImpl created PreparedStatements in two PreparedStatementCreator callbacks and then bound parameters on them. JdbcTemplate only closes a statement the callback returns, so a failure while binding (for example a SQLException from a setter, or a null commit type or timestamp) left the statement open until its connection was closed. SonarCloud reports both as blocker bugs (java:S2095, lines 43 and 119), which is what puts the project's reliability rating at E.

  • save: the bindings are wrapped so the statement is closed before the exception is rethrown. It stays a PreparedStatementCreator because the insert needs the generated id key.
  • findByRefAndLimit: the callback is now a PreparedStatementSetter passed to JdbcTemplate.query(sql, setter, rowMapper), so JdbcTemplate creates and closes the statement itself. The SQL and the bound values are unchanged.

No behaviour change on the success path.

Evidence

  • ./gradlew :rdb:compileJava passes on JDK 17.
  • SonarCloud's analyzer run on the file: the S2095 finding it reports on the old query code is gone with this change. That standalone run does not reproduce the line 43 finding on the old code, and the pull request analysis (0 new issues) only covers changed lines, so the first develop scan after merge is the check that the save finding closes.
  • The rdb module has no unit tests; the Postman collections in CI exercise commit inserts and the by-ref commit queries.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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