Program: 97264
Project: 97264
Buggy source:
@Override protected void doTxWork(IProgressMonitor monitor,OseeConnection connection) throws OseeCoreException {
  if (artifactsToPurge == null || artifactsToPurge.isEmpty()) {
    return;
  }
  List<Object[]> batchParameters=new ArrayList<Object[]>();
  int queryId=ArtifactLoader.getNewQueryId();
  Timestamp insertTime=GlobalTime.GreenwichMeanTimestamp();
  try {
    for (    Artifact art : artifactsToPurge) {
      for (      Branch branch : art.getFullBranch().getChildBranches(true)) {
        batchParameters.add(new Object[]{queryId,insertTime,art.getArtId(),branch.getUuid(),SQL3DataType.INTEGER});
      }
    }
    if (batchParameters.size() > 0) {
      ArtifactLoader.insertIntoArtifactJoin(connection,batchParameters);
      IOseeStatement chStmt=ConnectionHandler.getStatement(connection);
      try {
        chStmt.runPreparedQuery(COUNT_ARTIFACT_VIOLATIONS,queryId);
        boolean failed=false;
        StringBuilder sb=new StringBuilder();
        while (chStmt.next()) {
          int artId=chStmt.getInt("String_Node_Str");
          long branchUuid=chStmt.getLong("String_Node_Str");
          if (recurseChildrenBranches) {
            Branch branch=BranchManager.getBranch(branchUuid);
            Artifact artifactFromId=ArtifactQuery.getArtifactFromId(artId,branch);
            artifactsToPurge.add(artifactFromId);
          }
 else {
            failed=true;
            sb.append("String_Node_Str");
            sb.append(artId);
            sb.append("String_Node_Str");
            sb.append(branchUuid);
            sb.append("String_Node_Str");
          }
        }
        if (failed) {
          throw new OseeCoreException("String_Node_Str",sb.toString());
        }
      }
  finally {
        ArtifactLoader.clearQuery(connection,queryId);
        chStmt.close();
      }
    }
    batchParameters.clear();
    queryId=ArtifactLoader.getNewQueryId();
    insertTime=GlobalTime.GreenwichMeanTimestamp();
    for (    Artifact art : artifactsToPurge) {
      batchParameters.add(new Object[]{queryId,insertTime,art.getArtId(),art.getFullBranch().getUuid(),SQL3DataType.INTEGER});
    }
    ArtifactLoader.insertIntoArtifactJoin(connection,batchParameters);
    int transactionJoinId=ArtifactLoader.getNewQueryId();
    insertSelectItems(connection,"String_Node_Str","String_Node_Str",transactionJoinId,insertTime,queryId);
    insertSelectItems(connection,"String_Node_Str","String_Node_Str",transactionJoinId,insertTime,queryId);
    insertSelectItems(connection,"String_Node_Str","String_Node_Str",transactionJoinId,insertTime,queryId);
    ConnectionHandler.runPreparedUpdate(connection,DELETE_FROM_TXS_USING_JOIN_TRANSACTION,transactionJoinId);
    ConnectionHandler.runPreparedUpdate(connection,DELETE_FROM_TX_DETAILS_USING_JOIN_TRANSACTION,transactionJoinId);
    ConnectionHandler.runPreparedUpdate(connection,"String_Node_Str",transactionJoinId);
    for (    Artifact artifact : artifactsToPurge) {
      ArtifactCache.deCache(artifact);
      artifact.internalSetDeleted();
      for (      RelationLink rel : artifact.getRelationsAll(DeletionFlag.EXCLUDE_DELETED)) {
        rel.markAsPurged();
      }
      for (      Attribute<?> attr : artifact.internalGetAttributes()) {
        attr.markAsPurged();
      }
    }
    success=true;
  }
  finally {
    ArtifactLoader.clearQuery(connection,queryId);
  }
}

