This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new e9a306244d Fix proxying null value result set
e9a306244d is described below

commit e9a306244de4c2339caa1a651af420e9f7dd8298
Author: Huub de Beer <h...@heerdebeer.org>
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 037876e58a..1e642a34e0 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -163,6 +163,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: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to