]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed npe in SQLContainer's J2EEConnectionPool #7597
authorJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Thu, 22 Sep 2011 08:49:46 +0000 (08:49 +0000)
committerJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Thu, 22 Sep 2011 08:49:46 +0000 (08:49 +0000)
svn changeset:21225/svn branch:6.7

src/com/vaadin/data/util/sqlcontainer/connection/J2EEConnectionPool.java
tests/src/com/vaadin/tests/server/container/sqlcontainer/connection/J2EEConnectionPoolTest.java

index 09c9cc1b1bed86971a6d56ba7f5b8574cbbee7e1..12a2c6cd9f3da2a179be009bd1c4080a2de7e1b1 100644 (file)
@@ -5,12 +5,16 @@ package com.vaadin.data.util.sqlcontainer.connection;
 
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
 
 public class J2EEConnectionPool implements JDBCConnectionPool {
+    private static final Logger logger = Logger
+            .getLogger(J2EEConnectionPool.class.getName());
 
     private String dataSourceJndiName;
 
@@ -50,10 +54,12 @@ public class J2EEConnectionPool implements JDBCConnectionPool {
     }
 
     public void releaseConnection(Connection conn) {
-        try {
-            conn.close();
-        } catch (SQLException e) {
-            e.printStackTrace();
+        if (conn != null) {
+            try {
+                conn.close();
+            } catch (SQLException e) {
+                logger.log(Level.FINE, "Could not release SQL connection", e);
+            }
         }
     }
 
index dc5ca51d94f61aef542aa236968a550fcbfd562f..fd0c5b9af7752df3612d84f9c517030808b2be3f 100644 (file)
@@ -65,7 +65,8 @@ public class J2EEConnectionPoolTest {
         ds.getConnection();
         EasyMock.expectLastCall().andReturn(connection);
 
-        System.setProperty("java.naming.factory.initial",
+        System.setProperty(
+                "java.naming.factory.initial",
                 "com.vaadin.tests.server.container.sqlcontainer.connection.MockInitialContextFactory");
         Context context = EasyMock.createMock(Context.class);
         context.lookup("testDataSource");
@@ -94,8 +95,17 @@ public class J2EEConnectionPoolTest {
         EasyMock.replay(context);
 
         J2EEConnectionPool pool = new J2EEConnectionPool("foo");
-        Connection c = pool.reserveConnection();
+        pool.reserveConnection();
         EasyMock.verify(context);
     }
 
+    @Test
+    public void releaseConnection_null_shouldSucceed() throws SQLException {
+        DataSource ds = EasyMock.createMock(DataSource.class);
+        EasyMock.replay(ds);
+
+        J2EEConnectionPool pool = new J2EEConnectionPool(ds);
+        pool.releaseConnection(null);
+        EasyMock.verify(ds);
+    }
 }