Program: 79535
Project: 79535
Buggy source:
/** 
 * Create the user immediately - executing ssh commands as required.
 */
protected LoginCredentials createUser(ComputeService computeService,NodeMetadata node,Optional<HostAndPort> hostAndPortOverride,ConfigBag config){
  UserCreation userCreation=createUserStatements(computeService.getImage(node.getImageId()),config);
  if (!userCreation.statements.isEmpty()) {
    org.jclouds.compute.domain.OsFamily osFamily=node.getOperatingSystem().getFamily();
    org.jclouds.scriptbuilder.domain.OsFamily scriptOsFamily=(osFamily == org.jclouds.compute.domain.OsFamily.WINDOWS) ? org.jclouds.scriptbuilder.domain.OsFamily.WINDOWS : org.jclouds.scriptbuilder.domain.OsFamily.UNIX;
    List<String> commands=Lists.newArrayList();
    for (    Statement statement : userCreation.statements) {
      InitAdminAccess initAdminAccess=new InitAdminAccess(new AdminAccessConfiguration.Default());
      initAdminAccess.visit(statement);
      commands.add(statement.render(scriptOsFamily));
    }
    LoginCredentials initialCredentials=node.getCredentials();
    Optional<String> initialPassword=initialCredentials.getOptionalPassword();
    Optional<String> initialPrivateKey=initialCredentials.getOptionalPrivateKey();
    String initialUser=initialCredentials.getUser();
    String address=hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getHostText() : JcloudsUtil.getFirstReachableAddress(computeService.getContext(),node);
    int port=hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getPort() : node.getLoginPort();
    Map<String,Object> sshProps=Maps.newLinkedHashMap(config.getAllConfig());
    sshProps.put("String_Node_Str",initialUser);
    sshProps.put("String_Node_Str",address);
    sshProps.put("String_Node_Str",port);
    if (initialPassword.isPresent())     sshProps.put("String_Node_Str",initialPassword.get());
    if (initialPrivateKey.isPresent())     sshProps.put("String_Node_Str",initialPrivateKey.get());
    Map<String,Object> execProps=Maps.newLinkedHashMap();
    execProps.put(ShellTool.PROP_RUN_AS_ROOT.getName(),true);
    SshMachineLocation sshLoc=null;
    try {
      if (isManaged()) {
        sshLoc=getManagementContext().getLocationManager().createLocation(sshProps,SshMachineLocation.class);
      }
 else {
        sshLoc=new SshMachineLocation(sshProps);
      }
      int exitcode=sshLoc.execScript(execProps,"String_Node_Str",commands);
      if (exitcode != 0) {
        LOG.warn("String_Node_Str",exitcode,node);
      }
    }
  finally {
      getManagementContext().getLocationManager().unmanage(sshLoc);
      Closeables.closeQuietly(sshLoc);
    }
  }
  return userCreation.loginCredentials;
}

Fixed version (ground truth):
/** 
 * Create the user immediately - executing ssh commands as required.
 */
protected LoginCredentials createUser(ComputeService computeService,NodeMetadata node,Optional<HostAndPort> hostAndPortOverride,ConfigBag config){
  UserCreation userCreation=createUserStatements(computeService.getImage(node.getImageId()),config);
  if (!userCreation.statements.isEmpty()) {
    org.jclouds.compute.domain.OsFamily osFamily=node.getOperatingSystem().getFamily();
    org.jclouds.scriptbuilder.domain.OsFamily scriptOsFamily=(osFamily == org.jclouds.compute.domain.OsFamily.WINDOWS) ? org.jclouds.scriptbuilder.domain.OsFamily.WINDOWS : org.jclouds.scriptbuilder.domain.OsFamily.UNIX;
    List<String> commands=Lists.newArrayList();
    for (    Statement statement : userCreation.statements) {
      InitAdminAccess initAdminAccess=new InitAdminAccess(new AdminAccessConfiguration.Default());
      initAdminAccess.visit(statement);
      commands.add(statement.render(scriptOsFamily));
    }
    LoginCredentials initialCredentials=node.getCredentials();
    Optional<String> initialPassword=initialCredentials.getOptionalPassword();
    Optional<String> initialPrivateKey=initialCredentials.getOptionalPrivateKey();
    String initialUser=initialCredentials.getUser();
    String address=hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getHostText() : JcloudsUtil.getFirstReachableAddress(computeService.getContext(),node);
    int port=hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getPort() : node.getLoginPort();
    Map<String,Object> sshProps=Maps.newLinkedHashMap(config.getAllConfig());
    sshProps.put("String_Node_Str",initialUser);
    sshProps.put("String_Node_Str",address);
    sshProps.put("String_Node_Str",port);
    if (initialPassword.isPresent())     sshProps.put("String_Node_Str",initialPassword.get());
    if (initialPrivateKey.isPresent())     sshProps.put("String_Node_Str",initialPrivateKey.get());
    Map<String,Object> execProps=Maps.newLinkedHashMap();
    execProps.put(ShellTool.PROP_RUN_AS_ROOT.getName(),true);
    SshMachineLocation sshLoc=null;
    try {
      if (isManaged()) {
        sshLoc=getManagementContext().getLocationManager().createLocation(sshProps,SshMachineLocation.class);
      }
 else {
        sshLoc=new SshMachineLocation(sshProps);
      }
      int exitcode=sshLoc.execScript(execProps,"String_Node_Str",commands);
      if (exitcode != 0) {
        LOG.warn("String_Node_Str",exitcode,node);
      }
    }
  finally {
      getManagementContext().getLocationManager().unmanage(sshLoc);
      Streams.closeQuietly(sshLoc);
    }
  }
  return userCreation.loginCredentials;
}