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

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


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

commit de4d38800ef6978a183d5bc955d7cf85036b52d3
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 ++++++++++++----------
 1 file changed, 16 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();


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to