Program: 47885
Project: 47885
Buggy source:
/** 
 * Tests if record type is set when different settings of returnFields is used.
 * @throws Exception
 */
@Test public void testScanWithReturnFieldsRecordType() throws Exception {
  String ns="String_Node_Str";
  FieldType f1=typeManager.createFieldType("String_Node_Str",new QName(ns,"String_Node_Str"),Scope.NON_VERSIONED);
  FieldType f2=typeManager.createFieldType("String_Node_Str",new QName(ns,"String_Node_Str"),Scope.NON_VERSIONED);
  FieldType f3=typeManager.createFieldType("String_Node_Str",new QName(ns,"String_Node_Str"),Scope.NON_VERSIONED);
  FieldType f4=typeManager.createFieldType("String_Node_Str",new QName(ns,"String_Node_Str"),Scope.NON_VERSIONED);
  RecordType rt=typeManager.recordTypeBuilder().defaultNamespace(ns).name("String_Node_Str").fieldEntry().use(f1).add().fieldEntry().use(f2).add().fieldEntry().use(f3).add().fieldEntry().use(f4).add().create();
  repository.recordBuilder().recordType(rt.getName()).field(f1.getName(),"String_Node_Str").field(f2.getName(),"String_Node_Str").field(f3.getName(),"String_Node_Str").create();
  RecordScan scan=new RecordScan();
  scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
  scan.setReturnFields(new ReturnFields(ReturnFields.Type.ALL));
  Record record=repository.getScanner(scan).next();
  assertNotNull(record.getRecordTypeName());
  assertEquals(ns,record.getRecordTypeName().getNamespace());
  scan=new RecordScan();
  scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
  scan.setReturnFields(new ReturnFields(ReturnFields.Type.NONE));
  record=repository.getScanner(scan).next();
  assertNotNull(record.getRecordTypeName());
  assertEquals(ns,record.getRecordTypeName().getNamespace());
  scan=new RecordScan();
  scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
  scan.setReturnFields(new ReturnFields(f1.getName(),f2.getName()));
  record=repository.getScanner(scan).next();
  assertNotNull(record.getRecordTypeName());
  assertEquals(ns,record.getRecordTypeName().getNamespace());
}

Fixed version (ground truth):
/** 
 * Tests if record type is set when different settings of returnFields is used.
 */
@Test public void testScanWithReturnFieldsRecordType() throws Exception {
  String ns="String_Node_Str";
  FieldType f1=typeManager.createFieldType("String_Node_Str",new QName(ns,"String_Node_Str"),Scope.NON_VERSIONED);
  FieldType f2=typeManager.createFieldType("String_Node_Str",new QName(ns,"String_Node_Str"),Scope.NON_VERSIONED);
  FieldType f3=typeManager.createFieldType("String_Node_Str",new QName(ns,"String_Node_Str"),Scope.NON_VERSIONED);
  FieldType f4=typeManager.createFieldType("String_Node_Str",new QName(ns,"String_Node_Str"),Scope.NON_VERSIONED);
  RecordType rt=typeManager.recordTypeBuilder().defaultNamespace(ns).name("String_Node_Str").fieldEntry().use(f1).add().fieldEntry().use(f2).add().fieldEntry().use(f3).add().fieldEntry().use(f4).add().create();
  repository.recordBuilder().recordType(rt.getName()).field(f1.getName(),"String_Node_Str").field(f2.getName(),"String_Node_Str").field(f3.getName(),"String_Node_Str").create();
  RecordScan scan=new RecordScan();
  scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
  scan.setReturnFields(new ReturnFields(ReturnFields.Type.ALL));
  Record record=repository.getScanner(scan).next();
  assertNotNull(record.getRecordTypeName());
  assertEquals(ns,record.getRecordTypeName().getNamespace());
  scan=new RecordScan();
  scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
  scan.setReturnFields(new ReturnFields(ReturnFields.Type.NONE));
  record=repository.getScanner(scan).next();
  assertNotNull(record.getRecordTypeName());
  assertEquals(ns,record.getRecordTypeName().getNamespace());
  scan=new RecordScan();
  scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
  scan.setReturnFields(new ReturnFields(f1.getName(),f2.getName()));
  record=repository.getScanner(scan).next();
  assertNotNull(record.getRecordTypeName());
  assertEquals(ns,record.getRecordTypeName().getNamespace());
}