Program: 13108
Project: 13108
Buggy source:
ClusterState executeCreateIndices(ClusterState currentState,BulkCreateIndicesRequest request) throws Exception {
  List<String> indicesToCreate=new ArrayList<>(request.indices().size());
  String removalReason=null;
  String testIndex=null;
  try {
    validateAndFilterExistingIndices(currentState,indicesToCreate,request);
    if (indicesToCreate.isEmpty()) {
      return currentState;
    }
    Map<String,IndexMetaData.Custom> customs=Maps.newHashMap();
    Map<String,Map<String,Object>> mappings=Maps.newHashMap();
    Map<String,AliasMetaData> templatesAliases=Maps.newHashMap();
    List<String> templateNames=Lists.newArrayList();
    List<IndexTemplateMetaData> templates=findTemplates(request,currentState,indexTemplateFilter);
    applyTemplates(customs,mappings,templatesAliases,templateNames,templates);
    File mappingsDir=new File(environment.configFile().toFile(),"String_Node_Str");
    if (mappingsDir.isDirectory()) {
      addMappingFromMappingsFile(mappings,mappingsDir,request);
    }
    Settings indexSettings=createIndexSettings(currentState,templates);
    testIndex=indicesToCreate.get(0);
    indicesService.createIndex(testIndex,indexSettings,clusterService.localNode().getId());
    IndexService indexService=indicesService.indexServiceSafe(testIndex);
    MapperService mapperService=indexService.mapperService();
    if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
      try {
        mapperService.merge(MapperService.DEFAULT_MAPPING,new CompressedXContent(XContentFactory.jsonBuilder().map(mappings.get(MapperService.DEFAULT_MAPPING)).string()),MapperService.MergeReason.MAPPING_UPDATE,false);
      }
 catch (      Exception e) {
        removalReason="String_Node_Str";
        throw new MapperParsingException("String_Node_Str" + MapperService.DEFAULT_MAPPING + "String_Node_Str",e);
      }
    }
    for (    Map.Entry<String,Map<String,Object>> entry : mappings.entrySet()) {
      if (entry.getKey().equals(MapperService.DEFAULT_MAPPING)) {
        continue;
      }
      try {
        mapperService.merge(entry.getKey(),new CompressedXContent(XContentFactory.jsonBuilder().map(entry.getValue()).string()),MapperService.MergeReason.MAPPING_UPDATE,false);
      }
 catch (      Exception e) {
        removalReason="String_Node_Str";
        throw new MapperParsingException("String_Node_Str" + entry.getKey() + "String_Node_Str",e);
      }
    }
    IndexQueryParserService indexQueryParserService=indexService.queryParserService();
    for (    AliasMetaData aliasMetaData : templatesAliases.values()) {
      if (aliasMetaData.filter() != null) {
        aliasValidator.validateAliasFilter(aliasMetaData.alias(),aliasMetaData.filter().uncompressed(),indexQueryParserService);
      }
    }
    Map<String,MappingMetaData> mappingsMetaData=Maps.newHashMap();
    for (    DocumentMapper mapper : mapperService.docMappers(true)) {
      MappingMetaData mappingMd=new MappingMetaData(mapper);
      mappingsMetaData.put(mapper.type(),mappingMd);
    }
    MetaData.Builder newMetaDataBuilder=MetaData.builder(currentState.metaData());
    for (    String index : indicesToCreate) {
      final IndexMetaData.Builder indexMetaDataBuilder=IndexMetaData.builder(index).settings(indexSettings);
      for (      MappingMetaData mappingMd : mappingsMetaData.values()) {
        indexMetaDataBuilder.putMapping(mappingMd);
      }
      for (      AliasMetaData aliasMetaData : templatesAliases.values()) {
        indexMetaDataBuilder.putAlias(aliasMetaData);
      }
      for (      Map.Entry<String,IndexMetaData.Custom> customEntry : customs.entrySet()) {
        indexMetaDataBuilder.putCustom(customEntry.getKey(),customEntry.getValue());
      }
      indexMetaDataBuilder.state(IndexMetaData.State.OPEN);
      final IndexMetaData indexMetaData;
      try {
        indexMetaData=indexMetaDataBuilder.build();
      }
 catch (      Exception e) {
        removalReason="String_Node_Str";
        throw e;
      }
      logger.info("String_Node_Str",index,templateNames,indexMetaData.getNumberOfShards(),indexMetaData.getNumberOfReplicas(),mappings.keySet());
      indexService.indicesLifecycle().beforeIndexAddedToCluster(new Index(index),indexMetaData.getSettings());
      newMetaDataBuilder.put(indexMetaData,false);
    }
    MetaData newMetaData=newMetaDataBuilder.build();
    ClusterState updatedState=ClusterState.builder(currentState).metaData(newMetaData).build();
    RoutingTable.Builder routingTableBuilder=RoutingTable.builder(updatedState.routingTable());
    for (    String index : indicesToCreate) {
      routingTableBuilder.addAsNew(updatedState.metaData().index(index));
    }
    RoutingAllocation.Result routingResult=allocationService.reroute(ClusterState.builder(updatedState).routingTable(routingTableBuilder).build(),"String_Node_Str");
    updatedState=ClusterState.builder(updatedState).routingResult(routingResult).build();
    removalReason="String_Node_Str";
    return updatedState;
  }
  finally {
    if (testIndex != null) {
      indicesService.deleteIndex(testIndex,removalReason != null ? removalReason : "String_Node_Str");
    }
  }
}

