Program: 29250
Project: 29250
Buggy source:
/** 
 * This method will try to execute the command repeatedly, for example, retrying with updated credentials (typically from the interactive user), etc., until the command succeeds or there are no more ways to retry that might succeed.
 */
private Response doRestCommand(ParameterMap options,String pathSufix,String method,boolean isForMetadata,MediaType... acceptedResponseTypes) throws CommandException {
  Metrix.event("String_Node_Str");
  boolean shouldTryCommandAgain;
  boolean shouldSendCredentials=secure;
  boolean askedUserForCredentials=false;
  boolean shouldUseSecure=secure;
  boolean usedCallerProvidedCredentials=secure;
  URI uri=createURI(shouldUseSecure,pathSufix);
  do {
    Metrix.event("String_Node_Str");
    WebTarget target=client.target(uri);
    Metrix.event("String_Node_Str");
    target.configuration().setProperty(ClientProperties.HOSTNAME_VERIFIER,new BasicHostnameVerifier(host)).setProperty(ClientProperties.SSL_CONTEXT,getSslContext());
    shouldTryCommandAgain=false;
    try {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",uri.toString());
        logger.log(Level.FINER,"String_Node_Str",new Object[]{user,ok(password) ? "String_Node_Str" : "String_Node_Str"});
      }
      final AuthenticationInfo authInfo=authenticationInfo();
      if (authInfo != null && shouldSendCredentials) {
        HttpBasicAuthFilter besicAuth=new HttpBasicAuthFilter(authInfo.getUser(),authInfo.getPassword() == null ? "String_Node_Str" : authInfo.getPassword());
        target.configuration().register(besicAuth);
      }
      Metrix.event("String_Node_Str");
      Builder request=target.request(acceptedResponseTypes);
      Metrix.event("String_Node_Str");
      if (authToken != null) {
        request=request.header(SecureAdmin.Util.ADMIN_ONE_TIME_AUTH_TOKEN_HEADER_NAME,(isForMetadata ? AuthTokenManager.markTokenForReuse(authToken) : authToken));
      }
      if (commandModel != null && isCommandModelFromCache() && commandModel instanceof CachedCommandModel) {
        request=request.header(COMMAND_MODEL_MATCH_HEADER,((CachedCommandModel)commandModel).getETag());
        if (logger.isLoggable(Level.FINER)) {
          logger.log(Level.FINER,"String_Node_Str",((CachedCommandModel)commandModel).getETag());
        }
      }
      for (      Header h : requestHeaders) {
        request=request.header(h.getName(),h.getValue());
      }
      request=addAdditionalHeaders(request);
      if (logger.isLoggable(Level.FINER)) {
        request=request.header("String_Node_Str","String_Node_Str");
      }
      Invocation invoc=null;
      Metrix.event("String_Node_Str");
      if ("String_Node_Str".equals(method)) {
        if (outboundPayload != null && outboundPayload.size() > 0) {
          FormDataMultiPart mp=new FormDataMultiPart();
          for (          Map.Entry<String,List<String>> entry : options.entrySet()) {
            String key=entry.getKey();
            for (            String val : entry.getValue()) {
              mp.field(key,val);
            }
          }
          outboundPayload.addToMultipart(mp,logger);
          Entity<FormDataMultiPart> entity=Entity.<FormDataMultiPart>entity(mp,mp.getMediaType());
          invoc=request.build(method,entity);
        }
 else {
          Entity<ParameterMap> entity=Entity.<ParameterMap>entity(options,MediaType.APPLICATION_FORM_URLENCODED_TYPE);
          invoc=request.build(method,entity);
        }
      }
 else {
        invoc=request.build(method);
      }
      Metrix.event("String_Node_Str");
      Response response=invoc.invoke();
      Metrix.event("String_Node_Str");
      String redirection=checkConnect(response,uri.getHost(),uri.getPort());
      if (ok(redirection)) {
        if (logger.isLoggable(Level.FINER)) {
          logger.log(Level.FINER,"String_Node_Str",redirection);
        }
        uri=new URI(redirection);
        shouldTryCommandAgain=true;
        shouldUseSecure="String_Node_Str".equals(uri.getScheme());
        secure=true;
        shouldSendCredentials=shouldUseSecure;
        continue;
      }
      processHeaders(response);
      logger.finer("String_Node_Str");
      return response;
    }
 catch (    AuthenticationException authEx) {
      logger.log(Level.FINER,"String_Node_Str");
      if (!usedCallerProvidedCredentials) {
        logger.log(Level.FINER,"String_Node_Str");
        usedCallerProvidedCredentials=true;
        shouldSendCredentials=true;
        shouldTryCommandAgain=true;
        continue;
      }
      logger.log(Level.FINER,"String_Node_Str");
      if (askedUserForCredentials) {
        logger.log(Level.FINER,"String_Node_Str");
        throw authEx;
      }
      logger.log(Level.FINER,"String_Node_Str");
      if (!updateAuthentication()) {
        logger.log(Level.FINER,"String_Node_Str");
        throw authEx;
      }
      logger.log(Level.FINER,"String_Node_Str");
      askedUserForCredentials=true;
      shouldSendCredentials=true;
      shouldTryCommandAgain=true;
      continue;
    }
catch (    ConnectException ce) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",ce);
      }
      String msg=strings.get("String_Node_Str",host,port + "String_Node_Str");
      throw new CommandException(msg,ce);
    }
