Program: 103005
Project: 103005
Buggy source:
/** 
 * Tries to resolves a peer address into a display name, by reqesting the <tt>ContactSourceService</tt>s. This function returns only the first match.
 * @param peerAddress The peer address.
 * @return The corresponding display name, if there is a match. Nullotherwise.
 */
private static String resolveContactSource(String peerAddress){
  String displayName=null;
  if (!StringUtils.isNullOrEmpty(peerAddress)) {
    Vector<ResolveAddressToDisplayNameContactQueryListener> resolvers=new Vector<ResolveAddressToDisplayNameContactQueryListener>(1,1);
    int index=peerAddress.indexOf("String_Node_Str");
    String peerUserID=(index > -1) ? peerAddress.substring(0,index) : peerAddress;
    peerUserID=Pattern.quote(peerUserID);
    Pattern pattern=Pattern.compile("String_Node_Str" + peerUserID + "String_Node_Str"+ peerUserID+ "String_Node_Str");
    for (    ContactSourceService contactSourceService : GuiActivator.getContactSources()) {
      if (!(contactSourceService instanceof ExtendedContactSourceService))       continue;
      ContactQuery query=((ExtendedContactSourceService)contactSourceService).queryContactSource(pattern);
      resolvers.add(new ResolveAddressToDisplayNameContactQueryListener(query));
    }
    long startTime=System.currentTimeMillis();
    long currentTime=startTime;
    long timeout=500;
    while (displayName == null && currentTime - startTime < timeout) {
      for (int i=0; i < resolvers.size() && displayName == null; ++i) {
        ResolveAddressToDisplayNameContactQueryListener resolver=resolvers.get(i);
        if (!resolver.isRunning()) {
          if (resolver.isFound()) {
            displayName=resolver.getResolvedName();
            if (displayName.equals(peerAddress)) {
              displayName=null;
            }
          }
        }
      }
      Thread.yield();
      currentTime=System.currentTimeMillis();
    }
    for (int i=0; i < resolvers.size(); ++i) {
      ResolveAddressToDisplayNameContactQueryListener resolver=resolvers.get(i);
      if (resolver.isRunning()) {
        resolver.stop();
      }
    }
  }
  return displayName;
}

Fixed version (ground truth):
/** 
 * Tries to resolves a peer address into a display name, by reqesting the <tt>ContactSourceService</tt>s. This function returns only the first match.
 * @param peerAddress The peer address.
 * @return The corresponding display name, if there is a match. Nullotherwise.
 */
private static String resolveContactSource(String peerAddress){
  String displayName=null;
  if (!StringUtils.isNullOrEmpty(peerAddress)) {
    Vector<ResolveAddressToDisplayNameContactQueryListener> resolvers=new Vector<ResolveAddressToDisplayNameContactQueryListener>(1,1);
    int index=peerAddress.indexOf("String_Node_Str");
    String peerUserID=(index > -1) ? peerAddress.substring(0,index) : peerAddress;
    peerUserID=Pattern.quote(peerUserID);
    Pattern pattern=Pattern.compile("String_Node_Str" + peerUserID + "String_Node_Str"+ peerUserID+ "String_Node_Str");
    for (    ContactSourceService contactSourceService : GuiActivator.getContactSources()) {
      if (!(contactSourceService instanceof ExtendedContactSourceService))       continue;
      ContactQuery query=((ExtendedContactSourceService)contactSourceService).createContactQuery(pattern);
      resolvers.add(new ResolveAddressToDisplayNameContactQueryListener(query));
      query.start();
    }
    long startTime=System.currentTimeMillis();
    long currentTime=startTime;
    long timeout=500;
    while (displayName == null && currentTime - startTime < timeout) {
      for (int i=0; i < resolvers.size() && displayName == null; ++i) {
        ResolveAddressToDisplayNameContactQueryListener resolver=resolvers.get(i);
        if (!resolver.isRunning()) {
          if (resolver.isFound()) {
            displayName=resolver.getResolvedName();
            if (displayName.equals(peerAddress)) {
              displayName=null;
            }
          }
        }
      }
      Thread.yield();
      currentTime=System.currentTimeMillis();
    }
    for (int i=0; i < resolvers.size(); ++i) {
      ResolveAddressToDisplayNameContactQueryListener resolver=resolvers.get(i);
      if (resolver.isRunning()) {
        resolver.stop();
      }
    }
  }
  return displayName;
}