Program: 78170
Project: 78170
Buggy source:
private void doRetry(){
  if (!LeaderSelector.isLeader) {
    return;
  }
  final InstanceTask instanceTask=getInstanceTask();
  if (instanceTask == null) {
    return;
  }
  if (StringUtils.equals(instanceTask.getStatus(),Status.FAIL.name())) {
    List<DefMonitorRetry> defMonitorRetryList=ServiceBeanFactory.getDefMonitorRetryService().getByTaskId(instanceTaskKeyDetail.getTaskId(),1);
    if (defMonitorRetryList != null) {
      for (      DefMonitorRetry defMonitorRetry : defMonitorRetryList) {
        if (defMonitorRetry.getFailRetryN() == instanceTask.getRetriedNum()) {
          AlertUtils.alertMonitorRetry(instanceTask.getCatalogId(),instanceTask.getTaskId(),instanceTask.getTaskName(),instanceTask.getTaskDate(),instanceTask.getRetriedNum());
          break;
        }
      }
    }
  }
  if (StringUtils.equals(instanceTask.getStatus(),Status.FAIL.name()) && instanceTask.getRetriedNum() < instanceTask.getMaxRetryNum()) {
    final InstanceTaskExecutor curExecutor=this;
    ThreadPublicFactory.cachedThreadPool.submit(new Runnable(){
      @Override public void run(){
        try {
          Thread.currentThread().setName("String_Node_Str" + instanceTaskKeyDetail);
          if (instanceTask.getRetryInterval() > 0) {
            Thread.sleep(instanceTask.getRetryInterval() * 1000l);
          }
          InstanceTaskKey instanceTaskKey=instanceTaskKeyDetail.getInstanceTaskKey();
          InstanceTaskLock instanceTaskLock=InstanceTaskLockFactory.borrowLock(instanceTaskKey);
          instanceTaskLock.getLock().lock();
          try {
            InstanceTask curInstanceTask=getInstanceTask();
            if (isInvalidInstanceTask(curInstanceTask)) {
              return;
            }
            if (StringUtils.equals(curInstanceTask.getStatus(),Status.FAIL.name()) && curInstanceTask.getRetriedNum() < curInstanceTask.getMaxRetryNum()) {
              retriedNumAdd1(curInstanceTask);
              TaskRunningFactory.submit(curExecutor);
            }
          }
  finally {
            InstanceTaskLockFactory.returnLock(instanceTaskLock);
          }
        }
 catch (        Exception e) {
          logger.error("String_Node_Str" + instanceTaskKeyDetail,e);
        }
      }
    }
);
  }
}

Fixed version (ground truth):
private void doRetry(){
  if (!LeaderSelector.isLeader) {
    return;
  }
  final InstanceTask instanceTask=getInstanceTask();
  if (isInvalidInstanceTask(instanceTask)) {
    return;
  }
  if (StringUtils.equals(instanceTask.getStatus(),Status.FAIL.name())) {
    List<DefMonitorRetry> defMonitorRetryList=ServiceBeanFactory.getDefMonitorRetryService().getByTaskId(instanceTaskKeyDetail.getTaskId(),1);
    if (defMonitorRetryList != null) {
      for (      DefMonitorRetry defMonitorRetry : defMonitorRetryList) {
        if (defMonitorRetry.getFailRetryN() == instanceTask.getRetriedNum()) {
          AlertUtils.alertMonitorRetry(instanceTask.getCatalogId(),instanceTask.getTaskId(),instanceTask.getTaskName(),instanceTask.getTaskDate(),instanceTask.getRetriedNum());
          break;
        }
      }
    }
  }
  if (StringUtils.equals(instanceTask.getStatus(),Status.FAIL.name()) && instanceTask.getRetriedNum() < instanceTask.getMaxRetryNum()) {
    final InstanceTaskExecutor curExecutor=this;
    ThreadPublicFactory.cachedThreadPool.submit(new Runnable(){
      @Override public void run(){
        try {
          Thread.currentThread().setName("String_Node_Str" + instanceTaskKeyDetail);
          if (instanceTask.getRetryInterval() > 0) {
            Thread.sleep(instanceTask.getRetryInterval() * 1000l);
          }
          InstanceTaskKey instanceTaskKey=instanceTaskKeyDetail.getInstanceTaskKey();
          InstanceTaskLock instanceTaskLock=InstanceTaskLockFactory.borrowLock(instanceTaskKey);
          instanceTaskLock.getLock().lock();
          try {
            InstanceTask curInstanceTask=getInstanceTask();
            if (isInvalidInstanceTask(curInstanceTask)) {
              return;
            }
            if (StringUtils.equals(curInstanceTask.getStatus(),Status.FAIL.name()) && curInstanceTask.getRetriedNum() < curInstanceTask.getMaxRetryNum()) {
              retriedNumAdd1(curInstanceTask);
              TaskRunningFactory.submit(curExecutor);
            }
          }
  finally {
            InstanceTaskLockFactory.returnLock(instanceTaskLock);
          }
        }
 catch (        Exception e) {
          logger.error("String_Node_Str" + instanceTaskKeyDetail,e);
        }
      }
    }
);
  }
}