Program: 39951
Project: 39951
Buggy source:
public FormValidation doServerCheck(@QueryParameter final String server,@QueryParameter final String managerDN,@QueryParameter final String managerPassword){
  if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
    return FormValidation.ok();
  }
  try {
    Hashtable<String,String> props=new Hashtable<String,String>();
    if (managerDN != null && managerDN.trim().length() > 0 && !"String_Node_Str".equals(managerDN)) {
      props.put(Context.SECURITY_PRINCIPAL,managerDN);
    }
    if (managerPassword != null && managerPassword.trim().length() > 0 && !"String_Node_Str".equals(managerPassword)) {
      props.put(Context.SECURITY_CREDENTIALS,managerPassword);
    }
    props.put(Context.INITIAL_CONTEXT_FACTORY,"String_Node_Str");
    props.put(Context.PROVIDER_URL,toProviderUrl(server,"String_Node_Str"));
    DirContext ctx=new InitialDirContext(props);
    ctx.getAttributes("String_Node_Str");
    return FormValidation.ok();
  }
 catch (  NamingException e) {
    Matcher m=Pattern.compile("String_Node_Str").matcher(server.trim());
    if (!m.matches())     return FormValidation.error(hudson.security.Messages.LDAPSecurityRealm_SyntaxOfServerField());
    try {
      InetAddress adrs=InetAddress.getByName(m.group(2));
      int port=m.group(1) != null ? 636 : 389;
      if (m.group(3) != null)       port=Integer.parseInt(m.group(3));
      Socket s=new Socket(adrs,port);
      s.close();
    }
 catch (    UnknownHostException x) {
      return FormValidation.error(hudson.security.Messages.LDAPSecurityRealm_UnknownHost(x.getMessage()));
    }
catch (    IOException x) {
      return FormValidation.error(x,hudson.security.Messages.LDAPSecurityRealm_UnableToConnect(server,x.getMessage()));
    }
    return FormValidation.error(e,hudson.security.Messages.LDAPSecurityRealm_UnableToConnect(server,e));
  }
catch (  NumberFormatException x) {
    return FormValidation.error(hudson.security.Messages.LDAPSecurityRealm_InvalidPortNumber());
  }
}

Fixed version (ground truth):
public FormValidation doServerCheck(@QueryParameter final String server,@QueryParameter final String managerDN,@QueryParameter final String managerPassword){
  final String trimmedServer=fixEmptyAndTrim(server);
  if (trimmedServer == null) {
    return FormValidation.error("String_Node_Str");
  }
  if (!Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)) {
    return FormValidation.ok();
  }
  try {
    Hashtable<String,String> props=new Hashtable<String,String>();
    if (managerDN != null && managerDN.trim().length() > 0 && !"String_Node_Str".equals(managerDN)) {
      props.put(Context.SECURITY_PRINCIPAL,managerDN);
    }
    if (managerPassword != null && managerPassword.trim().length() > 0 && !"String_Node_Str".equals(managerPassword)) {
      props.put(Context.SECURITY_CREDENTIALS,managerPassword);
    }
    props.put(Context.INITIAL_CONTEXT_FACTORY,"String_Node_Str");
    props.put(Context.PROVIDER_URL,toProviderUrl(trimmedServer,"String_Node_Str"));
    DirContext ctx=new InitialDirContext(props);
    ctx.getAttributes("String_Node_Str");
    return FormValidation.ok();
  }
 catch (  NamingException e) {
    Matcher m=Pattern.compile("String_Node_Str").matcher(trimmedServer.trim());
    if (!m.matches())     return FormValidation.error(hudson.security.Messages.LDAPSecurityRealm_SyntaxOfServerField());
    try {
      InetAddress adrs=InetAddress.getByName(m.group(2));
      int port=m.group(1) != null ? 636 : 389;
      if (m.group(3) != null)       port=Integer.parseInt(m.group(3));
      Socket s=new Socket(adrs,port);
      s.close();
    }
 catch (    UnknownHostException x) {
      return FormValidation.error(hudson.security.Messages.LDAPSecurityRealm_UnknownHost(x.getMessage()));
    }
catch (    IOException x) {
      return FormValidation.error(x,hudson.security.Messages.LDAPSecurityRealm_UnableToConnect(trimmedServer,x.getMessage()));
    }
    return FormValidation.error(e,hudson.security.Messages.LDAPSecurityRealm_UnableToConnect(trimmedServer,e));
  }
catch (  NumberFormatException x) {
    return FormValidation.error(hudson.security.Messages.LDAPSecurityRealm_InvalidPortNumber());
  }
}