On Thu, 29 Oct 2026 21:58:22 GMT, Justin Lu <[email protected]> wrote:

> Within `writeData`, an insert statement is being created for every inserted 
> row. This is redundant because the insertion statement remains the same 
> between inserted rows. (i.e., all columns are included and the values are 
> supplied in `insertNewRow`). What is problematic is that the final insert 
> statement is the only one being closed. Additionally, if the code throws an 
> exception, then this final insert statement does not get closed as well.
> 
> This PR
> - Ensures the statement is created only once (and closed)
> - Ensures that if the code throws an exception, the statement is still closed
> 
> Note that the `finally` block follows similar to behavior to that in 
> `CachedRowSetReader.readData`, where the exception that could occur in the 
> `close` is discarded, if the original code already threw an exception. I did 
> not find it necessary here to retain the closed exception via `addSuppressed` 
> if the original code also threw.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

A more conservative alternative from a behavioral standpoint is simply keep 
creating the insert for every inserted row, but handle it with 
try-with-resources.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/33639#issuecomment-6509386964

Reply via email to