Program: 167748
Project: 167748
Buggy source:
@Override public LdapEntry[] search(LdapConnectionHandler originalConnectionHandler,LdapEntry entry) throws IOException, NamingException {
  Set<LdapEntry> foundEntries=new HashSet<LdapEntry>();
  LdapConnectionHandler connectionHandler=originalConnectionHandler;
  URI originalReferralAddress=null;
  if ((originalReferralAddress=entry.getReferralUri()) != null) {
    connectionHandler=connectionHandler.findForReferral(originalReferralAddress);
    if (connectionHandler == null) {
      SECURITY_LOGGER.tracef("String_Node_Str",originalReferralAddress);
      return foundEntries.toArray(new LdapEntry[foundEntries.size()]);
    }
  }
  DirContext dirContext=connectionHandler.getConnection();
  Attributes groups=dirContext.getAttributes(entry.getDistinguishedName(),new String[]{groupAttribute});
  Attribute groupRef=groups.get(groupAttribute);
  if (preferOriginalConnection) {
    connectionHandler=originalConnectionHandler;
    originalReferralAddress=null;
  }
  if (groupRef != null && groupRef.size() > 0) {
    NamingEnumeration<String> groupRefValues=(NamingEnumeration<String>)groupRef.getAll();
    while (groupRefValues.hasMore()) {
      String distingushedName=groupRefValues.next().replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str");
      SECURITY_LOGGER.tracef("String_Node_Str",distingushedName);
      LdapConnectionHandler groupLoadHandler=connectionHandler;
      URI groupReferralAddress=originalReferralAddress;
      boolean retry=false;
      String simpleName=null;
      do {
        retry=false;
        try {
          dirContext=groupLoadHandler.getConnection();
          Attributes groupNameAttrs=dirContext.getAttributes(distingushedName,groupNameAttribute != null ? new String[]{groupNameAttribute} : new String[]{});
          if (groupNameAttribute != null) {
            Attribute groupNameAttr=groupNameAttrs.get(groupNameAttribute);
            simpleName=(String)groupNameAttr.get();
            SECURITY_LOGGER.tracef("String_Node_Str",simpleName,distingushedName);
          }
 else {
            SECURITY_LOGGER.trace("String_Node_Str");
          }
          foundEntries.add(new LdapEntry(simpleName,distingushedName,groupReferralAddress));
        }
 catch (        LdapReferralException e) {
          Object info=e.getReferralInfo();
          try {
            URI fullUri=new URI(info.toString());
            groupReferralAddress=new URI(fullUri.getScheme(),null,fullUri.getHost(),fullUri.getPort(),null,null,null);
            distingushedName=fullUri.getPath().substring(1);
            SECURITY_LOGGER.tracef("String_Node_Str",groupReferralAddress.toString(),distingushedName);
            groupLoadHandler=groupLoadHandler.findForReferral(groupReferralAddress);
            if (groupLoadHandler == null) {
              SECURITY_LOGGER.tracef("String_Node_Str",fullUri);
            }
            retry=true;
          }
 catch (          URISyntaxException ue) {
            SECURITY_LOGGER.tracef("String_Node_Str",info);
          }
        }
      }
 while (retry);
    }
  }
 else {
    SECURITY_LOGGER.tracef("String_Node_Str",entry);
  }
  return foundEntries.toArray(new LdapEntry[foundEntries.size()]);
}

Fixed version (ground truth):
@Override public LdapEntry[] search(LdapConnectionHandler originalConnectionHandler,LdapEntry entry) throws IOException, NamingException {
  Set<LdapEntry> foundEntries=new HashSet<LdapEntry>();
  LdapConnectionHandler connectionHandler=originalConnectionHandler;
  URI originalReferralAddress=null;
  if ((originalReferralAddress=entry.getReferralUri()) != null) {
    connectionHandler=connectionHandler.findForReferral(originalReferralAddress);
    if (connectionHandler == null) {
      SECURITY_LOGGER.tracef("String_Node_Str",originalReferralAddress);
      return foundEntries.toArray(new LdapEntry[foundEntries.size()]);
    }
  }
  DirContext dirContext=connectionHandler.getConnection();
  Attributes groups=dirContext.getAttributes(entry.getDistinguishedName(),new String[]{groupAttribute});
  Attribute groupRef=groups.get(groupAttribute);
  if (preferOriginalConnection) {
    connectionHandler=originalConnectionHandler;
    originalReferralAddress=null;
  }
  if (groupRef != null && groupRef.size() > 0) {
    NamingEnumeration<String> groupRefValues=(NamingEnumeration<String>)groupRef.getAll();
    while (groupRefValues.hasMore()) {
      String distingushedName=groupRefValues.next().replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str");
      SECURITY_LOGGER.tracef("String_Node_Str",distingushedName);
      LdapConnectionHandler groupLoadHandler=connectionHandler;
      URI groupReferralAddress=originalReferralAddress;
      boolean retry=false;
      String simpleName=null;
      do {
        retry=false;
        try {
          dirContext=groupLoadHandler.getConnection();
          Attributes groupNameAttrs=dirContext.getAttributes(distingushedName,groupNameAttribute != null ? new String[]{groupNameAttribute} : new String[]{});
          if (groupNameAttribute != null) {
            Attribute groupNameAttr=groupNameAttrs.get(groupNameAttribute);
            simpleName=(String)groupNameAttr.get();
            SECURITY_LOGGER.tracef("String_Node_Str",simpleName,distingushedName);
          }
 else {
            SECURITY_LOGGER.trace("String_Node_Str");
          }
          foundEntries.add(new LdapEntry(simpleName,distingushedName,groupReferralAddress));
        }
 catch (        NameNotFoundException e) {
          SECURITY_LOGGER.tracef("String_Node_Str",e.getMessage());
          if (!this.IGNORE_NONEXISTENT_ROLE)           throw e;
        }
catch (        LdapReferralException e) {
          Object info=e.getReferralInfo();
          try {
            URI fullUri=new URI(info.toString());
            groupReferralAddress=new URI(fullUri.getScheme(),null,fullUri.getHost(),fullUri.getPort(),null,null,null);
            distingushedName=fullUri.getPath().substring(1);
            SECURITY_LOGGER.tracef("String_Node_Str",groupReferralAddress.toString(),distingushedName);
            groupLoadHandler=groupLoadHandler.findForReferral(groupReferralAddress);
            if (groupLoadHandler == null) {
              SECURITY_LOGGER.tracef("String_Node_Str",fullUri);
            }
            retry=true;
          }
 catch (          URISyntaxException ue) {
            SECURITY_LOGGER.tracef("String_Node_Str",info);
          }
        }
      }
 while (retry);
    }
  }
 else {
    SECURITY_LOGGER.tracef("String_Node_Str",entry);
  }
  return foundEntries.toArray(new LdapEntry[foundEntries.size()]);
}