Skip to content

Fix BZ 69236 - reset JDBC interceptors in declaration order - #1101

Merged
markt-asf merged 1 commit into
apache:mainfrom
arturobernalg:bz-69236-interceptor-reset-order
Oct 23, 2026
Merged

markt-asf merged 1 commit into
apache:mainfrom
arturobernalg:bz-69236-interceptor-reset-order

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

Fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=69236

When a pooled connection was created, the interceptor chain was built from the last interceptor to the first and each interceptor was reset as it was added, so reset() was called in reverse order. For a connection taken from the pool the chain was reset from the first interceptor to the last.

This change builds the chain first and then resets it in declaration order in both cases.

InterceptorResetOrderTest records the reset() calls of two interceptors for a new and for a reused connection. Without the change the new connection fails with expected:<[first, second]> but was:<[second, first]>. With the change both pass. The other jdbc-pool test classes give the same results with and without the change.

//reset the chain in the order the interceptors are declared, for new and cached handlers alike
JdbcInterceptor next = handler;
while (next!=null) {
next.reset(this, con);

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.

You need to catch exceptions that happen here and wrap them in an SQLException

When a pooled connection was created, the interceptor chain was built
from the last interceptor to the first and each interceptor was reset as
it was added, so reset() was called in reverse order. For a connection
taken from the pool the chain was reset from the first interceptor to
the last. Build the chain first and then reset it in declaration order
in both cases.
@arturobernalg
arturobernalg force-pushed the bz-69236-interceptor-reset-order branch from a954b4c to 4025006 Compare October 23, 2026 17:14
@arturobernalg

Copy link
Copy Markdown
Member Author

@markt-asf Done. Exceptions thrown by reset() are now wrapped in an SQLException, for new and for reused connections, and there is a test for it. Could you have another look?

@markt-asf
markt-asf merged commit cbdf2f2 into apache:main Oct 23, 2026
10 checks passed
@rmaucher

Copy link
Copy Markdown
Contributor

This clearly should not have been merged as is. I'll rework it (the test at least).

@markt-asf

Copy link
Copy Markdown
Contributor

I already have it locally. Just need to tidy up a few things and I'll push it.

@rmaucher

Copy link
Copy Markdown
Contributor

Thanks ! I was surprised this went in just like that, I guess it's easier for immediate back porting.

@markt-asf

Copy link
Copy Markdown
Contributor

I'm trying to keep on top of user provided PRs so contributors don't feel ignored. Give me two minutes and I'll have the checkstyle issues fixed too.

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.

3 participants