-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Correctly Proxy Statement returned from ResultSet #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The tomcat-jdbc connection pool creates reflective proxies around Connections, Statements, and ResultSets to allow interception of 'close' calls, and consistency of traversing the link back from a child element to its parent - e.g. Statement to Connection. However, the link from ResultSet to Statement does not intercept the call so a non-proxied Statement is returned, as well as the `equals` method not handling the comparison against a non-proxied class correctly. To overcome this, an invocation handler is being created for wrapping a ResultSet returned from any of the relevant Statement methods, with that invocation handler intercepting the `getStatement` call and returning the proxied creating statement. The `equals` checks have also been altered to handle non-proxied instances being passed in to them.
|
Thanks for the PR. All looks reasonable to me. There are a few bits of potential clean-up I noticed both in the patch and the surrounding code. I'll do that after I've merged this PR. |
|
Unfortunately this caused some issues. Where we previously relied on catching |
|
@chrisw-s Do you have a stacktrace that shows the exception you're getting or steps to reproduce the issue? |
|
Just this: This is with JTDS. It works fine in 10.1.26 |
|
Hello, Same is observed on my side with the following strack trace below. With latest tomcat 9.091 is ok while after updating to tomcat 9.092/93 it fails. The problem is that DB initiation is delegated to liquibase and after that fails application initialisation. |
|
Ah, ok. It's an exception being thrown whilst executing the underlying statement, which is happening outside the existing try/catch block that unwraps the exception. I'll raise a Bugzilla record and propose a PR to fix it. |
|
Proposed fix in #744 |
|
You should test the latest version (although I suspect you'll see the same results). Use of proxies rather than wrappers was a design decision for jdbc-pool so it could handle changes in the JDBC API. |
|
Hello proxies could be implemented dynamically using one of ASM libraries; Reflection is very expensive and taking into consideration the huge number of applications using Tomcat this change will generate a lot of CO2. |


The tomcat-jdbc connection pool creates reflective proxies around Connections, Statements, and ResultSets to allow interception of 'close' calls, and consistency of traversing the link back from a child element to its parent - e.g. Statement to Connection. However, the link from ResultSet to Statement does not intercept the call so a non-proxied Statement is returned, as well as the
equalsmethod not handling the comparison against a non-proxied class correctly. To overcome this, an invocation handler is being created for wrapping a ResultSet returned from any of the relevant Statement methods, with that invocation handler intercepting thegetStatementcall and returning the proxied creating statement. Theequalschecks have also been altered to handle non-proxied instances being passed in to them.https://bz.apache.org/bugzilla/show_bug.cgi?id=69206