Program: 93661
Project: 93661
Buggy source:
/** 
 * @param dbName
 * @param collName
 * @param documentId
 * @param content
 * @param requestEtag
 * @param patching
 * @return the HttpStatus code to retrun
 */
public static int upsertDocument(String dbName,String collName,String documentId,DBObject content,ObjectId requestEtag,boolean patching){
  DB db=DBDAO.getDB(dbName);
  DBCollection coll=db.getCollection(collName);
  ObjectId timestamp=new ObjectId();
  Instant now=Instant.ofEpochSecond(timestamp.getTimestamp());
  if (content == null) {
    content=new BasicDBObject();
  }
  content.put("String_Node_Str",timestamp);
  BasicDBObject idQuery=new BasicDBObject("String_Node_Str",getId(documentId));
  if (patching) {
    content.removeField("String_Node_Str");
    DBObject oldDocument=coll.findAndModify(idQuery,null,null,false,new BasicDBObject("String_Node_Str",content),false,false);
    if (oldDocument == null) {
      return HttpStatus.SC_NOT_FOUND;
    }
 else {
      return optimisticCheckEtag(coll,oldDocument,requestEtag,HttpStatus.SC_NO_CONTENT);
    }
  }
 else {
    content.put("String_Node_Str",now.toString());
    DBObject oldDocument=coll.findAndModify(idQuery,null,null,false,content,false,true);
    if (oldDocument != null) {
      Object oldTimestamp=oldDocument.get("String_Node_Str");
      if (oldTimestamp == null) {
        oldTimestamp=now.toString();
        logger.warn("String_Node_Str",dbName,collName,documentId);
      }
      BasicDBObject created=new BasicDBObject("String_Node_Str","String_Node_Str" + oldTimestamp);
      created.markAsPartialObject();
      coll.update(idQuery,new BasicDBObject("String_Node_Str",created),true,false);
      return optimisticCheckEtag(coll,oldDocument,requestEtag,HttpStatus.SC_NO_CONTENT);
    }
 else {
      return HttpStatus.SC_CREATED;
    }
  }
}

Fixed version (ground truth):
/** 
 * @param dbName
 * @param collName
 * @param documentId
 * @param content
 * @param requestEtag
 * @param patching
 * @return the HttpStatus code to retrun
 */
public static int upsertDocument(String dbName,String collName,String documentId,DBObject content,ObjectId requestEtag,boolean patching){
  DB db=DBDAO.getDB(dbName);
  DBCollection coll=db.getCollection(collName);
  ObjectId timestamp=new ObjectId();
  Instant now=Instant.ofEpochSecond(timestamp.getTimestamp());
  if (content == null) {
    content=new BasicDBObject();
  }
  content.put("String_Node_Str",timestamp);
  BasicDBObject idQuery=new BasicDBObject("String_Node_Str",getId(documentId));
  if (patching) {
    content.removeField("String_Node_Str");
    DBObject oldDocument=coll.findAndModify(idQuery,null,null,false,new BasicDBObject("String_Node_Str",content),false,false);
    if (oldDocument == null) {
      return HttpStatus.SC_NOT_FOUND;
    }
 else {
      return optimisticCheckEtag(coll,oldDocument,requestEtag,HttpStatus.SC_OK);
    }
  }
 else {
    content.put("String_Node_Str",now.toString());
    DBObject oldDocument=coll.findAndModify(idQuery,null,null,false,content,false,true);
    if (oldDocument != null) {
      Object oldTimestamp=oldDocument.get("String_Node_Str");
      if (oldTimestamp == null) {
        oldTimestamp=now.toString();
        logger.warn("String_Node_Str",dbName,collName,documentId);
      }
      BasicDBObject created=new BasicDBObject("String_Node_Str","String_Node_Str" + oldTimestamp);
      created.markAsPartialObject();
      coll.update(idQuery,new BasicDBObject("String_Node_Str",created),true,false);
      return optimisticCheckEtag(coll,oldDocument,requestEtag,HttpStatus.SC_OK);
    }
 else {
      return HttpStatus.SC_CREATED;
    }
  }
}