catch (    UnknownHostException he) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",he);
      }
      String msg=strings.get("String_Node_Str",host);
      throw new CommandException(msg,he);
    }
catch (    SocketException se) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",se);
      }
      try {
        boolean serverAppearsSecure=NetUtils.isSecurePort(host,port);
        if (serverAppearsSecure && !shouldUseSecure) {
          if (retryUsingSecureConnection(host,port)) {
            shouldUseSecure=true;
            shouldSendCredentials=true;
            usedCallerProvidedCredentials=true;
            shouldTryCommandAgain=true;
            continue;
          }
        }
        throw new CommandException(se);
      }
 catch (      IOException io) {
        throw new CommandException(io);
      }
    }
catch (    SSLException se) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",se);
      }
      try {
        boolean serverAppearsSecure=NetUtils.isSecurePort(host,port);
        if (!serverAppearsSecure && secure) {
          logger.severe(strings.get("String_Node_Str",host,port + "String_Node_Str"));
        }
        throw new CommandException(se);
      }
 catch (      IOException io) {
        throw new CommandException(io);
      }
    }
catch (    SocketTimeoutException e) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",e);
      }
      throw new CommandException(strings.get("String_Node_Str",(float)readTimeout / 1000),e);
    }
catch (    IOException e) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",e);
      }
      throw new CommandException(strings.get("String_Node_Str",e.getMessage()),e);
    }
catch (    CommandException e) {
      throw e;
    }
catch (    Exception e) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",e);
      }
      ByteArrayOutputStream buf=new ByteArrayOutputStream();
      e.printStackTrace(new PrintStream(buf));
      logger.finer(buf.toString());
      throw new CommandException(e);
    }
  }
 while (shouldTryCommandAgain);
  outboundPayload=null;
  return null;
}

Fixed version (ground truth):
/** 
 * This method will try to execute the command repeatedly, for example, retrying with updated credentials (typically from the interactive user), etc., until the command succeeds or there are no more ways to retry that might succeed.
 */
