Program: 44642
Project: 44642
Buggy source:
@Test public void testSaveXMLorJSONWithBinaryContent() throws Exception {
  RepositoryUser systemUser=getSystemUser();
  ContentObject contentObject=createContentObject(systemUser,"String_Node_Str",true);
  BinaryChannel logoBinaryChannel=loadManagedBinaryChannel(logo,"String_Node_Str");
  BinaryProperty imageProperty=(BinaryProperty)contentObject.getCmsProperty("String_Node_Str");
  imageProperty.addSimpleTypeValue(logoBinaryChannel);
  contentObject=contentService.save(contentObject,false,true,null);
  addEntityToBeDeletedAfterTestIsFinished(contentObject);
  String xml=contentObject.xml(false,true);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,xml,logo,"String_Node_Str",null);
  String json=contentObject.json(false,true);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,json,logo,"String_Node_Str",null);
  xml=contentService.getContentObject(contentObject.getId(),ResourceRepresentationType.XML,FetchLevel.FULL,CacheRegion.NONE,null,true);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,xml,logo,"String_Node_Str",null);
  json=contentService.getContentObject(contentObject.getId(),ResourceRepresentationType.JSON,FetchLevel.FULL,CacheRegion.NONE,null,true);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,json,logo,"String_Node_Str",null);
  Map<String,byte[]> binaryContent=new HashMap<String,byte[]>();
  String imageURL=logoBinaryChannel.buildResourceApiURL(null,null,null,null,null,false,false);
  byte[] contentCopy=Arrays.copyOf(logoBinaryChannel.getContent(),logoBinaryChannel.getContent().length);
  binaryContent.put(imageURL,contentCopy);
  logoBinaryChannel.setContent(null);
  xml=contentObject.xml(false,false);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,xml,logo,"String_Node_Str",binaryContent);
  json=contentObject.json(false,false);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,json,logo,"String_Node_Str",binaryContent);
  xml=contentObject.xml(false,false).replaceAll(Pattern.quote(imageURL),"String_Node_Str");
  binaryContent.put("String_Node_Str",contentCopy);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,xml,logo,"String_Node_Str",binaryContent);
  json=contentObject.json(false,false).replaceAll(Pattern.quote(imageURL),"String_Node_Str");
  binaryContent.put("String_Node_Str",contentCopy);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,json,logo,"String_Node_Str",binaryContent);
}

Fixed version (ground truth):
@Test public void testSaveXMLorJSONWithBinaryContent() throws Exception {
  RepositoryUser systemUser=getSystemUser();
  ContentObject contentObject=createContentObjectForType(TEST_CONTENT_TYPE,systemUser,"String_Node_Str",true);
  BinaryChannel logoBinaryChannel=loadManagedBinaryChannel(logo,"String_Node_Str");
  BinaryProperty imageProperty=(BinaryProperty)contentObject.getCmsProperty("String_Node_Str");
  imageProperty.addSimpleTypeValue(logoBinaryChannel);
  contentObject=contentService.save(contentObject,false,true,null);
  addEntityToBeDeletedAfterTestIsFinished(contentObject);
  String xml=contentObject.xml(false,true);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,xml,logo,"String_Node_Str",null);
  String json=contentObject.json(false,true);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,json,logo,"String_Node_Str",null);
  xml=contentService.getContentObject(contentObject.getId(),ResourceRepresentationType.XML,FetchLevel.FULL,CacheRegion.NONE,null,true);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,xml,logo,"String_Node_Str",null);
  json=contentService.getContentObject(contentObject.getId(),ResourceRepresentationType.JSON,FetchLevel.FULL,CacheRegion.NONE,null,true);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,json,logo,"String_Node_Str",null);
  Map<String,byte[]> binaryContent=new HashMap<String,byte[]>();
  String imageURL=logoBinaryChannel.buildResourceApiURL(null,null,null,null,null,false,false);
  byte[] contentCopy=Arrays.copyOf(logoBinaryChannel.getContent(),logoBinaryChannel.getContent().length);
  binaryContent.put(imageURL,contentCopy);
  logoBinaryChannel.setContent(null);
  xml=contentObject.xml(false,false);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,xml,logo,"String_Node_Str",binaryContent);
  json=contentObject.json(false,false);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,json,logo,"String_Node_Str",binaryContent);
  xml=contentObject.xml(false,false).replaceAll(Pattern.quote(imageURL),"String_Node_Str");
  binaryContent.put("String_Node_Str",contentCopy);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,xml,logo,"String_Node_Str",binaryContent);
  json=contentObject.json(false,false).replaceAll(Pattern.quote(imageURL),"String_Node_Str");
  binaryContent.put("String_Node_Str",contentCopy);
  contentObject=saveAndAssertBinaryContentIsSaved(contentObject,json,logo,"String_Node_Str",binaryContent);
}