Program: 15538
Project: 15538
Buggy source:
/** 
 * {@inheritDoc}<p/> Upon leadership election, this Admin server will create a   {@link PathChildrenCache}for   {@link Paths#STREAMS} and {@link Paths#JOBS}. These caches will have  {@link PathChildrenCacheListener PathChildrenCacheListeners} attached to themthat will react to stream and job creation and deletion. Upon leadership relinquishment, the listeners will be removed and the caches shut down.
 */
@Override public void takeLeadership(CuratorFramework client) throws Exception {
  LOG.info("String_Node_Str",getId());
  PathChildrenCache streamDeployments=null;
  PathChildrenCache jobDeployments=null;
  PathChildrenCacheListener streamListener;
  PathChildrenCacheListener jobListener;
  PathChildrenCacheListener containerListener;
  try {
    streamListener=new StreamListener(AdminServer.this,streamDefinitionRepository,moduleDefinitionRepository,moduleOptionsMetadataResolver);
    streamDeployments=new PathChildrenCache(client,Paths.STREAM_DEPLOYMENTS,true,ThreadUtils.newThreadFactory("String_Node_Str"));
    streamDeployments.getListenable().addListener(streamListener);
    streamDeployments.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
    jobListener=new JobListener(AdminServer.this,moduleDefinitionRepository,moduleOptionsMetadataResolver);
    jobDeployments=new PathChildrenCache(client,Paths.JOB_DEPLOYMENTS,true,ThreadUtils.newThreadFactory("String_Node_Str"));
    jobDeployments.getListenable().addListener(jobListener);
    jobDeployments.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
    containerListener=new ContainerListener(AdminServer.this,streamDefinitionRepository,moduleDefinitionRepository,moduleOptionsMetadataResolver,streamDeployments);
    PathChildrenCache containersCache=new PathChildrenCache(client,Paths.CONTAINERS,true,ThreadUtils.newThreadFactory("String_Node_Str"));
    containersCache.getListenable().addListener(containerListener);
    containersCache.start();
    containers.set(containersCache);
    Thread.sleep(Long.MAX_VALUE);
  }
 catch (  InterruptedException e) {
    LOG.info("String_Node_Str");
    Thread.currentThread().interrupt();
  }
 finally {
    PathChildrenCache containersCache=containers.getAndSet(null);
    if (containersCache != null) {
      containersCache.close();
    }
    if (streamDeployments != null) {
      streamDeployments.close();
    }
    if (jobDeployments != null) {
      jobDeployments.close();
    }
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}<p/> Upon leadership election, this Admin server will create a   {@link PathChildrenCache}for   {@link Paths#STREAMS} and {@link Paths#JOBS}. These caches will have  {@link PathChildrenCacheListener PathChildrenCacheListeners} attached to themthat will react to stream and job creation and deletion. Upon leadership relinquishment, the listeners will be removed and the caches shut down.
 */
@Override public void takeLeadership(CuratorFramework client) throws Exception {
  LOG.info("String_Node_Str",getId());
  PathChildrenCache streams=null;
  PathChildrenCache streamDeployments=null;
  PathChildrenCache jobDeployments=null;
  PathChildrenCacheListener streamListener;
  PathChildrenCacheListener jobListener;
  PathChildrenCacheListener containerListener;
  try {
    streamListener=new StreamListener(AdminServer.this,streamDefinitionRepository,moduleDefinitionRepository,moduleOptionsMetadataResolver);
    streams=new PathChildrenCache(client,Paths.STREAMS,true,ThreadUtils.newThreadFactory("String_Node_Str"));
    streams.start();
    streamDeployments=new PathChildrenCache(client,Paths.STREAM_DEPLOYMENTS,true,ThreadUtils.newThreadFactory("String_Node_Str"));
    streamDeployments.getListenable().addListener(streamListener);
    streamDeployments.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
    jobListener=new JobListener(AdminServer.this,moduleDefinitionRepository,moduleOptionsMetadataResolver);
    jobDeployments=new PathChildrenCache(client,Paths.JOB_DEPLOYMENTS,true,ThreadUtils.newThreadFactory("String_Node_Str"));
    jobDeployments.getListenable().addListener(jobListener);
    jobDeployments.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
    containerListener=new ContainerListener(AdminServer.this,streamDefinitionRepository,moduleDefinitionRepository,moduleOptionsMetadataResolver,streams);
    PathChildrenCache containersCache=new PathChildrenCache(client,Paths.CONTAINERS,true,ThreadUtils.newThreadFactory("String_Node_Str"));
    containersCache.getListenable().addListener(containerListener);
    containersCache.start();
    containers.set(containersCache);
    Thread.sleep(Long.MAX_VALUE);
  }
 catch (  InterruptedException e) {
    LOG.info("String_Node_Str");
    Thread.currentThread().interrupt();
  }
 finally {
    PathChildrenCache containersCache=containers.getAndSet(null);
    if (containersCache != null) {
      containersCache.close();
    }
    if (streams != null) {
      streams.close();
    }
    if (streamDeployments != null) {
      streamDeployments.close();
    }
    if (jobDeployments != null) {
      jobDeployments.close();
    }
  }
}