Program: 79670
Project: 79670
Buggy source:
public JcloudsSshMachineLocation obtain(Map flags) throws NoMachinesAvailableException {
  BrooklynJcloudsSetupHolder setup=new BrooklynJcloudsSetupHolder(this).useConfig(flags).apply();
  String groupId=elvis(setup.remove("String_Node_Str"),generateGroupId());
  final ComputeService computeService=JcloudsUtil.buildOrFindComputeService(setup.allconf,setup.unusedConf);
  NodeMetadata node=null;
  try {
    LOG.info("String_Node_Str" + elvis(setup.providerLocationId,setup.provider) + "String_Node_Str"+ setup.getCallerContext());
    Template template=buildTemplate(computeService,setup);
    setup.warnIfUnused("String_Node_Str");
    Set<? extends NodeMetadata> nodes=computeService.createNodesInGroup(groupId,1,template);
    node=Iterables.getOnlyElement(nodes,null);
    LOG.debug("String_Node_Str",node,setup.getCallerContext());
    if (node == null) {
      throw new IllegalStateException("String_Node_Str" + setup.provider + "String_Node_Str"+ setup.providerLocationId+ "String_Node_Str"+ setup.getCallerContext());
    }
    LoginCredentials expectedCredentials=setup.customCredentials;
    if (expectedCredentials != null) {
      Object oldUsername=setup.setUser(expectedCredentials.getUser());
      LOG.debug("String_Node_Str",new Object[]{node,expectedCredentials.getUser(),oldUsername});
      if (truth(expectedCredentials.getPassword()))       setup.setPassword(expectedCredentials.getPassword());
      if (truth(expectedCredentials.getPrivateKey()))       setup.setPrivateKeyData(expectedCredentials.getPrivateKey());
    }
    if (expectedCredentials == null) {
      expectedCredentials=LoginCredentials.fromCredentials(node.getCredentials());
      String user=setup.user;
      LOG.debug("String_Node_Str",new Object[]{node,user,expectedCredentials.getUser()});
      if (truth(expectedCredentials.getUser())) {
        if (user == null) {
          setup.setUser(user=expectedCredentials.getUser());
        }
 else         if ("String_Node_Str".equals(user) && ROOT_ALIASES.contains(expectedCredentials.getUser())) {
          LOG.warn("String_Node_Str" + expectedCredentials.getUser() + "String_Node_Str",node);
          setup.setUser(user=expectedCredentials.getUser());
        }
      }
      String pkd=elvis(setup.privateKeyData,expectedCredentials.getPrivateKey());
      String pwd=elvis(setup.password,expectedCredentials.getPassword());
      if (user == null || (pkd == null && pwd == null)) {
        String missing=(user == null ? "String_Node_Str" : "String_Node_Str");
        LOG.warn("String_Node_Str" + missing + "String_Node_Str"+ this+ "String_Node_Str"+ node+ "String_Node_Str");
        expectedCredentials=null;
      }
 else {
        LoginCredentials.Builder expectedCredentialsBuilder=LoginCredentials.builder().user(user);
        if (pkd != null)         expectedCredentialsBuilder.privateKey(pkd);
        if (pwd != null)         expectedCredentialsBuilder.password(pwd);
        expectedCredentials=expectedCredentialsBuilder.build();
      }
    }
    if (expectedCredentials != null)     node=NodeMetadataBuilder.fromNodeMetadata(node).credentials(expectedCredentials).build();
 else     expectedCredentials=LoginCredentials.fromCredentials(node.getCredentials());
    if (setup.get("String_Node_Str") != null ? truth(setup.get("String_Node_Str")) : true) {
      String vmIp=JcloudsUtil.getFirstReachableAddress(node);
      final NodeMetadata nodeRef=node;
      final LoginCredentials expectedCredentialsRef=expectedCredentials;
      long delayMs=-1;
      try {
        delayMs=Time.parseTimeString("String_Node_Str" + setup.get("String_Node_Str"));
      }
 catch (      Exception e) {
      }
      if (delayMs <= 0)       delayMs=START_SSHABLE_TIMEOUT;
      LOG.info("String_Node_Str",new Object[]{elvis(setup.get("String_Node_Str"),setup.get("String_Node_Str")),setup.getCallerContext(),setup.user,vmIp});
      boolean reachable=new Repeater().repeat().every(1,SECONDS).until(new Callable<Boolean>(){
        public Boolean call(){
          Statement statement=Statements.newStatementList(exec("String_Node_Str"));
          ExecResponse response=computeService.runScriptOnNode(nodeRef.getId(),statement,overrideLoginCredentials(expectedCredentialsRef));
          return response.getExitStatus() == 0;
        }
      }
).limitTimeTo(delayMs,MILLISECONDS).run();
      if (!reachable) {
        throw new IllegalStateException("String_Node_Str" + setup.user + "String_Node_Str"+ vmIp+ "String_Node_Str"+ setup.getCallerContext()+ "String_Node_Str"+ Time.makeTimeString(delayMs));
      }
    }
    String vmHostname=getPublicHostname(node,setup);
    Map sshConfig=generateSshConfig(setup,node);
    if (LOG.isDebugEnabled())     LOG.debug("String_Node_Str",new Object[]{setup.user,vmHostname,setup.getCallerContext(),Entities.sanitize(sshConfig)});
    JcloudsSshMachineLocation sshLocByHostname=new JcloudsSshMachineLocation(MutableMap.builder().put("String_Node_Str",vmHostname).put("String_Node_Str",vmHostname).put("String_Node_Str",setup.user).put("String_Node_Str",sshConfig).put("String_Node_Str",localTempDir).build(),this,node);
    sshLocByHostname.setParentLocation(this);
    vmInstanceIds.put(sshLocByHostname,node.getId());
    return sshLocByHostname;
  }
 catch (  RunNodesException e) {
    if (e.getNodeErrors().size() > 0) {
      node=Iterables.get(e.getNodeErrors().keySet(),0);
    }
    LOG.error("String_Node_Str",e.getMessage());
    throw Throwables.propagate(e);
  }
catch (  Exception e) {
    LOG.error("String_Node_Str",e.getMessage());
    LOG.info(Throwables.getStackTraceAsString(e));
    throw Throwables.propagate(e);
  }
 finally {
  }
}

