Program: 6927
Project: 6927
Buggy source:
@Override public void runTask() throws Exception {
  updateTaskRunning=true;
  try {
    Set<Long> friendIds=new HashSet<Long>(rbnb.getUsersService().getMyUser().getFriendIds());
synchronized (LibraryService.this) {
      Iterator<Long> it=libs.keySet().iterator();
      while (it.hasNext()) {
        long libUid=it.next();
        if (!friendIds.contains(libUid))         it.remove();
      }
    }
    int friendsDone=0;
    for (    long friendId : friendIds) {
      completion=(float)friendsDone / friendIds.size();
      User u=rbnb.getUsersService().getUser(friendId);
      Library cLib;
      Set<String> newSidsForUi=new HashSet<String>();
synchronized (LibraryService.this) {
        cLib=libs.get(friendId);
        if (cLib == null) {
          cLib=rbnb.getDbService().getLibrary(friendId);
          if (cLib != null) {
            Map<String,Date> unknownSids=rbnb.getDbService().getUnknownStreamsInLibrary(friendId);
            for (            String uSid : unknownSids.keySet()) {
              cLib.getTracks().remove(uSid);
            }
            newSidsForUi.addAll(cLib.getTracks().keySet());
            libs.put(friendId,cLib);
          }
        }
      }
      statusText="String_Node_Str" + u.getEmail();
      fireUpdated();
      LibraryMsg.Builder b=LibraryMsg.newBuilder();
      MetadataServerConfig msc=rbnb.getUsersService().getMsc();
      Date lastUpdated=(cLib == null) ? null : cLib.getLastUpdated();
      try {
        rbnb.getSerializationManager().getObjectFromUrl(b,msc.getLibraryUrl(friendId,lastUpdated));
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
      lastUpdated=now();
      Library nLib=new Library(b.build());
      Map<String,Date> newTrax=nLib.getTracks();
      log.debug("String_Node_Str" + u.getEmail() + "String_Node_Str"+ newTrax.size()+ "String_Node_Str");
      if (newTrax.size() > 0) {
        rbnb.getDbService().addTracksToLibrary(friendId,newTrax);
synchronized (LibraryService.this) {
          if (cLib == null) {
            cLib=new Library();
            cLib.setUserId(friendId);
            cLib.setLastUpdated(lastUpdated);
            libs.put(friendId,cLib);
          }
 else           cLib.setLastUpdated(lastUpdated);
        }
      }
      Map<String,Date> unknownTracks=rbnb.getDbService().getUnknownStreamsInLibrary(friendId);
      if (unknownTracks.size() > 0) {
        log.debug("String_Node_Str" + unknownTracks.size() + "String_Node_Str"+ u.getEmail());
        Date lastFiredEvent=now();
        for (        String sid : unknownTracks.keySet()) {
          Stream s=rbnb.getMetadataService().getStream(sid);
          if (s == null) {
            if (rbnb.getStatus() == RobonoboStatus.Stopping)             return;
          }
 else           newSidsForUi.add(sid);
          if (newSidsForUi.size() > 0 && msElapsedSince(lastFiredEvent) > (FIRE_UI_EVENT_DELAY * 1000)) {
            for (            String newSid : newSidsForUi) {
              cLib.getTracks().put(newSid,unknownTracks.get(newSid));
            }
            rbnb.getEventService().fireLibraryChanged(cLib,newSidsForUi);
            newSidsForUi=new HashSet<String>();
            lastFiredEvent=now();
          }
        }
      }
      if (newSidsForUi.size() > 0) {
        for (        String newSid : newSidsForUi) {
          cLib.getTracks().put(newSid,unknownTracks.get(newSid));
        }
        rbnb.getEventService().fireLibraryChanged(cLib,newSidsForUi);
      }
    }
    statusText="String_Node_Str";
    completion=1f;
    fireUpdated();
  }
  finally {
    updateTaskRunning=false;
  }
}

Fixed version (ground truth):
@Override public void runTask() throws Exception {
  updateTaskRunning=true;
  try {
    Set<Long> friendIds=new HashSet<Long>(rbnb.getUsersService().getMyUser().getFriendIds());
synchronized (LibraryService.this) {
      Iterator<Long> it=libs.keySet().iterator();
      while (it.hasNext()) {
        long libUid=it.next();
        if (!friendIds.contains(libUid))         it.remove();
      }
    }
    int friendsDone=0;
    for (    long friendId : friendIds) {
      completion=(float)friendsDone / friendIds.size();
      User u=rbnb.getUsersService().getUser(friendId);
      Library cLib;
      Set<String> newSidsForUi=new HashSet<String>();
synchronized (LibraryService.this) {
        cLib=libs.get(friendId);
        if (cLib == null) {
          cLib=rbnb.getDbService().getLibrary(friendId);
          if (cLib != null) {
            Map<String,Date> unknownSids=rbnb.getDbService().getUnknownStreamsInLibrary(friendId);
            for (            String uSid : unknownSids.keySet()) {
              cLib.getTracks().remove(uSid);
            }
            newSidsForUi.addAll(cLib.getTracks().keySet());
            libs.put(friendId,cLib);
          }
        }
      }
      statusText="String_Node_Str" + u.getEmail();
      fireUpdated();
      LibraryMsg.Builder b=LibraryMsg.newBuilder();
      MetadataServerConfig msc=rbnb.getUsersService().getMsc();
      Date lastUpdated=(cLib == null) ? null : cLib.getLastUpdated();
      try {
        rbnb.getSerializationManager().getObjectFromUrl(b,msc.getLibraryUrl(friendId,lastUpdated));
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
      lastUpdated=now();
      Library nLib=new Library(b.build());
      Map<String,Date> newTrax=nLib.getTracks();
      log.debug("String_Node_Str" + u.getEmail() + "String_Node_Str"+ newTrax.size()+ "String_Node_Str");
      if (newTrax.size() > 0) {
        rbnb.getDbService().addTracksToLibrary(friendId,newTrax);
synchronized (LibraryService.this) {
          if (cLib == null) {
            cLib=new Library();
            cLib.setUserId(friendId);
            cLib.setLastUpdated(lastUpdated);
            libs.put(friendId,cLib);
          }
 else           cLib.setLastUpdated(lastUpdated);
        }
      }
      Map<String,Date> unknownTracks=rbnb.getDbService().getUnknownStreamsInLibrary(friendId);
      for (      Entry<String,Date> entry : newTrax.entrySet()) {
        String sid=entry.getKey();
        Date dateAdded=entry.getValue();
        if (!unknownTracks.containsKey(sid)) {
          cLib.getTracks().put(sid,dateAdded);
          newSidsForUi.add(sid);
        }
      }
      if (unknownTracks.size() > 0) {
        log.debug("String_Node_Str" + unknownTracks.size() + "String_Node_Str"+ u.getEmail());
        Date lastFiredEvent=now();
        for (        String sid : unknownTracks.keySet()) {
          Stream s=rbnb.getMetadataService().getStream(sid);
          if (s == null) {
            if (rbnb.getStatus() == RobonoboStatus.Stopping)             return;
          }
 else           newSidsForUi.add(sid);
          if (newSidsForUi.size() > 0 && msElapsedSince(lastFiredEvent) > (FIRE_UI_EVENT_DELAY * 1000)) {
            for (            String newSid : newSidsForUi) {
              cLib.getTracks().put(newSid,unknownTracks.get(newSid));
            }
            rbnb.getEventService().fireLibraryChanged(cLib,newSidsForUi);
            newSidsForUi=new HashSet<String>();
            lastFiredEvent=now();
          }
        }
      }
      if (newSidsForUi.size() > 0) {
        for (        String newSid : newSidsForUi) {
          cLib.getTracks().put(newSid,unknownTracks.get(newSid));
        }
        rbnb.getEventService().fireLibraryChanged(cLib,newSidsForUi);
      }
    }
    statusText="String_Node_Str";
    completion=1f;
    fireUpdated();
  }
  finally {
    updateTaskRunning=false;
  }
}