Program: 160312
Project: 160312
Buggy source:
@SuppressWarnings("String_Node_Str") public void testPutAttachment(){
  CBLBlobStore attachments=database.getAttachments();
  byte[] attach1="String_Node_Str".getBytes();
  String base64=Base64.encodeBytes(attach1);
  Map<String,Object> attachment=new HashMap<String,Object>();
  attachment.put("String_Node_Str","String_Node_Str");
  attachment.put("String_Node_Str",base64);
  Map<String,Object> attachmentDict=new HashMap<String,Object>();
  attachmentDict.put("String_Node_Str",attachment);
  Map<String,Object> properties=new HashMap<String,Object>();
  properties.put("String_Node_Str",1);
  properties.put("String_Node_Str",false);
  properties.put("String_Node_Str",attachmentDict);
  CBLStatus status=new CBLStatus();
  CBLRevision rev1=database.putRevision(new CBLRevision(properties,database),null,false,status);
  Assert.assertEquals(CBLStatus.CREATED,status.getCode());
  Assert.assertEquals(1,attachments.count());
  CBLRevision gotRev1=database.getDocumentWithIDAndRev(rev1.getDocId(),rev1.getRevId(),EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
  Map<String,Object> gotAttachmentDict=(Map<String,Object>)gotRev1.getProperties().get("String_Node_Str");
  Map<String,Object> innerDict=new HashMap<String,Object>();
  innerDict.put("String_Node_Str","String_Node_Str");
  innerDict.put("String_Node_Str","String_Node_Str");
  innerDict.put("String_Node_Str",27);
  innerDict.put("String_Node_Str",true);
  innerDict.put("String_Node_Str",1);
  Map<String,Object> expectAttachmentDict=new HashMap<String,Object>();
  expectAttachmentDict.put("String_Node_Str",innerDict);
  Assert.assertEquals(expectAttachmentDict,gotAttachmentDict);
  byte[] attachv2="String_Node_Str".getBytes();
  database.updateAttachment("String_Node_Str",new ByteArrayInputStream(attachv2),"String_Node_Str",rev1.getDocId(),null,status);
  Assert.assertEquals(CBLStatus.CONFLICT,status.getCode());
  database.updateAttachment("String_Node_Str",new ByteArrayInputStream(attachv2),"String_Node_Str",rev1.getDocId(),"String_Node_Str",status);
  Assert.assertEquals(CBLStatus.CONFLICT,status.getCode());
  CBLRevision rev2=database.updateAttachment("String_Node_Str",new ByteArrayInputStream(attachv2),"String_Node_Str",rev1.getDocId(),rev1.getRevId(),status);
  Assert.assertEquals(CBLStatus.CREATED,status.getCode());
  Assert.assertEquals(rev1.getDocId(),rev2.getDocId());
  Assert.assertEquals(2,rev2.getGeneration());
  CBLRevision gotRev2=database.getDocumentWithIDAndRev(rev2.getDocId(),rev2.getRevId(),EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
  attachmentDict=(Map<String,Object>)gotRev2.getProperties().get("String_Node_Str");
  innerDict=new HashMap<String,Object>();
  innerDict.put("String_Node_Str","String_Node_Str");
  innerDict.put("String_Node_Str","String_Node_Str");
  innerDict.put("String_Node_Str",23);
  innerDict.put("String_Node_Str",true);
  innerDict.put("String_Node_Str",2);
  expectAttachmentDict.put("String_Node_Str",innerDict);
  Assert.assertEquals(expectAttachmentDict,attachmentDict);
  database.updateAttachment("String_Node_Str",null,null,rev2.getDocId(),rev2.getRevId(),status);
  Assert.assertEquals(CBLStatus.NOT_FOUND,status.getCode());
  database.updateAttachment("String_Node_Str",null,null,"String_Node_Str","String_Node_Str",status);
  Assert.assertEquals(CBLStatus.NOT_FOUND,status.getCode());
  CBLRevision rev3=database.updateAttachment("String_Node_Str",null,null,rev2.getDocId(),rev2.getRevId(),status);
  Assert.assertEquals(CBLStatus.OK,status.getCode());
  Assert.assertEquals(rev2.getDocId(),rev3.getDocId());
  Assert.assertEquals(3,rev3.getGeneration());
  CBLRevision gotRev3=database.getDocumentWithIDAndRev(rev3.getDocId(),rev3.getRevId(),EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
  attachmentDict=(Map<String,Object>)gotRev3.getProperties().get("String_Node_Str");
  Assert.assertNull(attachmentDict);
  database.close();
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public void testPutAttachment(){
  CBLBlobStore attachments=database.getAttachments();
  attachments.deleteBlobs();
  Assert.assertEquals(0,attachments.count());
  byte[] attach1="String_Node_Str".getBytes();
  String base64=Base64.encodeBytes(attach1);
  Map<String,Object> attachment=new HashMap<String,Object>();
  attachment.put("String_Node_Str","String_Node_Str");
  attachment.put("String_Node_Str",base64);
  Map<String,Object> attachmentDict=new HashMap<String,Object>();
  attachmentDict.put("String_Node_Str",attachment);
  Map<String,Object> properties=new HashMap<String,Object>();
  properties.put("String_Node_Str",1);
  properties.put("String_Node_Str",false);
  properties.put("String_Node_Str",attachmentDict);
  CBLStatus status=new CBLStatus();
  CBLRevision rev1=database.putRevision(new CBLRevision(properties,database),null,false,status);
  Assert.assertEquals(CBLStatus.CREATED,status.getCode());
  Assert.assertEquals(1,attachments.count());
  CBLRevision gotRev1=database.getDocumentWithIDAndRev(rev1.getDocId(),rev1.getRevId(),EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
  Map<String,Object> gotAttachmentDict=(Map<String,Object>)gotRev1.getProperties().get("String_Node_Str");
  Map<String,Object> innerDict=new HashMap<String,Object>();
  innerDict.put("String_Node_Str","String_Node_Str");
  innerDict.put("String_Node_Str","String_Node_Str");
  innerDict.put("String_Node_Str",27);
  innerDict.put("String_Node_Str",true);
  innerDict.put("String_Node_Str",1);
  Map<String,Object> expectAttachmentDict=new HashMap<String,Object>();
  expectAttachmentDict.put("String_Node_Str",innerDict);
  Assert.assertEquals(expectAttachmentDict,gotAttachmentDict);
  byte[] attachv2="String_Node_Str".getBytes();
  database.updateAttachment("String_Node_Str",new ByteArrayInputStream(attachv2),"String_Node_Str",rev1.getDocId(),null,status);
  Assert.assertEquals(CBLStatus.CONFLICT,status.getCode());
  database.updateAttachment("String_Node_Str",new ByteArrayInputStream(attachv2),"String_Node_Str",rev1.getDocId(),"String_Node_Str",status);
  Assert.assertEquals(CBLStatus.CONFLICT,status.getCode());
  CBLRevision rev2=database.updateAttachment("String_Node_Str",new ByteArrayInputStream(attachv2),"String_Node_Str",rev1.getDocId(),rev1.getRevId(),status);
  Assert.assertEquals(CBLStatus.CREATED,status.getCode());
  Assert.assertEquals(rev1.getDocId(),rev2.getDocId());
  Assert.assertEquals(2,rev2.getGeneration());
  CBLRevision gotRev2=database.getDocumentWithIDAndRev(rev2.getDocId(),rev2.getRevId(),EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
  attachmentDict=(Map<String,Object>)gotRev2.getProperties().get("String_Node_Str");
  innerDict=new HashMap<String,Object>();
  innerDict.put("String_Node_Str","String_Node_Str");
  innerDict.put("String_Node_Str","String_Node_Str");
  innerDict.put("String_Node_Str",23);
  innerDict.put("String_Node_Str",true);
  innerDict.put("String_Node_Str",2);
  expectAttachmentDict.put("String_Node_Str",innerDict);
  Assert.assertEquals(expectAttachmentDict,attachmentDict);
  database.updateAttachment("String_Node_Str",null,null,rev2.getDocId(),rev2.getRevId(),status);
  Assert.assertEquals(CBLStatus.NOT_FOUND,status.getCode());
  database.updateAttachment("String_Node_Str",null,null,"String_Node_Str","String_Node_Str",status);
  Assert.assertEquals(CBLStatus.NOT_FOUND,status.getCode());
  CBLRevision rev3=database.updateAttachment("String_Node_Str",null,null,rev2.getDocId(),rev2.getRevId(),status);
  Assert.assertEquals(CBLStatus.OK,status.getCode());
  Assert.assertEquals(rev2.getDocId(),rev3.getDocId());
  Assert.assertEquals(3,rev3.getGeneration());
  CBLRevision gotRev3=database.getDocumentWithIDAndRev(rev3.getDocId(),rev3.getRevId(),EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
  attachmentDict=(Map<String,Object>)gotRev3.getProperties().get("String_Node_Str");
  Assert.assertNull(attachmentDict);
  database.close();
}