Fixed version (ground truth):
ClusterState executeCreateIndices(ClusterState currentState,BulkCreateIndicesRequest request) throws Exception {
  List<String> indicesToCreate=new ArrayList<>(request.indices().size());
  String removalReason=null;
  String testIndex=null;
  try {
    validateAndFilterExistingIndices(currentState,indicesToCreate,request);
    if (indicesToCreate.isEmpty()) {
      return currentState;
    }
    Map<String,IndexMetaData.Custom> customs=Maps.newHashMap();
    Map<String,Map<String,Object>> mappings=Maps.newHashMap();
    Map<String,AliasMetaData> templatesAliases=Maps.newHashMap();
    List<String> templateNames=Lists.newArrayList();
    List<IndexTemplateMetaData> templates=findTemplates(request,currentState,indexTemplateFilter);
    applyTemplates(customs,mappings,templatesAliases,templateNames,templates);
    File mappingsDir=new File(environment.configFile().toFile(),"String_Node_Str");
    if (mappingsDir.isDirectory()) {
      addMappingFromMappingsFile(mappings,mappingsDir,request);
    }
    Settings.Builder indexSettingsBuilder=createIndexSettings(currentState,templates);
    testIndex=indicesToCreate.get(0);
    indicesService.createIndex(testIndex,indexSettingsBuilder.build(),clusterService.localNode().getId());
    IndexService indexService=indicesService.indexServiceSafe(testIndex);
    MapperService mapperService=indexService.mapperService();
    if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) {
      try {
        mapperService.merge(MapperService.DEFAULT_MAPPING,new CompressedXContent(XContentFactory.jsonBuilder().map(mappings.get(MapperService.DEFAULT_MAPPING)).string()),MapperService.MergeReason.MAPPING_UPDATE,false);
      }
 catch (      Exception e) {
        removalReason="String_Node_Str";
        throw new MapperParsingException("String_Node_Str" + MapperService.DEFAULT_MAPPING + "String_Node_Str",e);
      }
    }
    for (    Map.Entry<String,Map<String,Object>> entry : mappings.entrySet()) {
      if (entry.getKey().equals(MapperService.DEFAULT_MAPPING)) {
        continue;
      }
      try {
        mapperService.merge(entry.getKey(),new CompressedXContent(XContentFactory.jsonBuilder().map(entry.getValue()).string()),MapperService.MergeReason.MAPPING_UPDATE,false);
      }
 catch (      Exception e) {
        removalReason="String_Node_Str";
        throw new MapperParsingException("String_Node_Str" + entry.getKey() + "String_Node_Str",e);
      }
    }
    IndexQueryParserService indexQueryParserService=indexService.queryParserService();
    for (    AliasMetaData aliasMetaData : templatesAliases.values()) {
      if (aliasMetaData.filter() != null) {
        aliasValidator.validateAliasFilter(aliasMetaData.alias(),aliasMetaData.filter().uncompressed(),indexQueryParserService);
      }
    }
    Map<String,MappingMetaData> mappingsMetaData=Maps.newHashMap();
    for (    DocumentMapper mapper : mapperService.docMappers(true)) {
      MappingMetaData mappingMd=new MappingMetaData(mapper);
      mappingsMetaData.put(mapper.type(),mappingMd);
    }
    MetaData.Builder newMetaDataBuilder=MetaData.builder(currentState.metaData());
    for (    String index : indicesToCreate) {
      Settings indexSettings=indexSettingsBuilder.put(IndexMetaData.SETTING_INDEX_UUID,Strings.randomBase64UUID()).build();
      final IndexMetaData.Builder indexMetaDataBuilder=IndexMetaData.builder(index).settings(indexSettings);
      for (      MappingMetaData mappingMd : mappingsMetaData.values()) {
        indexMetaDataBuilder.putMapping(mappingMd);
      }
      for (      AliasMetaData aliasMetaData : templatesAliases.values()) {
        indexMetaDataBuilder.putAlias(aliasMetaData);
      }
      for (      Map.Entry<String,IndexMetaData.Custom> customEntry : customs.entrySet()) {
        indexMetaDataBuilder.putCustom(customEntry.getKey(),customEntry.getValue());
      }
      indexMetaDataBuilder.state(IndexMetaData.State.OPEN);
      final IndexMetaData indexMetaData;
      try {
        indexMetaData=indexMetaDataBuilder.build();
      }
 catch (      Exception e) {
        removalReason="String_Node_Str";
        throw e;
      }
      logger.info("String_Node_Str",index,templateNames,indexMetaData.getNumberOfShards(),indexMetaData.getNumberOfReplicas(),mappings.keySet());
      indexService.indicesLifecycle().beforeIndexAddedToCluster(new Index(index),indexMetaData.getSettings());
      newMetaDataBuilder.put(indexMetaData,false);
    }
    MetaData newMetaData=newMetaDataBuilder.build();
    ClusterState updatedState=ClusterState.builder(currentState).metaData(newMetaData).build();
    RoutingTable.Builder routingTableBuilder=RoutingTable.builder(updatedState.routingTable());
    for (    String index : indicesToCreate) {
      routingTableBuilder.addAsNew(updatedState.metaData().index(index));
    }
    RoutingAllocation.Result routingResult=allocationService.reroute(ClusterState.builder(updatedState).routingTable(routingTableBuilder).build(),"String_Node_Str");
    updatedState=ClusterState.builder(updatedState).routingResult(routingResult).build();
    removalReason="String_Node_Str";
    return updatedState;
  }
  finally {
    if (testIndex != null) {
      indicesService.deleteIndex(testIndex,removalReason != null ? removalReason : "String_Node_Str");
    }
  }
}