Program: 15539
Project: 15539
Buggy source:
/** 
 * Handle the arrival of a container. This implementation will scan the existing streams and determine if any modules should be deployed to the new container.
 * @param client curator client
 * @param data node data for the container that arrived
 */
private void onChildAdded(CuratorFramework client,ChildData data) throws Exception {
  Container container=new Container(Paths.stripPath(data.getPath()),mapBytesUtility.toMap(data.getData()));
  String containerName=container.getName();
  LOG.info("String_Node_Str",containerName);
  for (Iterator<Stream> streamIterator=new ChildPathIterator<Stream>(streamConverter,streams); streamIterator.hasNext(); ) {
    Stream stream=streamIterator.next();
    for (Iterator<ModuleDescriptor> descriptorIterator=stream.getDeploymentOrderIterator(); descriptorIterator.hasNext(); ) {
      ModuleDescriptor descriptor=descriptorIterator.next();
      String group=descriptor.getGroup();
      if (StringUtils.isEmpty(group) || container.getGroups().contains(group)) {
        String streamName=descriptor.getStreamName();
        String moduleType=descriptor.getModuleDefinition().getType().toString();
        String moduleName=descriptor.getModuleDefinition().getName();
        String moduleLabel=descriptor.getLabel();
        List<String> containersForModule=client.getChildren().forPath(new StreamsPath().setStreamName(streamName).setModuleType(moduleType).setModuleLabel(moduleLabel).build());
        if (!containersForModule.contains(containerName)) {
          int moduleCount=descriptor.getCount();
          if (moduleCount <= 0 || containersForModule.size() < moduleCount) {
            LOG.info("String_Node_Str",moduleName,container);
            client.create().creatingParentsIfNeeded().forPath(new ModuleDeploymentsPath().setContainer(containerName).setStreamName(streamName).setModuleType(moduleType).setModuleLabel(moduleLabel).build());
            String path=new StreamsPath().setStreamName(streamName).setModuleType(moduleType).setModuleLabel(moduleLabel).setContainer(containerName).build();
            long timeout=System.currentTimeMillis() + 30000;
            boolean deployed;
            do {
              Thread.sleep(10);
              deployed=client.checkExists().forPath(path) != null;
            }
 while (!deployed && System.currentTimeMillis() < timeout);
            if (!deployed) {
              throw new IllegalStateException(String.format("String_Node_Str",moduleName,containerName));
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Handle the arrival of a container. This implementation will scan the existing streams and determine if any modules should be deployed to the new container.
 * @param client curator client
 * @param data node data for the container that arrived
 */
private void onChildAdded(CuratorFramework client,ChildData data) throws Exception {
  Container container=new Container(Paths.stripPath(data.getPath()),mapBytesUtility.toMap(data.getData()));
  String containerName=container.getName();
  LOG.info("String_Node_Str",containerName);
  for (Iterator<Stream> streamIterator=new ChildPathIterator<Stream>(streamConverter,streams); streamIterator.hasNext(); ) {
    Stream stream=streamIterator.next();
    for (Iterator<ModuleDescriptor> descriptorIterator=stream.getDeploymentOrderIterator(); descriptorIterator.hasNext(); ) {
      ModuleDescriptor descriptor=descriptorIterator.next();
      String group=descriptor.getGroup();
      if (StringUtils.isEmpty(group) || container.getGroups().contains(group)) {
        String streamName=descriptor.getStreamName();
        String moduleType=descriptor.getModuleDefinition().getType().toString();
        String moduleName=descriptor.getModuleDefinition().getName();
        String moduleLabel=descriptor.getLabel();
        List<String> containersForModule=getContainersForModule(client,descriptor);
        if (!containersForModule.contains(containerName)) {
          int moduleCount=descriptor.getCount();
          if (moduleCount <= 0 || containersForModule.size() < moduleCount) {
            LOG.info("String_Node_Str",moduleName,container);
            client.create().creatingParentsIfNeeded().forPath(new ModuleDeploymentsPath().setContainer(containerName).setStreamName(streamName).setModuleType(moduleType).setModuleLabel(moduleLabel).build());
            String path=new StreamsPath().setStreamName(streamName).setModuleType(moduleType).setModuleLabel(moduleLabel).setContainer(containerName).build();
            long timeout=System.currentTimeMillis() + 30000;
            boolean deployed;
            do {
              Thread.sleep(10);
              deployed=client.checkExists().forPath(path) != null;
            }
 while (!deployed && System.currentTimeMillis() < timeout);
            if (!deployed) {
              throw new IllegalStateException(String.format("String_Node_Str",moduleName,containerName));
            }
          }
        }
      }
    }
  }
}