Program: 39073
Project: 39073
Buggy source:
private void writeCherryPickCommit(final Merger m,final CodeReviewCommit n) throws IOException {
  final StringBuilder msgbuf=new StringBuilder();
  msgbuf.append(n.getFullMessage());
  if (msgbuf.length() == 0) {
    msgbuf.append("String_Node_Str");
  }
  if (msgbuf.charAt(msgbuf.length() - 1) != '\n') {
    msgbuf.append('\n');
  }
  if (!msgbuf.toString().matches("String_Node_Str")) {
    msgbuf.append('\n');
  }
  if (server.getCanonicalURL() != null) {
    msgbuf.append("String_Node_Str");
    msgbuf.append(server.getCanonicalURL());
    msgbuf.append(n.patchsetId.getParentKey().get());
    msgbuf.append('\n');
  }
  ChangeApproval submitAudit=null;
  try {
    final List<ChangeApproval> approvalList=schema.changeApprovals().byChange(n.patchsetId.getParentKey()).toList();
    Collections.sort(approvalList,new Comparator<ChangeApproval>(){
      public int compare(      final ChangeApproval a,      final ChangeApproval b){
        return a.getGranted().compareTo(b.getGranted());
      }
    }
);
    for (    final ChangeApproval a : approvalList) {
      if (a.getValue() <= 0) {
        continue;
      }
      if (ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
        if (submitAudit == null || a.getGranted().compareTo(submitAudit.getGranted()) > 0) {
          submitAudit=a;
        }
        continue;
      }
      final Account acc=Common.getAccountCache().get(a.getAccountId());
      if (acc == null) {
        continue;
      }
      final StringBuilder identbuf=new StringBuilder();
      if (acc.getFullName() != null && acc.getFullName().length() > 0) {
        identbuf.append(' ');
        identbuf.append(acc.getFullName());
      }
      if (acc.getPreferredEmail() != null && acc.getPreferredEmail().length() > 0) {
        identbuf.append(' ');
        identbuf.append('<');
        identbuf.append(acc.getPreferredEmail());
        identbuf.append('>');
      }
      if (identbuf.length() == 0) {
        continue;
      }
      final String tag;
      if (CRVW.equals(a.getCategoryId())) {
        tag="String_Node_Str";
      }
 else       if (VRIF.equals(a.getCategoryId())) {
        tag="String_Node_Str";
      }
 else {
        final ApprovalType at=Common.getGerritConfig().getApprovalType(a.getCategoryId());
        if (at == null) {
          continue;
        }
        tag=at.getCategory().getName().replace(' ','-');
      }
      msgbuf.append(tag);
      msgbuf.append(':');
      msgbuf.append(identbuf);
      msgbuf.append('\n');
    }
  }
 catch (  OrmException e) {
    log.error("String_Node_Str" + n.patchsetId,e);
  }
  Account submitterAcct=null;
  if (submitAudit != null) {
    submitterAcct=Common.getAccountCache().get(submitAudit.getAccountId());
  }
  final Commit mergeCommit=new Commit(db);
  mergeCommit.setTreeId(m.getResultTreeId());
  mergeCommit.setParentIds(new ObjectId[]{mergeTip});
  mergeCommit.setAuthor(n.getAuthorIdent());
  if (submitterAcct != null) {
    String name=submitterAcct.getFullName();
    if (name == null || name.length() == 0) {
      name="String_Node_Str";
    }
    String email=submitterAcct.getPreferredEmail();
    if (email == null || email.length() == 0) {
      email="String_Node_Str" + submitterAcct.getId().get() + "String_Node_Str";
    }
    mergeCommit.setCommitter(new PersonIdent(name,email,submitAudit.getGranted(),myIdent.getTimeZone()));
  }
 else {
    mergeCommit.setCommitter(myIdent);
  }
  mergeCommit.setMessage(msgbuf.toString());
  final ObjectId id=m.getObjectWriter().writeCommit(mergeCommit);
  mergeTip=(CodeReviewCommit)rw.parseCommit(id);
  n.statusCode=CommitMergeStatus.CLEAN_PICK;
  status.put(n.patchsetId.getParentKey(),n.statusCode);
  newCommits.put(n.patchsetId.getParentKey(),mergeTip);
}

