Author: max.ross
Date: 2007-12-10 19:56:15 -0500 (Mon, 10 Dec 2007)
New Revision: 14240
Modified:
shards/trunk/src/java/org/hibernate/shards/session/ShardedSessionImpl.java
shards/trunk/src/test/org/hibernate/shards/session/ShardedSessionImplTest.java
Log:
HSHARDS-48
fix NPE in ShardedSessionImpl.disconnect()
Modified: shards/trunk/src/java/org/hibernate/shards/session/ShardedSessionImpl.java
===================================================================
--- shards/trunk/src/java/org/hibernate/shards/session/ShardedSessionImpl.java 2007-12-09
19:05:38 UTC (rev 14239)
+++ shards/trunk/src/java/org/hibernate/shards/session/ShardedSessionImpl.java 2007-12-11
00:56:15 UTC (rev 14240)
@@ -1255,7 +1255,10 @@
public Connection disconnect() throws HibernateException {
for (Shard s : getShards()) {
- s.getSession().disconnect();
+ Session session = s.getSession();
+ if (session != null) {
+ session.disconnect();
+ }
}
// we do not allow application-supplied connections, so we can always return
// null
Modified: shards/trunk/src/test/org/hibernate/shards/session/ShardedSessionImplTest.java
===================================================================
---
shards/trunk/src/test/org/hibernate/shards/session/ShardedSessionImplTest.java 2007-12-09
19:05:38 UTC (rev 14239)
+++
shards/trunk/src/test/org/hibernate/shards/session/ShardedSessionImplTest.java 2007-12-11
00:56:15 UTC (rev 14240)
@@ -32,6 +32,7 @@
import org.hibernate.shards.ShardedSessionFactoryDefaultMock;
import org.hibernate.shards.defaultmock.ClassMetadataDefaultMock;
import org.hibernate.shards.defaultmock.InterceptorDefaultMock;
+import org.hibernate.shards.defaultmock.SessionDefaultMock;
import org.hibernate.shards.defaultmock.TypeDefaultMock;
import org.hibernate.shards.engine.ShardedSessionFactoryImplementor;
import org.hibernate.shards.strategy.ShardStrategy;
@@ -683,4 +684,30 @@
ssi.close();
assertFalse(ssi.isOpen());
}
+
+ public void testDisconnectWithNullSessions() {
+
+ ShardedSessionImpl ssi = new MyShardedSessionImpl() {
+
+ public List<Shard> getShards() {
+ Shard shard1 = new ShardDefaultMock() {
+ public org.hibernate.classic.Session getSession() {
+ return new SessionDefaultMock() {
+ public Connection disconnect() throws HibernateException {
+ return null;
+ }
+ };
+ }
+ };
+ Shard shard2 = new ShardDefaultMock() {
+
+ public org.hibernate.classic.Session getSession() {
+ return null;
+ }
+ };
+ return Lists.newArrayList(shard1, shard2);
+ }
+ };
+ ssi.disconnect();
+ }
}
Show replies by date