This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 9627771c89 Fix proxying null value result set
9627771c89 is described below
commit 9627771c896fbab2528dbeaeadb5b4ff9260c91c
Author: Huub de Beer <[email protected]>
AuthorDate: Fri Aug 16 16:50:56 2024 +0200
Fix proxying null value result set
When invoking a method on a proxied statement returns `null`, that
statement's proxy should also return `null`.
In particular, `Statement#getResultSet` should not return a
`ResultSetProxy` when the proxied statement returns `null`. Otherwise,
that `ResultSet` proxy has a `null` delegate and calling methods on the
proxy that lead to calling methods on the delegate could result in a
`SqlException` with message "ResultSet closed."
Only prevent creation of `ResultSetProxy` for `null` return values when
invoking a method on `Statement`. In particular, don't do an early
return for `void` methods like `#close` because there's cleanup code for
that `close` method.
---
.../apache/tomcat/jdbc/pool/StatementFacade.java | 29 ++++++++++++----------
webapps/docs/changelog.xml | 6 +++++
2 files changed, 22 insertions(+), 13 deletions(-)
diff --git
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
index ea32d619c5..988dcf9486 100644
---
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
+++
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
@@ -119,21 +119,24 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
Object result;
try {
- if (compare(GET_RESULTSET, method)) {
- return getConstructor(RESULTSET_IDX, ResultSet.class)
- .newInstance(new
ResultSetProxy(method.invoke(delegate, args), proxy));
- }
- if (compare(GET_GENERATED_KEYS, method)) {
- return getConstructor(RESULTSET_IDX, ResultSet.class)
- .newInstance(new
ResultSetProxy(method.invoke(delegate, args), proxy));
- }
- if (compare(EXECUTE_QUERY, method)) {
- return getConstructor(RESULTSET_IDX, ResultSet.class)
- .newInstance(new
ResultSetProxy(method.invoke(delegate, args), proxy));
- }
-
// invoke next
result = method.invoke(delegate, args);
+
+ // Don't create a ResultSet proxy for null
+ if (result != null) {
+ if (compare(GET_RESULTSET, method)) {
+ return getConstructor(RESULTSET_IDX, ResultSet.class)
+ .newInstance(new ResultSetProxy(result,
proxy));
+ }
+ if (compare(GET_GENERATED_KEYS, method)) {
+ return getConstructor(RESULTSET_IDX, ResultSet.class)
+ .newInstance(new ResultSetProxy(result,
proxy));
+ }
+ if (compare(EXECUTE_QUERY, method)) {
+ return getConstructor(RESULTSET_IDX, ResultSet.class)
+ .newInstance(new ResultSetProxy(result,
proxy));
+ }
+ }
} catch (Throwable t) {
if (t instanceof InvocationTargetException && t.getCause() !=
null) {
throw t.getCause();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 9af06cc60e..0683832046 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -160,6 +160,12 @@
the application seeing the original <code>SQLException</code>. Fixed
by pull request <pr>744</pr> provided by Michael Clarke. (markt)
</fix>
+ <fix>
+ <bug>69279</bug>: Correct a regression in the fix for <bug>69206</bug>
+ that meant that methods that previously returned a <code>null</code>
+ <code>ResultSet</code> were returning a proxy with a null delegate.
+ Fixed by pull request <pr>745</pr> provided by Huub de Beer. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Other">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]