db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r661292 - in /db/derby/code/trunk/java: client/org/apache/derby/client/ClientPooledConnection40.java client/org/apache/derby/client/ClientXAConnection40.java testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java
Date Thu, 29 May 2008 11:10:03 GMT
Author: kahatlen
Date: Thu May 29 04:10:03 2008
New Revision: 661292

URL: http://svn.apache.org/viewvc?rev=661292&view=rev
Log:
DERBY-3695: NullPointerException when invoking statement event listeners if one of the listeners
is null

Made addStatementEventListener(null) a no-op on the client to match embedded.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java?rev=661292&r1=661291&r2=661292&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
Thu May 29 04:10:03 2008
@@ -81,7 +81,9 @@
         if (logWriter_ != null) {
             logWriter_.traceEntry(this, "addStatementEventListener", listener);
         }
-        statementEventListeners.add(listener);
+        if (listener != null) {
+            statementEventListeners.add(listener);
+        }
     }
     
     /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java?rev=661292&r1=661291&r2=661292&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection40.java Thu
May 29 04:10:03 2008
@@ -91,7 +91,9 @@
         if (logWriter_ != null) {
             logWriter_.traceEntry(this, "addStatementEventListener", listener);
         }
-        statementEventListeners.add(listener);
+        if (listener != null) {
+            statementEventListeners.add(listener);
+        }
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java?rev=661292&r1=661291&r2=661292&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java
Thu May 29 04:10:03 2008
@@ -232,6 +232,35 @@
     }
 
     /**
+     * Test that you don't get a NullPointerException when the listeners are
+     * triggered and one of them is null. DERBY-3695
+     */
+    public void testAddNullEvent() throws SQLException {
+        pooledConnection.addStatementEventListener(null);
+        PreparedStatement ps = prepare("VALUES (1)");
+        ps.close(); // trigger close event
+        assertEquals(1, closedCount);
+        assertEquals(0, errorCount);
+        ps = prepare("VALUES (1)");
+        connection.close();
+        try {
+            ps.execute();
+            fail("Execute should fail on closed connection");
+        } catch (SQLNonTransientConnectionException e) {
+            assertSQLState("08003", e);
+        }
+        assertEquals(1, errorCount);
+    }
+
+    /**
+     * Test that you can call {@code removeStatementEventListener()} with a
+     * {@code null} argument.
+     */
+    public void testRemoveNullEvent() throws SQLException {
+        pooledConnection.removeStatementEventListener(null);
+    }
+
+    /**
      * Test whether a close event is raised when a connection is
      * closed. (Client should raise a close event since the connection calls
      * <code>close()</code> on its statements. Embedded should not raise a



Mime
View raw message