Program: 145391
Project: 145391
Buggy source:
public void complete(Change aChange,SqlQuery aQuery,AccessControlException accessDenied,Exception failed){
  if (aChange != null && aQuery != null) {
    try {
      SqlCompiledQuery entity=entities.get(aChange.entityName);
      if (entity == null) {
        entity=aQuery.compile();
        entities.put(aChange.entityName,entity);
      }
      if (aChange instanceof Command) {
        ((Command)aChange).command=entity.getSqlClause();
      }
    }
 catch (    Exception ex) {
      Logger.getLogger(CommitRequestHandler.class.getName()).log(Level.SEVERE,null,ex);
      notRetrievedEntities.add(ex);
    }
  }
  if (accessDenied != null) {
    accessDeniedEntities.add(accessDenied);
  }
  if (failed != null) {
    notRetrievedEntities.add(failed);
  }
  if (++factCalls == expectedChanges.size()) {
    if (accessDeniedEntities.isEmpty() && notRetrievedEntities.isEmpty()) {
      if (onSuccess != null) {
        Map<String,List<Change>> changeLogs=new HashMap<>();
        expectedChanges.stream().forEach((        Change aSortedChange) -> {
          SqlCompiledQuery entity=entities.get(aSortedChange.entityName);
          List<Change> targetChangeLog=changeLogs.get(entity.getDatasourceName());
          if (targetChangeLog == null) {
            targetChangeLog=new ArrayList<>();
            changeLogs.put(entity.getDatasourceName(),targetChangeLog);
          }
          targetChangeLog.add(aSortedChange);
        }
);
        onSuccess.accept(changeLogs);
      }
    }
 else {
      if (onFailure != null) {
        onFailure.accept(new IllegalStateException(assembleErrors()));
      }
    }
  }
}

Fixed version (ground truth):
public void complete(Change aChange,SqlQuery aQuery,AccessControlException accessDenied,Exception failed){
  if (aChange != null && aQuery != null) {
    try {
      SqlCompiledQuery entity=entities.get(aChange.entityName);
      if (entity == null) {
        entity=aQuery.compile();
        entities.put(aChange.entityName,entity);
      }
      if (aChange instanceof Command) {
        ((Command)aChange).command=entity.getSqlClause();
      }
    }
 catch (    Exception ex) {
      Logger.getLogger(CommitRequestHandler.class.getName()).log(Level.SEVERE,null,ex);
      notRetrievedEntities.add(ex);
    }
  }
  if (accessDenied != null) {
    accessDeniedEntities.add(accessDenied);
  }
  if (failed != null) {
    notRetrievedEntities.add(failed);
  }
  if (++factCalls == expectedChanges.size()) {
    if (accessDeniedEntities.isEmpty() && notRetrievedEntities.isEmpty()) {
      if (onSuccess != null) {
        Map<String,List<Change>> changeLogs=new HashMap<>();
        expectedChanges.stream().forEach((        Change aSortedChange) -> {
          SqlCompiledQuery entity=entities.get(aSortedChange.entityName);
          String datasourceName=entity.getDatasourceName();
          if (datasourceName == null || datasourceName.isEmpty()) {
            datasourceName=defaultDatasource;
          }
          List<Change> targetChangeLog=changeLogs.get(datasourceName);
          if (targetChangeLog == null) {
            targetChangeLog=new ArrayList<>();
            changeLogs.put(entity.getDatasourceName(),targetChangeLog);
          }
          targetChangeLog.add(aSortedChange);
        }
);
        onSuccess.accept(changeLogs);
      }
    }
 else {
      if (onFailure != null) {
        onFailure.accept(new IllegalStateException(assembleErrors()));
      }
    }
  }
}