From 3d8848801b06656f425b027d16219b026bbbb2a8 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 27 Sep 2013 22:20:48 +0000
Subject: [PATCH] Fix OPENDJ-1156 - NPE in ReferenceCountedObject after shutting down directory

---
 opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
index 43f1bd0..3599b4f 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnection.java
@@ -295,7 +295,6 @@
     public void close(final UnbindRequest request, final String reason) {
         // FIXME: I18N need to internationalize this message.
         Validator.ensureNotNull(request);
-
         close(request, false, Responses.newResult(ResultCode.CLIENT_SIDE_USER_CANCELLED)
                 .setDiagnosticMessage(reason != null ? reason : "Connection closed by client"));
     }
@@ -624,10 +623,10 @@
         }
 
         /*
-         * Now try cleanly closing the connection if possible. Only send unbind
-         * if specified.
+         * If this is the final client initiated close then release close the
+         * connection and release resources.
          */
-        if (unbindRequest != null) {
+        if (notifyClose) {
             final ASN1BufferWriter asn1Writer = ASN1BufferWriter.getWriter();
             try {
                 ldapWriter.unbindRequest(asn1Writer, nextMsgID.getAndIncrement(), unbindRequest);
@@ -640,10 +639,10 @@
             } finally {
                 asn1Writer.recycle();
             }
+            factory.getTimeoutChecker().removeConnection(this);
+            connection.closeSilently();
+            factory.releaseTransportAndTimeoutChecker();
         }
-        factory.getTimeoutChecker().removeConnection(this);
-        connection.closeSilently();
-        factory.releaseTransportAndTimeoutChecker();
 
         // Notify listeners.
         if (tmpListeners != null) {

--
Gitblit v1.10.0