Provide sane AdaptorContext until Adaptor.destroy

The Adaptor should not have to deal with a window where the
AdaptorContext isn't usable. The AdaptorContext should only be
invalidated after Adaptor.destroy has returned.
diff --git a/src/com/google/enterprise/adaptor/GsaCommunicationHandler.java b/src/com/google/enterprise/adaptor/GsaCommunicationHandler.java
index c7037c1..d8b5843 100644
--- a/src/com/google/enterprise/adaptor/GsaCommunicationHandler.java
+++ b/src/com/google/enterprise/adaptor/GsaCommunicationHandler.java
@@ -434,7 +434,6 @@
     sendDocIdsSchedId = null;
     if (scope != null) {
       scope.close();
-      scope = null;
     }
     // Stop sendDocIds before scheduler, because scheduler blocks until all
     // tasks are completed. We want to interrupt sendDocIds so that the
@@ -450,7 +449,6 @@
     }
     if (backgroundExecutor != null) {
       backgroundExecutor.shutdownNow();
-      backgroundExecutor = null;
     }
     if (waiter != null) {
       try {
@@ -459,9 +457,18 @@
         Thread.currentThread().interrupt();
       }
     }
-    sessionManager = null;
-    adaptor.destroy();
-    waiter = null;
+    try {
+      adaptor.destroy();
+    } finally {
+      // Wait until after adaptor.destroy() to set things to null, so that the
+      // AdaptorContext is usable until the very end.
+      scope = null;
+      docIdFullPusher = null;
+      dashboard = null;
+      backgroundExecutor = null;
+      waiter = null;
+      sessionManager = null;
+    }
   }
 
   /**