Fixed version (ground truth):
public JcloudsSshMachineLocation obtain(Map flags) throws NoMachinesAvailableException {
  BrooklynJcloudsSetupHolder setup=new BrooklynJcloudsSetupHolder(this).useConfig(flags).apply();
  String groupId=elvis(setup.remove("String_Node_Str"),generateGroupId(setup.provider));
  final ComputeService computeService=JcloudsUtil.buildOrFindComputeService(setup.allconf,setup.unusedConf);
  NodeMetadata node=null;
  try {
    LOG.info("String_Node_Str" + elvis(setup.providerLocationId,setup.provider) + "String_Node_Str"+ setup.getCallerContext());
    Template template=buildTemplate(computeService,setup);
    setup.warnIfUnused("String_Node_Str");
    Set<? extends NodeMetadata> nodes=computeService.createNodesInGroup(groupId,1,template);
    node=Iterables.getOnlyElement(nodes,null);
    LOG.debug("String_Node_Str",node,setup.getCallerContext());
    if (node == null) {
      throw new IllegalStateException("String_Node_Str" + setup.provider + "String_Node_Str"+ setup.providerLocationId+ "String_Node_Str"+ setup.getCallerContext());
    }
    LoginCredentials expectedCredentials=setup.customCredentials;
    if (expectedCredentials != null) {
      Object oldUsername=setup.setUser(expectedCredentials.getUser());
      LOG.debug("String_Node_Str",new Object[]{node,expectedCredentials.getUser(),oldUsername});
      if (truth(expectedCredentials.getPassword()))       setup.setPassword(expectedCredentials.getPassword());
      if (truth(expectedCredentials.getPrivateKey()))       setup.setPrivateKeyData(expectedCredentials.getPrivateKey());
    }
    if (expectedCredentials == null) {
      expectedCredentials=LoginCredentials.fromCredentials(node.getCredentials());
      String user=setup.user;
      LOG.debug("String_Node_Str",new Object[]{node,user,expectedCredentials.getUser()});
      if (truth(expectedCredentials.getUser())) {
        if (user == null) {
          setup.setUser(user=expectedCredentials.getUser());
        }
 else         if ("String_Node_Str".equals(user) && ROOT_ALIASES.contains(expectedCredentials.getUser())) {
          LOG.warn("String_Node_Str" + expectedCredentials.getUser() + "String_Node_Str",node);
          setup.setUser(user=expectedCredentials.getUser());
        }
      }
      String pkd=elvis(setup.privateKeyData,expectedCredentials.getPrivateKey());
      String pwd=elvis(setup.password,expectedCredentials.getPassword());
      if (user == null || (pkd == null && pwd == null)) {
        String missing=(user == null ? "String_Node_Str" : "String_Node_Str");
        LOG.warn("String_Node_Str" + missing + "String_Node_Str"+ this+ "String_Node_Str"+ node+ "String_Node_Str");
        expectedCredentials=null;
      }
 else {
        LoginCredentials.Builder expectedCredentialsBuilder=LoginCredentials.builder().user(user);
        if (pkd != null)         expectedCredentialsBuilder.privateKey(pkd);
        if (pwd != null)         expectedCredentialsBuilder.password(pwd);
        expectedCredentials=expectedCredentialsBuilder.build();
      }
    }
    if (expectedCredentials != null)     node=NodeMetadataBuilder.fromNodeMetadata(node).credentials(expectedCredentials).build();
 else     expectedCredentials=LoginCredentials.fromCredentials(node.getCredentials());
    if (setup.get("String_Node_Str") != null ? truth(setup.get("String_Node_Str")) : true) {
      String vmIp=JcloudsUtil.getFirstReachableAddress(node);
      final NodeMetadata nodeRef=node;
      final LoginCredentials expectedCredentialsRef=expectedCredentials;
      long delayMs=-1;
      try {
        delayMs=Time.parseTimeString("String_Node_Str" + setup.get("String_Node_Str"));
      }
 catch (      Exception e) {
      }
      if (delayMs <= 0)       delayMs=START_SSHABLE_TIMEOUT;
      LOG.info("String_Node_Str",new Object[]{elvis(setup.get("String_Node_Str"),setup.get("String_Node_Str")),setup.getCallerContext(),setup.user,vmIp});
      boolean reachable=new Repeater().repeat().every(1,SECONDS).until(new Callable<Boolean>(){
        public Boolean call(){
          Statement statement=Statements.newStatementList(exec("String_Node_Str"));
          ExecResponse response=computeService.runScriptOnNode(nodeRef.getId(),statement,overrideLoginCredentials(expectedCredentialsRef));
          return response.getExitStatus() == 0;
        }
      }
).limitTimeTo(delayMs,MILLISECONDS).run();
      if (!reachable) {
        throw new IllegalStateException("String_Node_Str" + setup.user + "String_Node_Str"+ vmIp+ "String_Node_Str"+ setup.getCallerContext()+ "String_Node_Str"+ Time.makeTimeString(delayMs));
      }
    }
    String vmHostname=getPublicHostname(node,setup);
    Map sshConfig=generateSshConfig(setup,node);
    if (LOG.isDebugEnabled())     LOG.debug("String_Node_Str",new Object[]{setup.user,vmHostname,setup.getCallerContext(),Entities.sanitize(sshConfig)});
    JcloudsSshMachineLocation sshLocByHostname=new JcloudsSshMachineLocation(MutableMap.builder().put("String_Node_Str",vmHostname).put("String_Node_Str",vmHostname).put("String_Node_Str",setup.user).put("String_Node_Str",sshConfig).put("String_Node_Str",localTempDir).build(),this,node);
    sshLocByHostname.setParentLocation(this);
    vmInstanceIds.put(sshLocByHostname,node.getId());
    return sshLocByHostname;
  }
 catch (  RunNodesException e) {
    if (e.getNodeErrors().size() > 0) {
      node=Iterables.get(e.getNodeErrors().keySet(),0);
    }
    LOG.error("String_Node_Str",e.getMessage());
    throw Throwables.propagate(e);
  }
catch (  Exception e) {
    LOG.error("String_Node_Str",e.getMessage());
    LOG.info(Throwables.getStackTraceAsString(e));
    throw Throwables.propagate(e);
  }
 finally {
  }
}