Program: 79666
Project: 79666
Buggy source:
private Template buildTemplate(ComputeService computeService,BrooklynJcloudsSetupHolder setup){
  TemplateBuilder templateBuilder=(TemplateBuilder)setup.get("String_Node_Str");
  if (templateBuilder == null)   templateBuilder=new PortableTemplateBuilder();
 else   LOG.debug("String_Node_Str",new Object[]{templateBuilder,this,setup.getCallerContext()});
  if (setup.providerLocationId != null) {
    templateBuilder.locationId(setup.providerLocationId);
  }
  for (  Map.Entry<String,CustomizeTemplateBuilder> entry : SUPPORTED_TEMPLATE_BUILDER_PROPERTIES.entrySet()) {
    String name=entry.getKey();
    CustomizeTemplateBuilder code=entry.getValue();
    if (setup.use(name))     code.apply(templateBuilder,setup.allconf,setup.get(name));
  }
  if (templateBuilder instanceof PortableTemplateBuilder) {
    ((PortableTemplateBuilder)templateBuilder).attachComputeService(computeService);
    if (setup.use("String_Node_Str")) {
      if (((PortableTemplateBuilder)templateBuilder).isBlank()) {
        CharSequence defaultImageId=(CharSequence)setup.get("String_Node_Str");
        templateBuilder.imageId(defaultImageId.toString());
      }
    }
  }
  for (  JcloudsLocationCustomizer customizer : setup.customizers) {
    customizer.customize(computeService,templateBuilder);
  }
  Template template;
  try {
    template=templateBuilder.build();
    if (template == null)     throw new NullPointerException("String_Node_Str");
    LOG.debug("String_Node_Str" + this + "String_Node_Str"+ template+ "String_Node_Str"+ template.getImage()+ "String_Node_Str");
    if (template.getImage() == null)     throw new NullPointerException("String_Node_Str");
    if (isBadTemplate(template.getImage())) {
      if (templateBuilder instanceof PortableTemplateBuilder) {
        if (((PortableTemplateBuilder)templateBuilder).getOsFamily() == null) {
          templateBuilder.osFamily(OsFamily.UBUNTU).osVersionMatches("String_Node_Str").os64Bit(true);
          Template template2=templateBuilder.build();
          if (template2 != null) {
            LOG.debug("String_Node_Str" + this + "String_Node_Str",template2,template);
            template=template2;
          }
        }
      }
    }
  }
 catch (  AuthorizationException e) {
    LOG.warn("String_Node_Str" + e + "String_Node_Str");
    throw new IllegalStateException("String_Node_Str" + this + "String_Node_Str"+ templateBuilder,e);
  }
catch (  Exception e) {
    try {
synchronized (this) {
        LOG.warn("String_Node_Str" + templateBuilder + "String_Node_Str"+ this+ "String_Node_Str"+ e);
        if (!listedAvailableTemplatesOnNoSuchTemplate) {
          listedAvailableTemplatesOnNoSuchTemplate=true;
          LOG.info("String_Node_Str" + this + "String_Node_Str");
          Map m1=new LinkedHashMap(setup.allconf);
          if (m1.remove("String_Node_Str") != null)           m1.put("String_Node_Str",true);
          ComputeService computeServiceLessRestrictive=JcloudsUtil.buildOrFindComputeService(m1,new MutableMap());
          Set<? extends Image> imgs=computeServiceLessRestrictive.listImages();
          LOG.info("String_Node_Str" + imgs.size() + "String_Node_Str"+ this);
          for (          Image img : imgs) {
            LOG.info("String_Node_Str" + img);
          }
        }
      }
      throw new IllegalStateException("String_Node_Str" + templateBuilder + "String_Node_Str"+ this+ "String_Node_Str",e);
    }
 catch (    Exception e2) {
      LOG.warn("String_Node_Str" + e2,e2);
      throw new IllegalStateException("String_Node_Str" + this + "String_Node_Str"+ templateBuilder,e);
    }
  }
  TemplateOptions options=template.getOptions();
  for (  Map.Entry<String,CustomizeTemplateOptions> entry : SUPPORTED_TEMPLATE_OPTIONS_PROPERTIES.entrySet()) {
    String name=entry.getKey();
    CustomizeTemplateOptions code=entry.getValue();
    if (setup.use(name))     code.apply(options,setup.allconf,setup.get(name));
  }
  if (truth(setup.user) && !NON_ADDABLE_USERS.contains(setup.user) && !setup.user.equals(setup.loginUser)&& !truth(setup.isDontCreateUser())) {
    AdminAccess.Builder adminBuilder=AdminAccess.builder().adminUsername(setup.user).grantSudoToAdminUser(true);
    adminBuilder.adminPassword(setup.use("String_Node_Str") ? setup.password : Identifiers.makeRandomId(12));
    if (setup.publicKeyData != null)     adminBuilder.authorizeAdminPublicKey(true).adminPublicKey(setup.publicKeyData);
 else     adminBuilder.authorizeAdminPublicKey(false).adminPublicKey("String_Node_Str").lockSsh(true);
    adminBuilder.installAdminPrivateKey(false).adminPrivateKey("String_Node_Str");
    adminBuilder.resetLoginPassword(true).loginPassword(Identifiers.makeRandomId(12));
    adminBuilder.lockSsh(true);
    options.runScript(adminBuilder.build());
  }
 else   if (truth(setup.publicKeyData)) {
    options.authorizePublicKey(setup.publicKeyData);
  }
  for (  JcloudsLocationCustomizer customizer : setup.customizers) {
    customizer.customize(computeService,options);
  }
  LOG.debug("String_Node_Str",new Object[]{template,options,this,setup.getCallerContext()});
  return template;
}

