Program: 87133
Project: 87133
Buggy source:
/** 
 * Send daily notification emails for all users.
 * @param dayDelta : When to aggregate, delta from now.
 * @param handler : Handles the results, emails sent / users KO
 */
public void sendDailyMails(int dayDelta,final Handler<Either<String,JsonObject>> handler){
  final HttpServerRequest request=new JsonHttpServerRequest(new JsonObject());
  final AtomicInteger userPagination=new AtomicInteger(0);
  final Calendar dayDate=Calendar.getInstance();
  dayDate.add(Calendar.DAY_OF_MONTH,dayDelta);
  dayDate.set(Calendar.HOUR_OF_DAY,0);
  dayDate.set(Calendar.MINUTE,0);
  dayDate.set(Calendar.SECOND,0);
  dayDate.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);
              getUserNotifications(user.getString("String_Node_Str","String_Node_Str"),dayDate.getTime(),new Handler<JsonArray>(){
                public void handle(                JsonArray notifications){
                  if (notifications.size() == 0) {
                    usersEndHandler.handle(null);
                    return;
                  }
                  SimpleDateFormat formatter=new SimpleDateFormat("String_Node_Str",Locale.FRANCE);
                  final JsonArray dates=new JsonArray();
                  final JsonArray templates=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.DAILY.name().equals(notificationPrefsMixin("String_Node_Str",notificationPreference,notificationsDefaults.getObject(notificationName))) && !TimelineNotificationsLoader.Restrictions.INTERNAL.name().equals(notificationPrefsMixin("String_Node_Str",notificationPreference,notificationsDefaults.getObject(notificationName)))) {
                      templates.add(new JsonObject().putString("String_Node_Str",notificationsDefaults.getObject(notificationName,new JsonObject()).getString("String_Node_Str","String_Node_Str")).putObject("String_Node_Str",notification.getObject("String_Node_Str",new JsonObject())));
                      dates.add(formatter.format(MongoDb.parseIsoDate(notification.getObject("String_Node_Str"))));
                    }
                  }
                  if (templates.size() > 0) {
                    JsonObject templateParams=new JsonObject().putArray("String_Node_Str",templates).putArray("String_Node_Str",dates);
                    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):
/** 
 * Send daily notification emails for all users.
 * @param dayDelta : When to aggregate, delta from now.
 * @param handler : Handles the results, emails sent / users KO
 */
public void sendDailyMails(int dayDelta,final Handler<Either<String,JsonObject>> handler){
  final HttpServerRequest request=new JsonHttpServerRequest(new JsonObject());
  final AtomicInteger userPagination=new AtomicInteger(0);
  final Calendar dayDate=Calendar.getInstance();
  dayDate.add(Calendar.DAY_OF_MONTH,dayDelta);
  dayDate.set(Calendar.HOUR_OF_DAY,0);
  dayDate.set(Calendar.MINUTE,0);
  dayDate.set(Calendar.SECOND,0);
  dayDate.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;
              getUserNotifications(userPrefs.getString("String_Node_Str","String_Node_Str"),dayDate.getTime(),new Handler<JsonArray>(){
                public void handle(                JsonArray notifications){
                  if (notifications.size() == 0) {
                    usersEndHandler.handle(null);
                    return;
                  }
                  SimpleDateFormat formatter=new SimpleDateFormat("String_Node_Str",Locale.FRANCE);
                  final JsonArray dates=new JsonArray();
                  final JsonArray templates=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.DAILY.name().equals(notificationPrefsMixin("String_Node_Str",notificationPreference,notificationsDefaults.getObject(notificationName))) && !TimelineNotificationsLoader.Restrictions.INTERNAL.name().equals(notificationPrefsMixin("String_Node_Str",notificationPreference,notificationsDefaults.getObject(notificationName)))) {
                      templates.add(new JsonObject().putString("String_Node_Str",notificationsDefaults.getObject(notificationName,new JsonObject()).getString("String_Node_Str","String_Node_Str")).putObject("String_Node_Str",notification.getObject("String_Node_Str",new JsonObject())));
                      dates.add(formatter.format(MongoDb.parseIsoDate(notification.getObject("String_Node_Str"))));
                    }
                  }
                  if (templates.size() > 0) {
                    JsonObject templateParams=new JsonObject().putArray("String_Node_Str",templates).putArray("String_Node_Str",dates);
                    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);
      }
    }
  }
);
}