[libpostgresql-jdbc-java] 01/06: 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:19:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_0_324
in repository libpostgresql-jdbc-java.
commit 7b2d89272cd7329a06111b162b5a8fd653b7eb71
Author: Kris Jurka <books at ejurka.com>
Date: Wed Jan 7 05:29:24 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 f18652b..084662e2 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.9 2005/01/14 01:20:17 oliver Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/ds/common/PooledConnectionImpl.java,v 1.10 2005/01/17 10:59:04 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -262,22 +262,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
{
@@ -414,22 +403,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