Program: 160279
Project: 160279
Buggy source:
/** 
 * Error after close DB client https://github.com/couchbase/couchbase-lite-java/issues/52
 */
public void testClose() throws Exception {
  Log.d(Log.TAG,"String_Node_Str");
  boolean success=false;
  MockDispatcher dispatcher=new MockDispatcher();
  dispatcher.setServerType(MockDispatcher.ServerType.SYNC_GW);
  MockWebServer server=new MockWebServer();
  server.setDispatcher(dispatcher);
  try {
    server.play();
    MockCheckpointPut mockCheckpointPut=new MockCheckpointPut();
    mockCheckpointPut.setSticky(true);
    dispatcher.enqueueResponse(MockHelper.PATH_REGEX_CHECKPOINT,mockCheckpointPut);
    Replication pull=database.createPullReplication(server.getUrl("String_Node_Str"));
    pull.setContinuous(true);
    final CountDownLatch pullIdleState=new CountDownLatch(1);
    ReplicationIdleObserver pullIdleObserver=new ReplicationIdleObserver(pullIdleState);
    pull.addChangeListener(pullIdleObserver);
    pull.start();
    Replication push=database.createPullReplication(server.getUrl("String_Node_Str"));
    push.setContinuous(true);
    final CountDownLatch pushIdleState=new CountDownLatch(1);
    ReplicationIdleObserver pushIdleObserver=new ReplicationIdleObserver(pushIdleState);
    push.addChangeListener(pushIdleObserver);
    push.start();
    success=pullIdleState.await(30,TimeUnit.SECONDS);
    assertTrue(success);
    pull.removeChangeListener(pullIdleObserver);
    success=pushIdleState.await(30,TimeUnit.SECONDS);
    assertTrue(success);
    push.removeChangeListener(pushIdleObserver);
    final CountDownLatch pullStoppedState=new CountDownLatch(1);
    ReplicationFinishedObserver pullStoppedObserver=new ReplicationFinishedObserver(pullStoppedState);
    pull.addChangeListener(pullStoppedObserver);
    final CountDownLatch pushStoppedState=new CountDownLatch(1);
    ReplicationFinishedObserver pushStoppedObserver=new ReplicationFinishedObserver(pushStoppedState);
    push.addChangeListener(pushStoppedObserver);
    manager.close();
    assertEquals(0,pullStoppedState.getCount());
    assertEquals(0,pushStoppedState.getCount());
    pull.removeChangeListener(pullStoppedObserver);
    push.removeChangeListener(pushStoppedObserver);
    try {
      Thread.sleep(3 * 1000);
    }
 catch (    Exception e) {
    }
    Set<Thread> threadSet=Thread.getAllStackTraces().keySet();
    for (    Thread t : threadSet) {
      if (t.isAlive()) {
        assertEquals(-1,t.getName().indexOf("String_Node_Str"));
        assertEquals(-1,t.getName().indexOf("String_Node_Str"));
      }
    }
  }
  finally {
    server.shutdown();
  }
  Log.d(Log.TAG,"String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Error after close DB client https://github.com/couchbase/couchbase-lite-java/issues/52
 */
public void testClose() throws Exception {
  Log.d(Log.TAG,"String_Node_Str");
  MockWebServer server=new MockWebServer();
  try {
    MockDispatcher dispatcher=new MockDispatcher();
    dispatcher.setServerType(MockDispatcher.ServerType.SYNC_GW);
    server.setDispatcher(dispatcher);
    server.play();
    MockCheckpointPut mockCheckpointPut=new MockCheckpointPut();
    mockCheckpointPut.setSticky(true);
    dispatcher.enqueueResponse(MockHelper.PATH_REGEX_CHECKPOINT,mockCheckpointPut);
    Replication pull=database.createPullReplication(server.getUrl("String_Node_Str"));
    pull.setContinuous(true);
    final CountDownLatch pullIdleState=new CountDownLatch(1);
    ReplicationIdleObserver pullIdleObserver=new ReplicationIdleObserver(pullIdleState);
    pull.addChangeListener(pullIdleObserver);
    pull.start();
    Replication push=database.createPullReplication(server.getUrl("String_Node_Str"));
    push.setContinuous(true);
    final CountDownLatch pushIdleState=new CountDownLatch(1);
    ReplicationIdleObserver pushIdleObserver=new ReplicationIdleObserver(pushIdleState);
    push.addChangeListener(pushIdleObserver);
    push.start();
    assertTrue(pullIdleState.await(30,TimeUnit.SECONDS));
    assertTrue(pushIdleState.await(30,TimeUnit.SECONDS));
    pull.removeChangeListener(pullIdleObserver);
    push.removeChangeListener(pushIdleObserver);
    final CountDownLatch pullStoppedState=new CountDownLatch(1);
    ReplicationFinishedObserver pullStoppedObserver=new ReplicationFinishedObserver(pullStoppedState);
    pull.addChangeListener(pullStoppedObserver);
    final CountDownLatch pushStoppedState=new CountDownLatch(1);
    ReplicationFinishedObserver pushStoppedObserver=new ReplicationFinishedObserver(pushStoppedState);
    push.addChangeListener(pushStoppedObserver);
    manager.close();
    assertTrue(pullStoppedState.await(10,TimeUnit.SECONDS));
    assertTrue(pushStoppedState.await(10,TimeUnit.SECONDS));
    pull.removeChangeListener(pullStoppedObserver);
    push.removeChangeListener(pushStoppedObserver);
    try {
      Thread.sleep(3 * 1000);
    }
 catch (    Exception e) {
    }
    Set<Thread> threadSet=Thread.getAllStackTraces().keySet();
    for (    Thread t : threadSet) {
      if (t.isAlive()) {
        assertEquals(-1,t.getName().indexOf("String_Node_Str"));
        assertEquals(-1,t.getName().indexOf("String_Node_Str"));
      }
    }
  }
  finally {
    server.shutdown();
  }
  Log.d(Log.TAG,"String_Node_Str");
}