Program: 160304
Project: 160304
Buggy source:
@SuppressWarnings("String_Node_Str") public void testPutLargeAttachment() throws Exception {
  String testAttachmentName="String_Node_Str";
  BlobStore attachments=database.getAttachments();
  attachments.deleteBlobs();
  Assert.assertEquals(0,attachments.count());
  Status status=new Status();
  Map<String,Object> rev1Properties=new HashMap<String,Object>();
  rev1Properties.put("String_Node_Str",1);
  rev1Properties.put("String_Node_Str",false);
  RevisionInternal rev1=database.putRevision(new RevisionInternal(rev1Properties,database),null,false,status);
  Assert.assertEquals(Status.CREATED,status.getCode());
  StringBuffer largeAttachment=new StringBuffer();
  for (int i=0; i < Database.kBigAttachmentLength; i++) {
    largeAttachment.append("String_Node_Str");
  }
  byte[] attach1=largeAttachment.toString().getBytes();
  database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1),rev1.getSequence(),testAttachmentName,"String_Node_Str",rev1.getGeneration());
  Attachment attachment=database.getAttachmentForSequence(rev1.getSequence(),testAttachmentName);
  Assert.assertEquals("String_Node_Str",attachment.getContentType());
  byte[] data=IOUtils.toByteArray(attachment.getContent());
  Assert.assertTrue(Arrays.equals(attach1,data));
  EnumSet<Database.TDContentOptions> contentOptions=EnumSet.of(Database.TDContentOptions.TDIncludeAttachments,Database.TDContentOptions.TDBigAttachmentsFollow);
  Map<String,Object> attachmentDictForSequence=database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(),contentOptions);
  Map<String,Object> innerDict=(Map<String,Object>)attachmentDictForSequence.get(testAttachmentName);
  if (!innerDict.containsKey("String_Node_Str")) {
    throw new RuntimeException("String_Node_Str");
  }
  if (((Boolean)innerDict.get("String_Node_Str")).booleanValue() == false) {
    throw new RuntimeException("String_Node_Str");
  }
  if (!innerDict.containsKey("String_Node_Str")) {
    throw new RuntimeException("String_Node_Str");
  }
  RevisionInternal rev1WithAttachments=database.getDocumentWithIDAndRev(rev1.getDocId(),rev1.getRevId(),contentOptions);
  Map<String,Object> rev1PropertiesPrime=rev1WithAttachments.getProperties();
  rev1PropertiesPrime.put("String_Node_Str",2);
  RevisionInternal newRev=new RevisionInternal(rev1PropertiesPrime,database);
  RevisionInternal rev2=database.putRevision(newRev,rev1WithAttachments.getRevId(),false,status);
  Assert.assertEquals(Status.CREATED,status.getCode());
  Map<String,Object> rev2Attachment=(Map<String,Object>)rev2.getProperties().get("String_Node_Str");
  Map<String,Object> attachMeta=(Map<String,Object>)rev2Attachment.get(testAttachmentName);
  assertFalse(attachMeta.containsKey(testAttachmentName));
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public void testPutLargeAttachment() throws Exception {
  String testAttachmentName="String_Node_Str";
  BlobStore attachments=database.getAttachments();
  attachments.deleteBlobs();
  Assert.assertEquals(0,attachments.count());
  Status status=new Status();
  Map<String,Object> rev1Properties=new HashMap<String,Object>();
  rev1Properties.put("String_Node_Str",1);
  rev1Properties.put("String_Node_Str",false);
  RevisionInternal rev1=database.putRevision(new RevisionInternal(rev1Properties,database),null,false,status);
  Assert.assertEquals(Status.CREATED,status.getCode());
  StringBuffer largeAttachment=new StringBuffer();
  for (int i=0; i < Database.kBigAttachmentLength; i++) {
    largeAttachment.append("String_Node_Str");
  }
  byte[] attach1=largeAttachment.toString().getBytes();
  database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1),rev1.getSequence(),testAttachmentName,"String_Node_Str",rev1.getGeneration());
  Attachment attachment=database.getAttachmentForSequence(rev1.getSequence(),testAttachmentName);
  Assert.assertEquals("String_Node_Str",attachment.getContentType());
  byte[] data=IOUtils.toByteArray(attachment.getContent());
  Assert.assertTrue(Arrays.equals(attach1,data));
  EnumSet<Database.TDContentOptions> contentOptions=EnumSet.of(Database.TDContentOptions.TDIncludeAttachments,Database.TDContentOptions.TDBigAttachmentsFollow);
  Map<String,Object> attachmentDictForSequence=database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(),contentOptions);
  Map<String,Object> innerDict=(Map<String,Object>)attachmentDictForSequence.get(testAttachmentName);
  if (!innerDict.containsKey("String_Node_Str")) {
    throw new RuntimeException("String_Node_Str");
  }
  if (((Boolean)innerDict.get("String_Node_Str")).booleanValue() == false) {
    throw new RuntimeException("String_Node_Str");
  }
  if (!innerDict.containsKey("String_Node_Str")) {
    throw new RuntimeException("String_Node_Str");
  }
  RevisionInternal rev1WithAttachments=database.getDocumentWithIDAndRev(rev1.getDocId(),rev1.getRevId(),contentOptions);
  Map<String,Object> rev1WithAttachmentsProperties=rev1WithAttachments.getProperties();
  Map<String,Object> rev2Properties=new HashMap<String,Object>();
  rev2Properties.put("String_Node_Str",rev1WithAttachmentsProperties.get("String_Node_Str"));
  rev2Properties.put("String_Node_Str",2);
  RevisionInternal newRev=new RevisionInternal(rev2Properties,database);
  RevisionInternal rev2=database.putRevision(newRev,rev1WithAttachments.getRevId(),false,status);
  Assert.assertEquals(Status.CREATED,status.getCode());
  database.copyAttachmentNamedFromSequenceToSequence(testAttachmentName,rev1WithAttachments.getSequence(),rev2.getSequence());
  Attachment rev2FetchedAttachment=database.getAttachmentForSequence(rev2.getSequence(),testAttachmentName);
  Assert.assertEquals(attachment.getLength(),rev2FetchedAttachment.getLength());
  Assert.assertEquals(attachment.getMetadata(),rev2FetchedAttachment.getMetadata());
  Assert.assertEquals(attachment.getContentType(),rev2FetchedAttachment.getContentType());
  Map<String,Object> rev3Properties=new HashMap<String,Object>();
  rev3Properties.put("String_Node_Str",rev2.getProperties().get("String_Node_Str"));
  rev3Properties.put("String_Node_Str",3);
  rev3Properties.put("String_Node_Str",false);
  RevisionInternal rev3=new RevisionInternal(rev3Properties,database);
  rev3=database.putRevision(rev3,rev2.getRevId(),false,status);
  Assert.assertEquals(Status.CREATED,status.getCode());
  byte[] attach3="String_Node_Str".getBytes();
  database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach3),rev3.getSequence(),testAttachmentName,"String_Node_Str",rev3.getGeneration());
  Attachment rev3FetchedAttachment=database.getAttachmentForSequence(rev3.getSequence(),testAttachmentName);
  data=IOUtils.toByteArray(rev3FetchedAttachment.getContent());
  Assert.assertTrue(Arrays.equals(attach3,data));
  Assert.assertEquals("String_Node_Str",rev3FetchedAttachment.getContentType());
  Set<BlobKey> blobKeys=database.getAttachments().allKeys();
  Assert.assertEquals(2,blobKeys.size());
  database.compact();
  blobKeys=database.getAttachments().allKeys();
  Assert.assertEquals(1,blobKeys.size());
}