private Response doRestCommand(ParameterMap options,String pathSufix,String method,boolean isForMetadata,MediaType... acceptedResponseTypes) throws CommandException {
  Metrix.event("String_Node_Str");
  boolean shouldTryCommandAgain;
  boolean shouldSendCredentials=secure;
  boolean askedUserForCredentials=false;
  boolean shouldUseSecure=secure;
  boolean usedCallerProvidedCredentials=secure;
  URI uri=createURI(shouldUseSecure,pathSufix);
  do {
    Metrix.event("String_Node_Str");
    WebTarget target=client.target(uri);
    Metrix.event("String_Node_Str");
    target.configuration().setProperty(ClientProperties.HOSTNAME_VERIFIER,new BasicHostnameVerifier(host)).setProperty(ClientProperties.SSL_CONTEXT,getSslContext());
    shouldTryCommandAgain=false;
    try {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",uri.toString());
        logger.log(Level.FINER,"String_Node_Str",new Object[]{user,ok(password) ? "String_Node_Str" : "String_Node_Str"});
      }
      final AuthenticationInfo authInfo=authenticationInfo();
      if (authInfo != null && shouldSendCredentials) {
        HttpBasicAuthFilter besicAuth=new HttpBasicAuthFilter(authInfo.getUser(),authInfo.getPassword() == null ? "String_Node_Str" : authInfo.getPassword());
        target.configuration().register(besicAuth);
      }
      Metrix.event("String_Node_Str");
      Builder request=target.request(acceptedResponseTypes);
      Metrix.event("String_Node_Str");
      if (authToken != null) {
        request=request.header(SecureAdmin.Util.ADMIN_ONE_TIME_AUTH_TOKEN_HEADER_NAME,(isForMetadata ? AuthTokenManager.markTokenForReuse(authToken) : authToken));
      }
      if (commandModel != null && isCommandModelFromCache() && commandModel instanceof CachedCommandModel) {
        request=request.header(COMMAND_MODEL_MATCH_HEADER,((CachedCommandModel)commandModel).getETag());
        if (logger.isLoggable(Level.FINER)) {
          logger.log(Level.FINER,"String_Node_Str",((CachedCommandModel)commandModel).getETag());
        }
      }
      for (      Header h : requestHeaders) {
        request=request.header(h.getName(),h.getValue());
      }
      request=addAdditionalHeaders(request);
      if (logger.isLoggable(Level.FINER)) {
        request=request.header("String_Node_Str","String_Node_Str");
      }
      Invocation invoc=null;
      Metrix.event("String_Node_Str");
      if ("String_Node_Str".equals(method)) {
        if (outboundPayload != null && outboundPayload.size() > 0) {
          FormDataMultiPart mp=new FormDataMultiPart();
          for (          Map.Entry<String,List<String>> entry : options.entrySet()) {
            String key=entry.getKey();
            for (            String val : entry.getValue()) {
              mp.field(key,val);
            }
          }
          outboundPayload.addToMultipart(mp,logger);
          Entity<FormDataMultiPart> entity=Entity.<FormDataMultiPart>entity(mp,mp.getMediaType());
          invoc=request.build(method,entity);
        }
 else {
          Entity<ParameterMap> entity=Entity.<ParameterMap>entity(options,MediaType.APPLICATION_FORM_URLENCODED_TYPE);
          invoc=request.build(method,entity);
        }
      }
 else {
        invoc=request.build(method);
      }
      Metrix.event("String_Node_Str");
      Response response;
      try {
        response=invoc.invoke();
      }
 catch (      ClientException ex) {
        if (ex.getCause() != null && ex.getCause() instanceof Exception) {
          throw (Exception)ex.getCause();
        }
 else {
          throw ex;
        }
      }
      Metrix.event("String_Node_Str");
      String redirection=checkConnect(response,uri.getHost(),uri.getPort());
      if (ok(redirection)) {
        if (logger.isLoggable(Level.FINER)) {
          logger.log(Level.FINER,"String_Node_Str",redirection);
        }
        uri=new URI(redirection);
        shouldTryCommandAgain=true;
        shouldUseSecure="String_Node_Str".equals(uri.getScheme());
        secure=true;
        shouldSendCredentials=shouldUseSecure;
        continue;
      }
      processHeaders(response);
      logger.finer("String_Node_Str");
      return response;
    }
 catch (    AuthenticationException authEx) {
      logger.log(Level.FINER,"String_Node_Str");
      if (!usedCallerProvidedCredentials) {
        logger.log(Level.FINER,"String_Node_Str");
        usedCallerProvidedCredentials=true;
        shouldSendCredentials=true;
        shouldTryCommandAgain=true;
        continue;
      }
      logger.log(Level.FINER,"String_Node_Str");
      if (askedUserForCredentials) {
        logger.log(Level.FINER,"String_Node_Str");
        throw authEx;
      }
      logger.log(Level.FINER,"String_Node_Str");
      if (!updateAuthentication()) {
        logger.log(Level.FINER,"String_Node_Str");
        throw authEx;
      }
      logger.log(Level.FINER,"String_Node_Str");
      askedUserForCredentials=true;
      shouldSendCredentials=true;
      shouldTryCommandAgain=true;
      continue;
    }
catch (    ConnectException ce) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",ce);
      }
      String msg=strings.get("String_Node_Str",host,port + "String_Node_Str");
      throw new CommandException(msg,ce);
    }
catch (    UnknownHostException he) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",he);
      }
      String msg=strings.get("String_Node_Str",host);
      throw new CommandException(msg,he);
    }
catch (    SocketException se) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",se);
      }
      try {
        boolean serverAppearsSecure=NetUtils.isSecurePort(host,port);
        if (serverAppearsSecure && !shouldUseSecure) {
          if (retryUsingSecureConnection(host,port)) {
            shouldUseSecure=true;
            shouldSendCredentials=true;
            usedCallerProvidedCredentials=true;
            shouldTryCommandAgain=true;
            continue;
          }
        }
        throw new CommandException(se);
      }
 catch (      IOException io) {
        throw new CommandException(io);
      }
    }
catch (    SSLException se) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",se);
      }
      try {
        boolean serverAppearsSecure=NetUtils.isSecurePort(host,port);
        if (!serverAppearsSecure && secure) {
          logger.severe(strings.get("String_Node_Str",host,port + "String_Node_Str"));
        }
        throw new CommandException(se);
      }
 catch (      IOException io) {
        throw new CommandException(io);
      }
    }
catch (    SocketTimeoutException e) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",e);
      }
      throw new CommandException(strings.get("String_Node_Str",(float)readTimeout / 1000),e);
    }
catch (    IOException e) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",e);
      }
      throw new CommandException(strings.get("String_Node_Str",e.getMessage()),e);
    }
catch (    CommandException e) {
      throw e;
    }
catch (    Exception e) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"String_Node_Str",e);
      }
      ByteArrayOutputStream buf=new ByteArrayOutputStream();
      e.printStackTrace(new PrintStream(buf));
      logger.finer(buf.toString());
      throw new CommandException(e);
    }
  }
 while (shouldTryCommandAgain);
  outboundPayload=null;
  return null;
}