[libpostgresql-jdbc-java] 01/07: The Statement and Connection proxies used for connection pooling code relied on the underlying real connection and statement code for equals and hashcode support. When the proxies are closed we discard the references to the real objects, so we can't rely on them for this support because we'll get a NullPointerException.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_1_414
in repository libpostgresql-jdbc-java.

commit 88bfe8082ee7c79342bce214612cd1da3d0f57e0
Author: Kris Jurka <books at ejurka.com>
Date:   Wed Jan 7 05:29:18 2009 +0000

    The Statement and Connection proxies used for connection pooling
    code relied on the underlying real connection and statement code
    for equals and hashcode support.  When the proxies are closed we
    discard the references to the real objects, so we can't rely on
    them for this support because we'll get a NullPointerException.
    
    As reported by Radu Buzila.
---
 org/postgresql/ds/common/PooledConnectionImpl.java | 32 +++--------------
 .../test/jdbc2/optional/PoolingDataSourceTest.java | 42 ++++++++++++++++++++--
 2 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/org/postgresql/ds/common/PooledConnectionImpl.java b/org/postgresql/ds/common/PooledConnectionImpl.java
index aced803..3060c98 100644
--- a/org/postgresql/ds/common/PooledConnectionImpl.java
+++ b/org/postgresql/ds/common/PooledConnectionImpl.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/ds/common/PooledConnectionImpl.java,v 1.10 2005/01/17 10:59:04 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/ds/common/PooledConnectionImpl.java,v 1.10.4.2 2007/11/14 22:03:57 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -275,22 +275,11 @@ public class PooledConnectionImpl implements PooledConnection
                 }
                 if (method.getName().equals("hashCode"))
                 {
-                    return new Integer(con.hashCode());
+                    return System.identityHashCode(proxy);
                 }
                 if (method.getName().equals("equals"))
                 {
-                    if (args[0] == null)
-                    {
-                        return Boolean.FALSE;
-                    }
-                    try
-                    {
-                        return Proxy.isProxyClass(args[0].getClass()) && ((ConnectionHandler) Proxy.getInvocationHandler(args[0])).con == con ? Boolean.TRUE : Boolean.FALSE;
-                    }
-                    catch (ClassCastException e)
-                    {
-                        return Boolean.FALSE;
-                    }
+                    return proxy == args[0];
                 }
                 try
                 {
@@ -427,22 +416,11 @@ public class PooledConnectionImpl implements PooledConnection
                 }
                 if (method.getName().equals("hashCode"))
                 {
-                    return new Integer(st.hashCode());
+                    return System.identityHashCode(proxy);
                 }
                 if (method.getName().equals("equals"))
                 {
-                    if (args[0] == null)
-                    {
-                        return Boolean.FALSE;
-                    }
-                    try
-                    {
-                        return Proxy.isProxyClass(args[0].getClass()) && ((StatementHandler) Proxy.getInvocationHandler(args[0])).st == st ? Boolean.TRUE : Boolean.FALSE;
-                    }
-                    catch (ClassCastException e)
-                    {
-                        return Boolean.FALSE;
-                    }
+                    return proxy == args[0];
                 }
                 return method.invoke(st, args);
             }
diff --git a/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java b/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java
index 384f406..60ba5e4 100644
--- a/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java
+++ b/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java
@@ -3,14 +3,13 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java,v 1.6 2004/11/09 08:55:49 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java,v 1.7 2005/01/11 08:25:48 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
 package org.postgresql.test.jdbc2.optional;
 
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.*;
 import org.postgresql.test.TestUtil;
 import org.postgresql.jdbc2.optional.PoolingDataSource;
 import org.postgresql.ds.common.BaseDataSource;
@@ -127,4 +126,41 @@ public class PoolingDataSourceTest extends BaseDataSourceTest
         stmt.close();
         con.close();
     }
+
+    public void testConnectionObjectMethods() throws SQLException
+    {
+        con = getDataSourceConnection();
+
+        Connection conRef = con;
+        assertEquals(con, conRef);
+
+        int hc1 = con.hashCode();
+        con.close();
+        int hc2 = con.hashCode();
+
+        assertEquals(con, conRef);
+        assertEquals(hc1, hc2);
+    }
+
+    public void testStatementObjectMethods() throws SQLException
+    {
+        con = getDataSourceConnection();
+
+        Statement stmt = con.createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT 1");
+        Statement stmtRef = stmt;
+
+        assertEquals(stmt, stmtRef);
+        // Currently we aren't proxying ResultSet, so this doesn't
+        // work, see Bug #1010542.
+        // assertEquals(stmt, rs.getStatement());
+
+        int hc1 = stmt.hashCode();
+        stmt.close();
+        int hc2 = stmt.hashCode();
+
+        assertEquals(stmt, stmtRef);
+        assertEquals(hc1, hc2);
+    }
+
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list