Fixed version (ground truth):
private void writeCherryPickCommit(final Merger m,final CodeReviewCommit n) throws IOException {
  final StringBuilder msgbuf=new StringBuilder();
  msgbuf.append(n.getFullMessage());
  if (msgbuf.length() == 0) {
    msgbuf.append("String_Node_Str");
  }
  if (msgbuf.charAt(msgbuf.length() - 1) != '\n') {
    msgbuf.append('\n');
  }
  if (!endsWithKey(msgbuf.toString())) {
    msgbuf.append('\n');
  }
  if (server.getCanonicalURL() != null) {
    msgbuf.append("String_Node_Str");
    msgbuf.append(server.getCanonicalURL());
    msgbuf.append(n.patchsetId.getParentKey().get());
    msgbuf.append('\n');
  }
  ChangeApproval submitAudit=null;
  try {
    final List<ChangeApproval> approvalList=schema.changeApprovals().byChange(n.patchsetId.getParentKey()).toList();
    Collections.sort(approvalList,new Comparator<ChangeApproval>(){
      public int compare(      final ChangeApproval a,      final ChangeApproval b){
        return a.getGranted().compareTo(b.getGranted());
      }
    }
);
    for (    final ChangeApproval a : approvalList) {
      if (a.getValue() <= 0) {
        continue;
      }
      if (ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
        if (submitAudit == null || a.getGranted().compareTo(submitAudit.getGranted()) > 0) {
          submitAudit=a;
        }
        continue;
      }
      final Account acc=Common.getAccountCache().get(a.getAccountId());
      if (acc == null) {
        continue;
      }
      final StringBuilder identbuf=new StringBuilder();
      if (acc.getFullName() != null && acc.getFullName().length() > 0) {
        identbuf.append(' ');
        identbuf.append(acc.getFullName());
      }
      if (acc.getPreferredEmail() != null && acc.getPreferredEmail().length() > 0) {
        identbuf.append(' ');
        identbuf.append('<');
        identbuf.append(acc.getPreferredEmail());
        identbuf.append('>');
      }
      if (identbuf.length() == 0) {
        continue;
      }
      final String tag;
      if (CRVW.equals(a.getCategoryId())) {
        tag="String_Node_Str";
      }
 else       if (VRIF.equals(a.getCategoryId())) {
        tag="String_Node_Str";
      }
 else {
        final ApprovalType at=Common.getGerritConfig().getApprovalType(a.getCategoryId());
        if (at == null) {
          continue;
        }
        tag=at.getCategory().getName().replace(' ','-');
      }
      msgbuf.append(tag);
      msgbuf.append(':');
      msgbuf.append(identbuf);
      msgbuf.append('\n');
    }
  }
 catch (  OrmException e) {
    log.error("String_Node_Str" + n.patchsetId,e);
  }
  Account submitterAcct=null;
  if (submitAudit != null) {
    submitterAcct=Common.getAccountCache().get(submitAudit.getAccountId());
  }
  final Commit mergeCommit=new Commit(db);
  mergeCommit.setTreeId(m.getResultTreeId());
  mergeCommit.setParentIds(new ObjectId[]{mergeTip});
  mergeCommit.setAuthor(n.getAuthorIdent());
  if (submitterAcct != null) {
    String name=submitterAcct.getFullName();
    if (name == null || name.length() == 0) {
      name="String_Node_Str";
    }
    String email=submitterAcct.getPreferredEmail();
    if (email == null || email.length() == 0) {
      email="String_Node_Str" + submitterAcct.getId().get() + "String_Node_Str";
    }
    mergeCommit.setCommitter(new PersonIdent(name,email,submitAudit.getGranted(),myIdent.getTimeZone()));
  }
 else {
    mergeCommit.setCommitter(myIdent);
  }
  mergeCommit.setMessage(msgbuf.toString());
  final ObjectId id=m.getObjectWriter().writeCommit(mergeCommit);
  mergeTip=(CodeReviewCommit)rw.parseCommit(id);
  n.statusCode=CommitMergeStatus.CLEAN_PICK;
  status.put(n.patchsetId.getParentKey(),n.statusCode);
  newCommits.put(n.patchsetId.getParentKey(),mergeTip);
}