Fixed version (ground truth):
private Template buildTemplate(ComputeService computeService,BrooklynJcloudsSetupHolder setup){
  TemplateBuilder templateBuilder=(TemplateBuilder)setup.get("String_Node_Str");
  if (templateBuilder == null)   templateBuilder=new PortableTemplateBuilder();
 else   LOG.debug("String_Node_Str",new Object[]{templateBuilder,this,setup.getCallerContext()});
  if (setup.providerLocationId != null) {
    templateBuilder.locationId(setup.providerLocationId);
  }
  for (  Map.Entry<String,CustomizeTemplateBuilder> entry : SUPPORTED_TEMPLATE_BUILDER_PROPERTIES.entrySet()) {
    String name=entry.getKey();
    CustomizeTemplateBuilder code=entry.getValue();
    if (setup.use(name))     code.apply(templateBuilder,setup.allconf,setup.get(name));
  }
  if (templateBuilder instanceof PortableTemplateBuilder) {
    ((PortableTemplateBuilder)templateBuilder).attachComputeService(computeService);
    if (setup.use("String_Node_Str")) {
      if (((PortableTemplateBuilder)templateBuilder).isBlank()) {
        CharSequence defaultImageId=(CharSequence)setup.get("String_Node_Str");
        templateBuilder.imageId(defaultImageId.toString());
      }
    }
  }
  for (  JcloudsLocationCustomizer customizer : setup.customizers) {
    customizer.customize(computeService,templateBuilder);
  }
  Template template;
  try {
    template=templateBuilder.build();
    if (template == null)     throw new NullPointerException("String_Node_Str");
    LOG.debug("String_Node_Str" + this + "String_Node_Str"+ template+ "String_Node_Str"+ template.getImage()+ "String_Node_Str");
    if (template.getImage() == null)     throw new NullPointerException("String_Node_Str");
    if (isBadTemplate(template.getImage())) {
      if (templateBuilder instanceof PortableTemplateBuilder) {
        if (((PortableTemplateBuilder)templateBuilder).getOsFamily() == null) {
          templateBuilder.osFamily(OsFamily.UBUNTU).osVersionMatches("String_Node_Str").os64Bit(true);
          Template template2=templateBuilder.build();
          if (template2 != null) {
            LOG.debug("String_Node_Str" + this + "String_Node_Str",template2,template);
            template=template2;
          }
        }
      }
    }
  }
 catch (  AuthorizationException e) {
    LOG.warn("String_Node_Str" + e + "String_Node_Str");
    throw new IllegalStateException("String_Node_Str" + this + "String_Node_Str"+ templateBuilder,e);
  }
catch (  Exception e) {
    try {
synchronized (this) {
        LOG.warn("String_Node_Str" + templateBuilder + "String_Node_Str"+ this+ "String_Node_Str"+ e);
        if (!listedAvailableTemplatesOnNoSuchTemplate) {
          listedAvailableTemplatesOnNoSuchTemplate=true;
          LOG.info("String_Node_Str" + this + "String_Node_Str");
          Map m1=new LinkedHashMap(setup.allconf);
          if (m1.remove("String_Node_Str") != null)           m1.put("String_Node_Str",true);
          ComputeService computeServiceLessRestrictive=JcloudsUtil.buildOrFindComputeService(m1,new MutableMap());
          Set<? extends Image> imgs=computeServiceLessRestrictive.listImages();
          LOG.info("String_Node_Str" + imgs.size() + "String_Node_Str"+ this);
          for (          Image img : imgs) {
            LOG.info("String_Node_Str" + img);
          }
        }
      }
    }
 catch (    Exception e2) {
      LOG.warn("String_Node_Str" + e2,e2);
      throw new IllegalStateException("String_Node_Str" + this + "String_Node_Str"+ templateBuilder,e);
    }
    throw new IllegalStateException("String_Node_Str" + templateBuilder + "String_Node_Str"+ this+ "String_Node_Str",e);
  }
  TemplateOptions options=template.getOptions();
  for (  Map.Entry<String,CustomizeTemplateOptions> entry : SUPPORTED_TEMPLATE_OPTIONS_PROPERTIES.entrySet()) {
    String name=entry.getKey();
    CustomizeTemplateOptions code=entry.getValue();
    if (setup.use(name))     code.apply(options,setup.allconf,setup.get(name));
  }
  if (truth(setup.user) && !NON_ADDABLE_USERS.contains(setup.user) && !setup.user.equals(setup.loginUser)&& !truth(setup.isDontCreateUser())) {
    AdminAccess.Builder adminBuilder=AdminAccess.builder().adminUsername(setup.user).grantSudoToAdminUser(true);
    adminBuilder.adminPassword(setup.use("String_Node_Str") ? setup.password : Identifiers.makeRandomId(12));
    if (setup.publicKeyData != null)     adminBuilder.authorizeAdminPublicKey(true).adminPublicKey(setup.publicKeyData);
 else     adminBuilder.authorizeAdminPublicKey(false).adminPublicKey("String_Node_Str").lockSsh(true);
    adminBuilder.installAdminPrivateKey(false).adminPrivateKey("String_Node_Str");
    adminBuilder.resetLoginPassword(true).loginPassword(Identifiers.makeRandomId(12));
    adminBuilder.lockSsh(true);
    options.runScript(adminBuilder.build());
  }
 else   if (truth(setup.publicKeyData)) {
    options.authorizePublicKey(setup.publicKeyData);
  }
  for (  JcloudsLocationCustomizer customizer : setup.customizers) {
    customizer.customize(computeService,options);
  }
  LOG.debug("String_Node_Str",new Object[]{template,options,this,setup.getCallerContext()});
  return template;
}