Program: 87134
Project: 87134
Buggy source:
/** 
 * Sends weekly notification emails for all users.
 * @param dayDelta : Day from which to aggregate, delta from now.
 * @param handler : Handles the results, emails sent / users KO
 */
public void sendWeeklyMails(int dayDelta,final Handler<Either<String,JsonObject>> handler){
  final HttpServerRequest request=new JsonHttpServerRequest(new JsonObject());
  final AtomicInteger userPagination=new AtomicInteger(0);
  final Calendar weekDate=Calendar.getInstance();
  weekDate.add(Calendar.DAY_OF_MONTH,dayDelta - 6);
  weekDate.set(Calendar.HOUR_OF_DAY,0);
  weekDate.set(Calendar.MINUTE,0);
  weekDate.set(Calendar.SECOND,0);
  weekDate.set(Calendar.MILLISECOND,0);
  final JsonObject results=new JsonObject().putNumber("String_Node_Str",0).putNumber("String_Node_Str",0);
  final JsonObject notificationsDefaults=new JsonObject();
  final Handler<Boolean> userContinuationHandler=new Handler<Boolean>(){
    private final Handler<Boolean> continuation=this;
    private final Handler<JsonArray> usersHandler=new Handler<JsonArray>(){
      public void handle(      final JsonArray users){
        final int nbUsers=users.size();
        if (nbUsers == 0) {
          continuation.handle(false);
          return;
        }
        final AtomicInteger usersCountdown=new AtomicInteger(nbUsers);
        final VoidHandler usersEndHandler=new VoidHandler(){
          protected void handle(){
            if (usersCountdown.decrementAndGet() <= 0) {
              continuation.handle(nbUsers == USERS_LIMIT);
            }
          }
        }
;
        final JsonArray userIds=new JsonArray();
        for (        Object userObj : users)         userIds.add(((JsonObject)userObj).getString("String_Node_Str","String_Node_Str"));
        getUsersPreferences(userIds,new Handler<JsonArray>(){
          public void handle(          JsonArray preferences){
            int i=0;
            for (            Object userObj : users) {
              final JsonObject user=(JsonObject)userObj;
              final JsonObject userPrefs=(JsonObject)preferences.get(i);
              getAggregatedUserNotifications(user.getString("String_Node_Str","String_Node_Str"),weekDate.getTime(),new Handler<JsonArray>(){
                public void handle(                JsonArray notifications){
                  if (notifications.size() == 0) {
                    usersEndHandler.handle(null);
                    return;
                  }
                  final JsonArray weeklyNotifications=new JsonArray();
                  for (                  Object notificationObj : notifications) {
                    JsonObject notification=(JsonObject)notificationObj;
                    final String notificationName=notification.getString("String_Node_Str","String_Node_Str").toLowerCase() + "String_Node_Str" + notification.getString("String_Node_Str","String_Node_Str").toLowerCase();
                    if (notificationsDefaults.getObject(notificationName) == null)                     continue;
                    JsonObject notificationPreference=userPrefs.getObject("String_Node_Str",new JsonObject()).getObject("String_Node_Str",new JsonObject()).getObject(notificationName,new JsonObject());
                    if (TimelineNotificationsLoader.Frequencies.WEEKLY.name().equals(notificationPrefsMixin("String_Node_Str",notificationPreference,notificationsDefaults.getObject(notificationName))) && !TimelineNotificationsLoader.Restrictions.INTERNAL.name().equals(notificationPrefsMixin("String_Node_Str",notificationPreference,notificationsDefaults.getObject(notificationName)))) {
                      notification.putString("String_Node_Str",notificationName);
                      weeklyNotifications.add(notification);
                    }
                  }
                  final JsonObject weeklyNotificationsObj=new JsonObject();
                  final JsonArray weeklyNotificationsGroupedArray=new JsonArray();
                  for (                  Object notif : weeklyNotifications) {
                    JsonObject notification=(JsonObject)notif;
                    if (!weeklyNotificationsObj.containsField(notification.getString("String_Node_Str").toLowerCase()))                     weeklyNotificationsObj.putObject(notification.getString("String_Node_Str").toLowerCase(),new JsonObject().putString("String_Node_Str",notificationsDefaults.getObject(notification.getString("String_Node_Str")).getString("String_Node_Str","String_Node_Str")).putArray("String_Node_Str",new JsonArray()));
                    weeklyNotificationsObj.getObject(notification.getString("String_Node_Str").toLowerCase()).getArray(("String_Node_Str"),new JsonArray()).add(notification);
                  }
                  for (                  String key : weeklyNotificationsObj.toMap().keySet()) {
                    weeklyNotificationsGroupedArray.add(new JsonObject().putString("String_Node_Str",key).putString("String_Node_Str",weeklyNotificationsObj.getObject(key).getString("String_Node_Str","String_Node_Str")).putArray("String_Node_Str",weeklyNotificationsObj.getObject(key).getArray("String_Node_Str")));
                  }
                  if (weeklyNotifications.size() > 0) {
                    JsonObject templateParams=new JsonObject().putArray("String_Node_Str",weeklyNotificationsGroupedArray);
                    processTimelineTemplate(templateParams,"String_Node_Str","String_Node_Str",new Handler<String>(){
                      public void handle(                      final String processedTemplate){
                        final Handler<Message<JsonObject>> completionHandler=new Handler<Message<JsonObject>>(){
                          public void handle(                          Message<JsonObject> event){
                            if ("String_Node_Str".equals(event.body().getString("String_Node_Str","String_Node_Str"))) {
                              log.error("String_Node_Str" + event.body());
                              results.putNumber("String_Node_Str",results.getInteger("String_Node_Str") + 1);
                            }
 else {
                              results.putNumber("String_Node_Str",results.getInteger("String_Node_Str") + 1);
                            }
                            usersEndHandler.handle(null);
                          }
                        }
;
                        JsonArray keys=new JsonArray().add("String_Node_Str");
                        translateTimeline(keys,"String_Node_Str",new Handler<JsonArray>(){
                          public void handle(                          JsonArray translations){
                            emailSender.sendEmail(request,user.getString("String_Node_Str","String_Node_Str"),null,null,translations.get(0).toString(),processedTemplate,null,false,completionHandler);
                          }
                        }
);
                      }
                    }
);
                  }
 else {
                    usersEndHandler.handle(null);
                  }
                }
              }
);
            }
          }
        }
);
      }
    }
;
    public void handle(    Boolean continuation){
      if (continuation) {
        getImpactedUsers(userPagination.getAndIncrement(),new Handler<Either<String,JsonArray>>(){
          public void handle(          Either<String,JsonArray> event){
            if (event.isLeft()) {
              log.error("String_Node_Str" + event.left().getValue());
              handler.handle(new Either.Left<String,JsonObject>(event.left().getValue()));
            }
 else {
              JsonArray users=event.right().getValue();
              usersHandler.handle(users);
            }
          }
        }
);
      }
 else {
        handler.handle(new Either.Right<String,JsonObject>(results));
      }
    }
  }
;
  getNotificationsDefaults(new Handler<JsonArray>(){
    public void handle(    final JsonArray notifications){
      if (notifications == null) {
        log.error("String_Node_Str");
        return;
      }
 else {
        for (        Object notifObj : notifications) {
          final JsonObject notif=(JsonObject)notifObj;
          notificationsDefaults.putObject(notif.getString("String_Node_Str","String_Node_Str"),notif);
        }
        userContinuationHandler.handle(true);
      }
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Sends weekly notification emails for all users.
 * @param dayDelta : Day from which to aggregate, delta from now.
 * @param handler : Handles the results, emails sent / users KO
 */
public void sendWeeklyMails(int dayDelta,final Handler<Either<String,JsonObject>> handler){
  final HttpServerRequest request=new JsonHttpServerRequest(new JsonObject());
  final AtomicInteger userPagination=new AtomicInteger(0);
  final Calendar weekDate=Calendar.getInstance();
  weekDate.add(Calendar.DAY_OF_MONTH,dayDelta - 6);
  weekDate.set(Calendar.HOUR_OF_DAY,0);
  weekDate.set(Calendar.MINUTE,0);
  weekDate.set(Calendar.SECOND,0);
  weekDate.set(Calendar.MILLISECOND,0);
  final JsonObject results=new JsonObject().putNumber("String_Node_Str",0).putNumber("String_Node_Str",0);
  final JsonObject notificationsDefaults=new JsonObject();
  final Handler<Boolean> userContinuationHandler=new Handler<Boolean>(){
    private final Handler<Boolean> continuation=this;
    private final Handler<JsonArray> usersHandler=new Handler<JsonArray>(){
      public void handle(      final JsonArray users){
        final int nbUsers=users.size();
        if (nbUsers == 0) {
          continuation.handle(false);
          return;
        }
        final AtomicInteger usersCountdown=new AtomicInteger(nbUsers);
        final VoidHandler usersEndHandler=new VoidHandler(){
          protected void handle(){
            if (usersCountdown.decrementAndGet() <= 0) {
              continuation.handle(nbUsers == USERS_LIMIT);
            }
          }
        }
;
        final JsonArray userIds=new JsonArray();
        for (        Object userObj : users)         userIds.add(((JsonObject)userObj).getString("String_Node_Str","String_Node_Str"));
        getUsersPreferences(userIds,new Handler<JsonArray>(){
          public void handle(          JsonArray preferences){
            for (            Object userObj : preferences) {
              final JsonObject userPrefs=(JsonObject)userObj;
              getAggregatedUserNotifications(userPrefs.getString("String_Node_Str","String_Node_Str"),weekDate.getTime(),new Handler<JsonArray>(){
                public void handle(                JsonArray notifications){
                  if (notifications.size() == 0) {
                    usersEndHandler.handle(null);
                    return;
                  }
                  final JsonArray weeklyNotifications=new JsonArray();
                  for (                  Object notificationObj : notifications) {
                    JsonObject notification=(JsonObject)notificationObj;
                    final String notificationName=notification.getString("String_Node_Str","String_Node_Str").toLowerCase() + "String_Node_Str" + notification.getString("String_Node_Str","String_Node_Str").toLowerCase();
                    if (notificationsDefaults.getObject(notificationName) == null)                     continue;
                    JsonObject notificationPreference=userPrefs.getObject("String_Node_Str",new JsonObject()).getObject("String_Node_Str",new JsonObject()).getObject(notificationName,new JsonObject());
                    if (TimelineNotificationsLoader.Frequencies.WEEKLY.name().equals(notificationPrefsMixin("String_Node_Str",notificationPreference,notificationsDefaults.getObject(notificationName))) && !TimelineNotificationsLoader.Restrictions.INTERNAL.name().equals(notificationPrefsMixin("String_Node_Str",notificationPreference,notificationsDefaults.getObject(notificationName)))) {
                      notification.putString("String_Node_Str",notificationName);
                      weeklyNotifications.add(notification);
                    }
                  }
                  final JsonObject weeklyNotificationsObj=new JsonObject();
                  final JsonArray weeklyNotificationsGroupedArray=new JsonArray();
                  for (                  Object notif : weeklyNotifications) {
                    JsonObject notification=(JsonObject)notif;
                    if (!weeklyNotificationsObj.containsField(notification.getString("String_Node_Str").toLowerCase()))                     weeklyNotificationsObj.putObject(notification.getString("String_Node_Str").toLowerCase(),new JsonObject().putString("String_Node_Str",notificationsDefaults.getObject(notification.getString("String_Node_Str")).getString("String_Node_Str","String_Node_Str")).putArray("String_Node_Str",new JsonArray()));
                    weeklyNotificationsObj.getObject(notification.getString("String_Node_Str").toLowerCase()).getArray(("String_Node_Str"),new JsonArray()).add(notification);
                  }
                  for (                  String key : weeklyNotificationsObj.toMap().keySet()) {
                    weeklyNotificationsGroupedArray.add(new JsonObject().putString("String_Node_Str",key).putString("String_Node_Str",weeklyNotificationsObj.getObject(key).getString("String_Node_Str","String_Node_Str")).putArray("String_Node_Str",weeklyNotificationsObj.getObject(key).getArray("String_Node_Str")));
                  }
                  if (weeklyNotifications.size() > 0) {
                    JsonObject templateParams=new JsonObject().putArray("String_Node_Str",weeklyNotificationsGroupedArray);
                    processTimelineTemplate(templateParams,"String_Node_Str","String_Node_Str",new Handler<String>(){
                      public void handle(                      final String processedTemplate){
                        final Handler<Message<JsonObject>> completionHandler=new Handler<Message<JsonObject>>(){
                          public void handle(                          Message<JsonObject> event){
                            if ("String_Node_Str".equals(event.body().getString("String_Node_Str","String_Node_Str"))) {
                              log.error("String_Node_Str" + event.body());
                              results.putNumber("String_Node_Str",results.getInteger("String_Node_Str") + 1);
                            }
 else {
                              results.putNumber("String_Node_Str",results.getInteger("String_Node_Str") + 1);
                            }
                            usersEndHandler.handle(null);
                          }
                        }
;
                        JsonArray keys=new JsonArray().add("String_Node_Str");
                        translateTimeline(keys,"String_Node_Str",new Handler<JsonArray>(){
                          public void handle(                          JsonArray translations){
                            emailSender.sendEmail(request,userPrefs.getString("String_Node_Str","String_Node_Str"),null,null,translations.get(0).toString(),processedTemplate,null,false,completionHandler);
                          }
                        }
);
                      }
                    }
);
                  }
 else {
                    usersEndHandler.handle(null);
                  }
                }
              }
);
            }
          }
        }
);
      }
    }
;
    public void handle(    Boolean continuation){
      if (continuation) {
        getImpactedUsers(userPagination.getAndIncrement(),new Handler<Either<String,JsonArray>>(){
          public void handle(          Either<String,JsonArray> event){
            if (event.isLeft()) {
              log.error("String_Node_Str" + event.left().getValue());
              handler.handle(new Either.Left<String,JsonObject>(event.left().getValue()));
            }
 else {
              JsonArray users=event.right().getValue();
              usersHandler.handle(users);
            }
          }
        }
);
      }
 else {
        handler.handle(new Either.Right<String,JsonObject>(results));
      }
    }
  }
;
  getNotificationsDefaults(new Handler<JsonArray>(){
    public void handle(    final JsonArray notifications){
      if (notifications == null) {
        log.error("String_Node_Str");
        return;
      }
 else {
        for (        Object notifObj : notifications) {
          final JsonObject notif=(JsonObject)notifObj;
          notificationsDefaults.putObject(notif.getString("String_Node_Str","String_Node_Str"),notif);
        }
        userContinuationHandler.handle(true);
      }
    }
  }
);
}