Fixed version (ground truth):
@Override protected void doTxWork(IProgressMonitor monitor,OseeConnection connection) throws OseeCoreException {
  if (artifactsToPurge == null || artifactsToPurge.isEmpty()) {
    return;
  }
  List<Object[]> batchParameters=new ArrayList<Object[]>();
  int queryId=ArtifactLoader.getNewQueryId();
  Timestamp insertTime=GlobalTime.GreenwichMeanTimestamp();
  try {
    for (    Artifact art : artifactsToPurge) {
      for (      Branch branch : art.getFullBranch().getChildBranches(true)) {
        batchParameters.add(new Object[]{queryId,insertTime,art.getArtId(),branch.getUuid(),SQL3DataType.INTEGER});
      }
    }
    if (batchParameters.size() > 0) {
      ArtifactLoader.insertIntoArtifactJoin(connection,batchParameters);
      IOseeStatement chStmt=ConnectionHandler.getStatement(connection);
      try {
        chStmt.runPreparedQuery(COUNT_ARTIFACT_VIOLATIONS,queryId);
        boolean failed=false;
        StringBuilder sb=new StringBuilder();
        while (chStmt.next()) {
          int artId=chStmt.getInt("String_Node_Str");
          long branchUuid=chStmt.getLong("String_Node_Str");
          if (recurseChildrenBranches) {
            Branch branch=BranchManager.getBranch(branchUuid);
            Artifact artifactFromId=ArtifactQuery.getArtifactFromId(artId,branch);
            artifactsToPurge.add(artifactFromId);
          }
 else {
            failed=true;
            sb.append("String_Node_Str");
            sb.append(artId);
            sb.append("String_Node_Str");
            sb.append(branchUuid);
            sb.append("String_Node_Str");
          }
        }
        if (failed) {
          throw new OseeCoreException("String_Node_Str",sb.toString());
        }
      }
  finally {
        ArtifactLoader.clearQuery(connection,queryId);
        chStmt.close();
      }
    }
    batchParameters.clear();
    queryId=ArtifactLoader.getNewQueryId();
    insertTime=GlobalTime.GreenwichMeanTimestamp();
    Set<Artifact> childreArtifactsToPurge=new HashSet<Artifact>();
    for (    Artifact art : artifactsToPurge) {
      childreArtifactsToPurge.addAll(art.getDescendants(DeletionFlag.INCLUDE_DELETED));
    }
    artifactsToPurge.addAll(childreArtifactsToPurge);
    for (    Artifact art : artifactsToPurge) {
      batchParameters.add(new Object[]{queryId,insertTime,art.getArtId(),art.getFullBranch().getUuid(),SQL3DataType.INTEGER});
    }
    ArtifactLoader.insertIntoArtifactJoin(connection,batchParameters);
    int transactionJoinId=ArtifactLoader.getNewQueryId();
    insertSelectItems(connection,"String_Node_Str","String_Node_Str",transactionJoinId,insertTime,queryId);
    insertSelectItems(connection,"String_Node_Str","String_Node_Str",transactionJoinId,insertTime,queryId);
    insertSelectItems(connection,"String_Node_Str","String_Node_Str",transactionJoinId,insertTime,queryId);
    ConnectionHandler.runPreparedUpdate(connection,DELETE_FROM_TXS_USING_JOIN_TRANSACTION,transactionJoinId);
    ConnectionHandler.runPreparedUpdate(connection,DELETE_FROM_TX_DETAILS_USING_JOIN_TRANSACTION,transactionJoinId);
    ConnectionHandler.runPreparedUpdate(connection,"String_Node_Str",transactionJoinId);
    for (    Artifact artifact : artifactsToPurge) {
      ArtifactCache.deCache(artifact);
      artifact.internalSetDeleted();
      for (      RelationLink rel : artifact.getRelationsAll(DeletionFlag.EXCLUDE_DELETED)) {
        rel.markAsPurged();
      }
      for (      Attribute<?> attr : artifact.internalGetAttributes()) {
        attr.markAsPurged();
      }
    }
    success=true;
  }
  finally {
    ArtifactLoader.clearQuery(connection,queryId);
  }
}