nus-yam/ex-repair huggingface dataset:
Program: 155582
Project: 155582
Buggy source:
@Test public void executeTransaction_warningIfManuallyCancelled(){
  assertEquals(0,realm.where("String_Node_Str").count());
  TestHelper.TestLogger testLogger=new TestHelper.TestLogger();
  try {
    RealmLog.add(testLogger);
    realm.executeTransaction(new DynamicRealm.Transaction(){
      @Override public void execute(      DynamicRealm realm){
        DynamicRealmObject owner=realm.createObject("String_Node_Str");
        owner.setString("String_Node_Str","String_Node_Str");
        realm.cancelTransaction();
        throw new RuntimeException("String_Node_Str");
      }
    }
);
  }
 catch (  RuntimeException ignored) {
    assertEquals(testLogger.message,"String_Node_Str");
  }
 finally {
    RealmLog.remove(testLogger);
  }
  assertEquals(0,realm.where("String_Node_Str").count());
}

Fixed version (ground truth):
@Test public void executeTransaction_warningIfManuallyCancelled(){
  assertEquals(0,realm.where("String_Node_Str").count());
  TestHelper.TestLogger testLogger=new TestHelper.TestLogger();
  try {
    RealmLog.add(testLogger);
    realm.executeTransaction(new DynamicRealm.Transaction(){
      @Override public void execute(      DynamicRealm realm){
        DynamicRealmObject owner=realm.createObject("String_Node_Str");
        owner.setString("String_Node_Str","String_Node_Str");
        realm.cancelTransaction();
        throw new RuntimeException("String_Node_Str");
      }
    }
);
  }
 catch (  RuntimeException ignored) {
    assertEquals("String_Node_Str",testLogger.message);
  }
 finally {
    RealmLog.remove(testLogger);
  }
  assertEquals(0,realm.where("String_Node_Str").count());
}
Program: 155583
Project: 155583
Buggy source:
@Test public void getInstanceClearsCacheWhenFailed(){
  String REALM_NAME="String_Node_Str";
  RealmConfiguration configA=configFactory.createConfiguration(REALM_NAME,TestHelper.getRandomKey(42));
  RealmConfiguration configB=configFactory.createConfiguration(REALM_NAME,TestHelper.getRandomKey(43));
  Realm realm=Realm.getInstance(configA);
  realm.close();
  try {
    Realm.getInstance(configB);
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(expected.getKind(),RealmFileException.Kind.ACCESS_ERROR);
    assertTrue(Realm.deleteRealm(configA));
    realm=Realm.getInstance(configB);
    realm.close();
  }
}

Fixed version (ground truth):
@Test public void getInstanceClearsCacheWhenFailed(){
  String REALM_NAME="String_Node_Str";
  RealmConfiguration configA=configFactory.createConfiguration(REALM_NAME,TestHelper.getRandomKey(42));
  RealmConfiguration configB=configFactory.createConfiguration(REALM_NAME,TestHelper.getRandomKey(43));
  Realm realm=Realm.getInstance(configA);
  realm.close();
  try {
    Realm.getInstance(configB);
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(RealmFileException.Kind.ACCESS_ERROR,expected.getKind());
    assertTrue(Realm.deleteRealm(configA));
    realm=Realm.getInstance(configB);
    realm.close();
  }
}
Program: 155584
Project: 155584
Buggy source:
@Test public void dontCacheWrongConfigurations() throws IOException {
  Realm testRealm;
  String REALM_NAME="String_Node_Str";
  RealmConfiguration wrongConfig=configFactory.createConfigurationBuilder().name(REALM_NAME).encryptionKey(TestHelper.SHA512("String_Node_Str")).schema(StringOnly.class).build();
  RealmConfiguration rightConfig=configFactory.createConfigurationBuilder().name(REALM_NAME).encryptionKey(TestHelper.SHA512("String_Node_Str")).schema(StringOnly.class).build();
  testRealm=Realm.getInstance(rightConfig);
  assertNotNull(testRealm);
  testRealm.close();
  try {
    Realm.getInstance(wrongConfig);
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(expected.getKind(),RealmFileException.Kind.ACCESS_ERROR);
  }
  testRealm=Realm.getInstance(rightConfig);
  assertNotNull(testRealm);
  testRealm.close();
}

Fixed version (ground truth):
@Test public void dontCacheWrongConfigurations() throws IOException {
  Realm testRealm;
  String REALM_NAME="String_Node_Str";
  RealmConfiguration wrongConfig=configFactory.createConfigurationBuilder().name(REALM_NAME).encryptionKey(TestHelper.SHA512("String_Node_Str")).schema(StringOnly.class).build();
  RealmConfiguration rightConfig=configFactory.createConfigurationBuilder().name(REALM_NAME).encryptionKey(TestHelper.SHA512("String_Node_Str")).schema(StringOnly.class).build();
  testRealm=Realm.getInstance(rightConfig);
  assertNotNull(testRealm);
  testRealm.close();
  try {
    Realm.getInstance(wrongConfig);
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(RealmFileException.Kind.ACCESS_ERROR,expected.getKind());
  }
  testRealm=Realm.getInstance(rightConfig);
  assertNotNull(testRealm);
  testRealm.close();
}
Program: 155585
Project: 155585
Buggy source:
@Test public void assetFileFakeFile(){
  Realm.deleteRealm(new RealmConfiguration.Builder(context).build());
  RealmConfiguration configuration=new RealmConfiguration.Builder(context).assetFile("String_Node_Str").build();
  try {
    Realm.getInstance(configuration);
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(expected.getKind(),RealmFileException.Kind.ACCESS_ERROR);
  }
}

Fixed version (ground truth):
@Test public void assetFileFakeFile(){
  Realm.deleteRealm(new RealmConfiguration.Builder(context).build());
  RealmConfiguration configuration=new RealmConfiguration.Builder(context).assetFile("String_Node_Str").build();
  try {
    Realm.getInstance(configuration);
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(RealmFileException.Kind.ACCESS_ERROR,expected.getKind());
  }
}
Program: 155586
Project: 155586
Buggy source:
@Test public void inMemoryRealm(){
  testRealm.beginTransaction();
  Dog dog=testRealm.createObject(Dog.class);
  dog.setName("String_Node_Str");
  testRealm.commitTransaction();
  assertEquals(testRealm.where(Dog.class).count(),1);
  assertEquals(testRealm.where(Dog.class).findFirst().getName(),"String_Node_Str");
  testRealm.close();
  testRealm=Realm.getInstance(inMemConf);
  assertEquals(testRealm.where(Dog.class).count(),0);
}

Fixed version (ground truth):
@Test public void inMemoryRealm(){
  testRealm.beginTransaction();
  Dog dog=testRealm.createObject(Dog.class);
  dog.setName("String_Node_Str");
  testRealm.commitTransaction();
  assertEquals(1,testRealm.where(Dog.class).count());
  assertEquals("String_Node_Str",testRealm.where(Dog.class).findFirst().getName());
  testRealm.close();
  testRealm=Realm.getInstance(inMemConf);
  assertEquals(0,testRealm.where(Dog.class).count());
}
Program: 155587
Project: 155587
Buggy source:
@Test public void writeCopyTo(){
  byte[] key=TestHelper.getRandomKey();
  String fileName=IDENTIFIER + "String_Node_Str";
  String encFileName=IDENTIFIER + "String_Node_Str";
  RealmConfiguration conf=configFactory.createConfigurationBuilder().name(fileName).build();
  RealmConfiguration encConf=configFactory.createConfigurationBuilder().name(encFileName).encryptionKey(key).build();
  Realm.deleteRealm(conf);
  Realm.deleteRealm(encConf);
  testRealm.beginTransaction();
  Dog dog=testRealm.createObject(Dog.class);
  dog.setName("String_Node_Str");
  testRealm.commitTransaction();
  testRealm.writeCopyTo(new File(configFactory.getRoot(),fileName));
  Realm onDiskRealm=Realm.getInstance(conf);
  assertEquals(onDiskRealm.where(Dog.class).count(),1);
  onDiskRealm.close();
  testRealm.writeEncryptedCopyTo(new File(configFactory.getRoot(),encFileName),key);
  onDiskRealm=Realm.getInstance(encConf);
  assertEquals(onDiskRealm.where(Dog.class).count(),1);
  onDiskRealm.close();
  try {
    RealmConfiguration wrongKeyConf=configFactory.createConfigurationBuilder().name(encFileName).encryptionKey(TestHelper.getRandomKey(42)).build();
    Realm.getInstance(wrongKeyConf);
    fail("String_Node_Str");
  }
 catch (  RealmFileException expected) {
    assertEquals(expected.getKind(),RealmFileException.Kind.ACCESS_ERROR);
  }
}

Fixed version (ground truth):
@Test public void writeCopyTo(){
  byte[] key=TestHelper.getRandomKey();
  String fileName=IDENTIFIER + "String_Node_Str";
  String encFileName=IDENTIFIER + "String_Node_Str";
  RealmConfiguration conf=configFactory.createConfigurationBuilder().name(fileName).build();
  RealmConfiguration encConf=configFactory.createConfigurationBuilder().name(encFileName).encryptionKey(key).build();
  Realm.deleteRealm(conf);
  Realm.deleteRealm(encConf);
  testRealm.beginTransaction();
  Dog dog=testRealm.createObject(Dog.class);
  dog.setName("String_Node_Str");
  testRealm.commitTransaction();
  testRealm.writeCopyTo(new File(configFactory.getRoot(),fileName));
  Realm onDiskRealm=Realm.getInstance(conf);
  assertEquals(1,onDiskRealm.where(Dog.class).count());
  onDiskRealm.close();
  testRealm.writeEncryptedCopyTo(new File(configFactory.getRoot(),encFileName),key);
  onDiskRealm=Realm.getInstance(encConf);
  assertEquals(1,onDiskRealm.where(Dog.class).count());
  onDiskRealm.close();
  try {
    RealmConfiguration wrongKeyConf=configFactory.createConfigurationBuilder().name(encFileName).encryptionKey(TestHelper.getRandomKey(42)).build();
    Realm.getInstance(wrongKeyConf);
    fail("String_Node_Str");
  }
 catch (  RealmFileException expected) {
    assertEquals(RealmFileException.Kind.ACCESS_ERROR,expected.getKind());
  }
}
Program: 155588
Project: 155588
Buggy source:
@Override public void run(){
  Realm realm=Realm.getInstance(inMemConf);
  realm.beginTransaction();
  Dog dog=realm.createObject(Dog.class);
  dog.setName("String_Node_Str");
  realm.commitTransaction();
  try {
    assertEquals(realm.where(Dog.class).count(),1);
  }
 catch (  AssertionFailedError afe) {
    threadError[0]=afe;
    realm.close();
    return;
  }
  workerCommittedLatch.countDown();
  try {
    realmInMainClosedLatch.await(TestHelper.SHORT_WAIT_SECS,TimeUnit.SECONDS);
  }
 catch (  InterruptedException e) {
    threadError[0]=new AssertionFailedError("String_Node_Str");
    realm.close();
    return;
  }
  realm.close();
  workerClosedLatch.countDown();
}

Fixed version (ground truth):
@Override public void run(){
  Realm realm=Realm.getInstance(inMemConf);
  realm.beginTransaction();
  Dog dog=realm.createObject(Dog.class);
  dog.setName("String_Node_Str");
  realm.commitTransaction();
  try {
    assertEquals(1,realm.where(Dog.class).count());
  }
 catch (  AssertionFailedError afe) {
    threadError[0]=afe;
    realm.close();
    return;
  }
  workerCommittedLatch.countDown();
  try {
    realmInMainClosedLatch.await(TestHelper.SHORT_WAIT_SECS,TimeUnit.SECONDS);
  }
 catch (  InterruptedException e) {
    threadError[0]=new AssertionFailedError("String_Node_Str");
    realm.close();
    return;
  }
  realm.close();
  workerClosedLatch.countDown();
}
Program: 155589
Project: 155589
Buggy source:
@Test public void inMemoryRealmWithDifferentNames(){
  testRealm.beginTransaction();
  Dog dog=testRealm.createObject(Dog.class);
  dog.setName("String_Node_Str");
  testRealm.commitTransaction();
  RealmConfiguration inMemConf2=configFactory.createConfigurationBuilder().name(IDENTIFIER + "String_Node_Str").inMemory().build();
  Realm testRealm2=Realm.getInstance(inMemConf2);
  testRealm2.beginTransaction();
  Dog dog2=testRealm2.createObject(Dog.class);
  dog2.setName("String_Node_Str");
  testRealm2.commitTransaction();
  assertEquals(testRealm.where(Dog.class).count(),1);
  assertEquals(testRealm.where(Dog.class).findFirst().getName(),"String_Node_Str");
  assertEquals(testRealm2.where(Dog.class).count(),1);
  assertEquals(testRealm2.where(Dog.class).findFirst().getName(),"String_Node_Str");
  testRealm2.close();
}

Fixed version (ground truth):
@Test public void inMemoryRealmWithDifferentNames(){
  testRealm.beginTransaction();
  Dog dog=testRealm.createObject(Dog.class);
  dog.setName("String_Node_Str");
  testRealm.commitTransaction();
  RealmConfiguration inMemConf2=configFactory.createConfigurationBuilder().name(IDENTIFIER + "String_Node_Str").inMemory().build();
  Realm testRealm2=Realm.getInstance(inMemConf2);
  testRealm2.beginTransaction();
  Dog dog2=testRealm2.createObject(Dog.class);
  dog2.setName("String_Node_Str");
  testRealm2.commitTransaction();
  assertEquals(1,testRealm.where(Dog.class).count());
  assertEquals("String_Node_Str",testRealm.where(Dog.class).findFirst().getName());
  assertEquals(1,testRealm2.where(Dog.class).count());
  assertEquals("String_Node_Str",testRealm2.where(Dog.class).findFirst().getName());
  testRealm2.close();
}
Program: 155591
Project: 155591
Buggy source:
public void testCreateInitialRealm() throws InterruptedException {
  new InterprocessHandler(new Runnable(){
    @Override public void run(){
      testRealm=Realm.getInstance(new RealmConfiguration.Builder(getContext()).build());
      assertEquals(testRealm.where(AllTypes.class).count(),0);
      testRealm.beginTransaction();
      testRealm.createObject(AllTypes.class);
      testRealm.commitTransaction();
      triggerServiceStep(RemoteProcessService.stepCreateInitialRealm_A);
    }
  }
){
    @Override public void handleMessage(    Message msg){
      super.handleMessage(msg);
      if (msg.what == RemoteProcessService.stepCreateInitialRealm_A.message) {
        clearTimeoutFlag();
        done();
      }
 else {
        assertTrue(false);
      }
    }
  }
;
  Looper.loop();
}

Fixed version (ground truth):
public void testCreateInitialRealm() throws InterruptedException {
  new InterprocessHandler(new Runnable(){
    @Override public void run(){
      testRealm=Realm.getInstance(new RealmConfiguration.Builder(getContext()).build());
      assertEquals(0,testRealm.where(AllTypes.class).count());
      testRealm.beginTransaction();
      testRealm.createObject(AllTypes.class);
      testRealm.commitTransaction();
      triggerServiceStep(RemoteProcessService.stepCreateInitialRealm_A);
    }
  }
){
    @Override public void handleMessage(    Message msg){
      super.handleMessage(msg);
      if (msg.what == RemoteProcessService.stepCreateInitialRealm_A.message) {
        clearTimeoutFlag();
        done();
      }
 else {
        assertTrue(false);
      }
    }
  }
;
  Looper.loop();
}
Program: 155592
Project: 155592
Buggy source:
@Override public void run(){
  testRealm=Realm.getInstance(new RealmConfiguration.Builder(getContext()).build());
  assertEquals(testRealm.where(AllTypes.class).count(),0);
  testRealm.beginTransaction();
  testRealm.createObject(AllTypes.class);
  testRealm.commitTransaction();
  triggerServiceStep(RemoteProcessService.stepCreateInitialRealm_A);
}

Fixed version (ground truth):
@Override public void run(){
  testRealm=Realm.getInstance(new RealmConfiguration.Builder(getContext()).build());
  assertEquals(0,testRealm.where(AllTypes.class).count());
  testRealm.beginTransaction();
  testRealm.createObject(AllTypes.class);
  testRealm.commitTransaction();
  triggerServiceStep(RemoteProcessService.stepCreateInitialRealm_A);
}
Program: 155593
Project: 155593
Buggy source:
@Test public void executeTransaction_cancelInsideClosureThrowsException(){
  assertEquals(0,realm.where(Owner.class).count());
  TestHelper.TestLogger testLogger=new TestHelper.TestLogger();
  try {
    RealmLog.add(testLogger);
    realm.executeTransaction(new Realm.Transaction(){
      @Override public void execute(      Realm realm){
        Owner owner=realm.createObject(Owner.class);
        owner.setName("String_Node_Str");
        realm.cancelTransaction();
        throw new RuntimeException("String_Node_Str");
      }
    }
);
  }
 catch (  RuntimeException ignored) {
    assertEquals(testLogger.message,"String_Node_Str");
  }
 finally {
    RealmLog.remove(testLogger);
  }
  assertEquals(0,realm.where(Owner.class).count());
}

Fixed version (ground truth):
@Test public void executeTransaction_cancelInsideClosureThrowsException(){
  assertEquals(0,realm.where(Owner.class).count());
  TestHelper.TestLogger testLogger=new TestHelper.TestLogger();
  try {
    RealmLog.add(testLogger);
    realm.executeTransaction(new Realm.Transaction(){
      @Override public void execute(      Realm realm){
        Owner owner=realm.createObject(Owner.class);
        owner.setName("String_Node_Str");
        realm.cancelTransaction();
        throw new RuntimeException("String_Node_Str");
      }
    }
);
  }
 catch (  RuntimeException ignored) {
    assertEquals("String_Node_Str",testLogger.message);
  }
 finally {
    RealmLog.remove(testLogger);
  }
  assertEquals(0,realm.where(Owner.class).count());
}
Program: 155594
Project: 155594
Buggy source:
@Test public void getInstance_writeProtectedFile() throws IOException {
  String REALM_FILE="String_Node_Str";
  File folder=configFactory.getRoot();
  File realmFile=new File(folder,REALM_FILE);
  assertFalse(realmFile.exists());
  assertTrue(realmFile.createNewFile());
  assertTrue(realmFile.setWritable(false));
  try {
    Realm.getInstance(new RealmConfiguration.Builder(InstrumentationRegistry.getTargetContext()).directory(folder).name(REALM_FILE).build());
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(expected.getKind(),RealmFileException.Kind.PERMISSION_DENIED);
  }
}

Fixed version (ground truth):
@Test public void getInstance_writeProtectedFile() throws IOException {
  String REALM_FILE="String_Node_Str";
  File folder=configFactory.getRoot();
  File realmFile=new File(folder,REALM_FILE);
  assertFalse(realmFile.exists());
  assertTrue(realmFile.createNewFile());
  assertTrue(realmFile.setWritable(false));
  try {
    Realm.getInstance(new RealmConfiguration.Builder(InstrumentationRegistry.getTargetContext()).directory(folder).name(REALM_FILE).build());
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(RealmFileException.Kind.PERMISSION_DENIED,expected.getKind());
  }
}
Program: 155595
Project: 155595
Buggy source:
@Test public void getInstance_writeProtectedFileWithContext() throws IOException {
  String REALM_FILE="String_Node_Str";
  File folder=configFactory.getRoot();
  File realmFile=new File(folder,REALM_FILE);
  assertFalse(realmFile.exists());
  assertTrue(realmFile.createNewFile());
  assertTrue(realmFile.setWritable(false));
  try {
    Realm.getInstance(new RealmConfiguration.Builder(context).directory(folder).name(REALM_FILE).build());
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(expected.getKind(),RealmFileException.Kind.PERMISSION_DENIED);
  }
}

Fixed version (ground truth):
@Test public void getInstance_writeProtectedFileWithContext() throws IOException {
  String REALM_FILE="String_Node_Str";
  File folder=configFactory.getRoot();
  File realmFile=new File(folder,REALM_FILE);
  assertFalse(realmFile.exists());
  assertTrue(realmFile.createNewFile());
  assertTrue(realmFile.setWritable(false));
  try {
    Realm.getInstance(new RealmConfiguration.Builder(context).directory(folder).name(REALM_FILE).build());
    fail();
  }
 catch (  RealmFileException expected) {
    assertEquals(RealmFileException.Kind.PERMISSION_DENIED,expected.getKind());
  }
}
Program: 155596
Project: 155596
Buggy source:
@Test @RunTestInLooperThread public void non_looper_thread_commit_realmresults_sync(){
  final Realm realm=looperThread.getRealm();
  realm.addChangeListener(new RealmChangeListener<Realm>(){
    @Override public void onChange(    Realm object){
      if (realm.where(Dog.class).count() == 2) {
        looperThread.postRunnable(new Runnable(){
          @Override public void run(){
            assertEquals(typebasedCommitInvocations.get(),1);
            looperThread.testComplete();
          }
        }
);
      }
    }
  }
);
  realm.beginTransaction();
  realm.createObject(Dog.class);
  realm.commitTransaction();
  final RealmResults<Dog> dogs=realm.where(Dog.class).findAll();
  looperThread.keepStrongReference(dogs);
  dogs.addChangeListener(new RealmChangeListener<RealmResults<Dog>>(){
    @Override public void onChange(    RealmResults<Dog> object){
      typebasedCommitInvocations.incrementAndGet();
      assertEquals(2,dogs.size());
    }
  }
);
  Thread thread=new Thread(){
    @Override public void run(){
      Realm bgRealm=Realm.getInstance(realm.getConfiguration());
      bgRealm.beginTransaction();
      bgRealm.createObject(Dog.class);
      bgRealm.commitTransaction();
      bgRealm.close();
    }
  }
;
  thread.start();
  try {
    thread.join();
  }
 catch (  InterruptedException e) {
    fail(e.getMessage());
  }
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void non_looper_thread_commit_realmresults_sync(){
  final Realm realm=looperThread.getRealm();
  realm.addChangeListener(new RealmChangeListener<Realm>(){
    @Override public void onChange(    Realm object){
      if (realm.where(Dog.class).count() == 2) {
        looperThread.postRunnable(new Runnable(){
          @Override public void run(){
            assertEquals(1,typebasedCommitInvocations.get());
            looperThread.testComplete();
          }
        }
);
      }
    }
  }
);
  realm.beginTransaction();
  realm.createObject(Dog.class);
  realm.commitTransaction();
  final RealmResults<Dog> dogs=realm.where(Dog.class).findAll();
  looperThread.keepStrongReference(dogs);
  dogs.addChangeListener(new RealmChangeListener<RealmResults<Dog>>(){
    @Override public void onChange(    RealmResults<Dog> object){
      typebasedCommitInvocations.incrementAndGet();
      assertEquals(2,dogs.size());
    }
  }
);
  Thread thread=new Thread(){
    @Override public void run(){
      Realm bgRealm=Realm.getInstance(realm.getConfiguration());
      bgRealm.beginTransaction();
      bgRealm.createObject(Dog.class);
      bgRealm.commitTransaction();
      bgRealm.close();
    }
  }
;
  thread.start();
  try {
    thread.join();
  }
 catch (  InterruptedException e) {
    fail(e.getMessage());
  }
}
Program: 155597
Project: 155597
Buggy source:
@Test public void sort(){
  Collection collection=new Collection(sharedRealm,table.where().greaterThan(new long[]{2},oneNullTable,1));
  SortDescriptor sortDescriptor=SortDescriptor.getTestInstance(table,new long[]{2});
  Collection collection2=collection.sort(sortDescriptor);
  assertTrue(collection.getNativePtr() != collection2.getNativePtr());
  assertEquals(2,collection.size());
  assertEquals(2,collection2.size());
  assertEquals(collection2.getUncheckedRow(0).getLong(2),3);
  assertEquals(collection2.getUncheckedRow(1).getLong(2),4);
}

Fixed version (ground truth):
@Test public void sort(){
  Collection collection=new Collection(sharedRealm,table.where().greaterThan(new long[]{2},oneNullTable,1));
  SortDescriptor sortDescriptor=SortDescriptor.getTestInstance(table,new long[]{2});
  Collection collection2=collection.sort(sortDescriptor);
  assertTrue(collection.getNativePtr() != collection2.getNativePtr());
  assertEquals(2,collection.size());
  assertEquals(2,collection2.size());
  assertEquals(3,collection2.getUncheckedRow(0).getLong(2));
  assertEquals(4,collection2.getUncheckedRow(1).getLong(2));
}
Program: 155598
Project: 155598
Buggy source:
@Test public void constructor_withDistinct(){
  SortDescriptor distinctDescriptor=SortDescriptor.getInstanceForDistinct(null,table,"String_Node_Str");
  Collection collection=new Collection(sharedRealm,table.where(),null,distinctDescriptor);
  assertEquals(collection.size(),3);
  assertEquals(collection.getUncheckedRow(0).getString(0),"String_Node_Str");
  assertEquals(collection.getUncheckedRow(1).getString(0),"String_Node_Str");
  assertEquals(collection.getUncheckedRow(2).getString(0),"String_Node_Str");
}

Fixed version (ground truth):
@Test public void constructor_withDistinct(){
  SortDescriptor distinctDescriptor=SortDescriptor.getInstanceForDistinct(null,table,"String_Node_Str");
  Collection collection=new Collection(sharedRealm,table.where(),null,distinctDescriptor);
  assertEquals(3,collection.size());
  assertEquals("String_Node_Str",collection.getUncheckedRow(0).getString(0));
  assertEquals("String_Node_Str",collection.getUncheckedRow(1).getString(0));
  assertEquals("String_Node_Str",collection.getUncheckedRow(2).getString(0));
}
Program: 155599
Project: 155599
Buggy source:
@Test @RunTestInLooperThread public void addListener_queryReturned(){
  final SharedRealm sharedRealm=getSharedRealm();
  Table table=sharedRealm.getTable("String_Node_Str");
  final Collection collection=new Collection(sharedRealm,table.where());
  looperThread.keepStrongReference(collection);
  assertEquals(collection.size(),4);
  collection.addListener(collection,new RealmChangeListener<Collection>(){
    @Override public void onChange(    Collection collection1){
      assertEquals(collection,collection1);
      assertEquals(5,collection1.size());
      sharedRealm.close();
      looperThread.testComplete();
    }
  }
);
  addRowAsync();
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void addListener_queryReturned(){
  final SharedRealm sharedRealm=getSharedRealm();
  Table table=sharedRealm.getTable("String_Node_Str");
  final Collection collection=new Collection(sharedRealm,table.where());
  looperThread.keepStrongReference(collection);
  assertEquals(4,collection.size());
  collection.addListener(collection,new RealmChangeListener<Collection>(){
    @Override public void onChange(    Collection collection1){
      assertEquals(collection,collection1);
      assertEquals(5,collection1.size());
      sharedRealm.close();
      looperThread.testComplete();
    }
  }
);
  addRowAsync();
}
Program: 155600
Project: 155600
Buggy source:
@Test public void nullValues(){
  Table table=TestHelper.createTable(sharedRealm,"String_Node_Str");
  long colStringIndex=table.addColumn(RealmFieldType.STRING,"String_Node_Str",true);
  long colIntIndex=table.addColumn(RealmFieldType.INTEGER,"String_Node_Str",true);
  table.addColumn(RealmFieldType.FLOAT,"String_Node_Str");
  table.addColumn(RealmFieldType.DOUBLE,"String_Node_Str");
  long colBoolIndex=table.addColumn(RealmFieldType.BOOLEAN,"String_Node_Str",true);
  table.addColumn(RealmFieldType.DATE,"String_Node_Str");
  table.addColumn(RealmFieldType.BINARY,"String_Node_Str");
  long rowIndex=OsObject.createRow(table);
  UncheckedRow row=table.getUncheckedRow(rowIndex);
  row.setString(colStringIndex,"String_Node_Str");
  assertEquals(row.getString(colStringIndex),"String_Node_Str");
  row.setNull(colStringIndex);
  assertNull(row.getString(colStringIndex));
  row.setLong(colIntIndex,1);
  assertFalse(row.isNull(colIntIndex));
  row.setNull(colIntIndex);
  assertTrue(row.isNull(colIntIndex));
  row.setBoolean(colBoolIndex,true);
  assertFalse(row.isNull(colBoolIndex));
  row.setNull(colBoolIndex);
  assertTrue(row.isNull(colBoolIndex));
}

Fixed version (ground truth):
@Test public void nullValues(){
  Table table=TestHelper.createTable(sharedRealm,"String_Node_Str");
  long colStringIndex=table.addColumn(RealmFieldType.STRING,"String_Node_Str",true);
  long colIntIndex=table.addColumn(RealmFieldType.INTEGER,"String_Node_Str",true);
  table.addColumn(RealmFieldType.FLOAT,"String_Node_Str");
  table.addColumn(RealmFieldType.DOUBLE,"String_Node_Str");
  long colBoolIndex=table.addColumn(RealmFieldType.BOOLEAN,"String_Node_Str",true);
  table.addColumn(RealmFieldType.DATE,"String_Node_Str");
  table.addColumn(RealmFieldType.BINARY,"String_Node_Str");
  long rowIndex=OsObject.createRow(table);
  UncheckedRow row=table.getUncheckedRow(rowIndex);
  row.setString(colStringIndex,"String_Node_Str");
  assertEquals("String_Node_Str",row.getString(colStringIndex));
  row.setNull(colStringIndex);
  assertNull(row.getString(colStringIndex));
  row.setLong(colIntIndex,1);
  assertFalse(row.isNull(colIntIndex));
  row.setNull(colIntIndex);
  assertTrue(row.isNull(colIntIndex));
  row.setBoolean(colBoolIndex,true);
  assertFalse(row.isNull(colBoolIndex));
  row.setNull(colBoolIndex);
  assertTrue(row.isNull(colBoolIndex));
}
Program: 155601
Project: 155601
Buggy source:
public void testParseJsonDateToDate(){
  String jsonDate="String_Node_Str";
  Date output=JsonUtils.stringToDate(jsonDate);
  assertEquals(output.getTime(),1198908717056L);
}

Fixed version (ground truth):
public void testParseJsonDateToDate(){
  String jsonDate="String_Node_Str";
  Date output=JsonUtils.stringToDate(jsonDate);
  assertEquals(1198908717056L,output.getTime());
}
Program: 155602
Project: 155602
Buggy source:
@Test @RunTestInLooperThread public void findAllSortedAsync(){
  final DynamicRealm dynamicRealm=initializeDynamicRealm();
  final RealmResults<DynamicRealmObject> allTypes=dynamicRealm.where(AllTypes.CLASS_NAME).between(AllTypes.FIELD_LONG,0,4).findAllSortedAsync(AllTypes.FIELD_STRING,Sort.DESCENDING);
  assertFalse(allTypes.isLoaded());
  assertEquals(0,allTypes.size());
  allTypes.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>(){
    @Override public void onChange(    RealmResults<DynamicRealmObject> object){
      assertEquals(5,allTypes.size());
      for (int i=0; i < 5; i++) {
        int iteration=(4 - i);
        assertEquals("String_Node_Str" + iteration,allTypes.get(4 - iteration).getString(AllTypes.FIELD_STRING));
      }
      dynamicRealm.close();
      looperThread.testComplete();
    }
  }
);
  looperThread.keepStrongReference.add(allTypes);
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void findAllSortedAsync(){
  final DynamicRealm dynamicRealm=initializeDynamicRealm();
  final RealmResults<DynamicRealmObject> allTypes=dynamicRealm.where(AllTypes.CLASS_NAME).between(AllTypes.FIELD_LONG,0,4).findAllSortedAsync(AllTypes.FIELD_STRING,Sort.DESCENDING);
  assertFalse(allTypes.isLoaded());
  assertEquals(0,allTypes.size());
  allTypes.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>(){
    @Override public void onChange(    RealmResults<DynamicRealmObject> object){
      assertEquals(5,allTypes.size());
      for (int i=0; i < 5; i++) {
        int iteration=(4 - i);
        assertEquals("String_Node_Str" + iteration,allTypes.get(4 - iteration).getString(AllTypes.FIELD_STRING));
      }
      dynamicRealm.close();
      looperThread.testComplete();
    }
  }
);
  looperThread.keepStrongReference(allTypes);
}
Program: 155603
Project: 155603
Buggy source:
@Test @RunTestInLooperThread public void findFirstAsync(){
  final DynamicRealm dynamicRealm=initializeDynamicRealm();
  final DynamicRealmObject allTypes=dynamicRealm.where(AllTypes.CLASS_NAME).between(AllTypes.FIELD_LONG,4,9).findFirstAsync();
  assertFalse(allTypes.isLoaded());
  looperThread.keepStrongReference.add(allTypes);
  allTypes.addChangeListener(new RealmChangeListener<DynamicRealmObject>(){
    @Override public void onChange(    DynamicRealmObject object){
      assertEquals("String_Node_Str",allTypes.getString(AllTypes.FIELD_STRING));
      dynamicRealm.close();
      looperThread.testComplete();
    }
  }
);
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void findFirstAsync(){
  final DynamicRealm dynamicRealm=initializeDynamicRealm();
  final DynamicRealmObject allTypes=dynamicRealm.where(AllTypes.CLASS_NAME).between(AllTypes.FIELD_LONG,4,9).findFirstAsync();
  assertFalse(allTypes.isLoaded());
  looperThread.keepStrongReference(allTypes);
  allTypes.addChangeListener(new RealmChangeListener<DynamicRealmObject>(){
    @Override public void onChange(    DynamicRealmObject object){
      assertEquals("String_Node_Str",allTypes.getString(AllTypes.FIELD_STRING));
      dynamicRealm.close();
      looperThread.testComplete();
    }
  }
);
}
Program: 155605
Project: 155605
Buggy source:
@Test @RunTestInLooperThread public void findAllAsync(){
  final DynamicRealm dynamicRealm=initializeDynamicRealm();
  final RealmResults<DynamicRealmObject> allTypes=dynamicRealm.where(AllTypes.CLASS_NAME).between(AllTypes.FIELD_LONG,4,9).findAllAsync();
  assertFalse(allTypes.isLoaded());
  assertEquals(0,allTypes.size());
  allTypes.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>(){
    @Override public void onChange(    RealmResults<DynamicRealmObject> object){
      assertEquals(6,allTypes.size());
      for (int i=0; i < allTypes.size(); i++) {
        assertEquals("String_Node_Str" + (4 + i),allTypes.get(i).getString(AllTypes.FIELD_STRING));
      }
      dynamicRealm.close();
      looperThread.testComplete();
    }
  }
);
  looperThread.keepStrongReference.add(allTypes);
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void findAllAsync(){
  final DynamicRealm dynamicRealm=initializeDynamicRealm();
  final RealmResults<DynamicRealmObject> allTypes=dynamicRealm.where(AllTypes.CLASS_NAME).between(AllTypes.FIELD_LONG,4,9).findAllAsync();
  assertFalse(allTypes.isLoaded());
  assertEquals(0,allTypes.size());
  allTypes.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>(){
    @Override public void onChange(    RealmResults<DynamicRealmObject> object){
      assertEquals(6,allTypes.size());
      for (int i=0; i < allTypes.size(); i++) {
        assertEquals("String_Node_Str" + (4 + i),allTypes.get(i).getString(AllTypes.FIELD_STRING));
      }
      dynamicRealm.close();
      looperThread.testComplete();
    }
  }
);
  looperThread.keepStrongReference(allTypes);
}
Program: 155606
Project: 155606
Buggy source:
private DynamicRealm initializeDynamicRealm(){
  RealmConfiguration defaultConfig=looperThread.realmConfiguration;
  final DynamicRealm dynamicRealm=DynamicRealm.getInstance(defaultConfig);
  populateTestRealm(dynamicRealm,10);
  looperThread.keepStrongReference.add(dynamicRealm);
  return dynamicRealm;
}

Fixed version (ground truth):
private DynamicRealm initializeDynamicRealm(){
  RealmConfiguration defaultConfig=looperThread.getConfiguration();
  final DynamicRealm dynamicRealm=DynamicRealm.getInstance(defaultConfig);
  populateTestRealm(dynamicRealm,10);
  looperThread.keepStrongReference(dynamicRealm);
  return dynamicRealm;
}
Program: 155607
Project: 155607
Buggy source:
@Test @RunTestInLooperThread public void notification_notSentAfterUnregisterListenerModelObject(){
  final Realm looperThreadRealm=looperThread.realm;
  looperThreadRealm.beginTransaction();
  AllJavaTypes child=looperThreadRealm.createObject(AllJavaTypes.class,10);
  looperThreadRealm.commitTransaction();
  RealmChangeListener<AllJavaTypes> listener=new RealmChangeListener<AllJavaTypes>(){
    @Override public void onChange(    AllJavaTypes object){
      fail("String_Node_Str");
    }
  }
;
  child.addChangeListener(listener);
  child.removeChangeListener(listener);
  looperThreadRealm.beginTransaction();
  AllJavaTypes parent=looperThreadRealm.createObject(AllJavaTypes.class,1);
  parent.setFieldObject(child);
  looperThreadRealm.commitTransaction();
  verifyPostConditions(looperThreadRealm,new PostConditions(){
    @Override public void run(    Realm realm){
      assertEquals(2,looperThreadRealm.where(AllJavaTypes.class).findAll().size());
    }
  }
,child,parent);
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void notification_notSentAfterUnregisterListenerModelObject(){
  final Realm looperThreadRealm=looperThread.getRealm();
  looperThreadRealm.beginTransaction();
  AllJavaTypes child=looperThreadRealm.createObject(AllJavaTypes.class,10);
  looperThreadRealm.commitTransaction();
  RealmChangeListener<AllJavaTypes> listener=new RealmChangeListener<AllJavaTypes>(){
    @Override public void onChange(    AllJavaTypes object){
      fail("String_Node_Str");
    }
  }
;
  child.addChangeListener(listener);
  child.removeChangeListener(listener);
  looperThreadRealm.beginTransaction();
  AllJavaTypes parent=looperThreadRealm.createObject(AllJavaTypes.class,1);
  parent.setFieldObject(child);
  looperThreadRealm.commitTransaction();
  verifyPostConditions(looperThreadRealm,new PostConditions(){
    @Override public void run(    Realm realm){
      assertEquals(2,looperThreadRealm.where(AllJavaTypes.class).findAll().size());
    }
  }
,child,parent);
}
Program: 155608
Project: 155608
Buggy source:
@Test @RunTestInLooperThread public void notification_notSentAfterUnregisterListenerRealmResults(){
  final Realm looperThreadRealm=looperThread.realm;
  looperThreadRealm.beginTransaction();
  AllJavaTypes child=looperThreadRealm.createObject(AllJavaTypes.class,10);
  looperThreadRealm.commitTransaction();
  RealmChangeListener<RealmResults<AllJavaTypes>> listener=new RealmChangeListener<RealmResults<AllJavaTypes>>(){
    @Override public void onChange(    RealmResults<AllJavaTypes> object){
      fail("String_Node_Str");
    }
  }
;
  RealmResults<AllJavaTypes> objParents=child.getObjectParents();
  objParents.addChangeListener(listener);
  objParents.removeChangeListener(listener);
  looperThreadRealm.beginTransaction();
  AllJavaTypes parent=looperThreadRealm.createObject(AllJavaTypes.class,1);
  parent.setFieldObject(child);
  looperThreadRealm.commitTransaction();
  verifyPostConditions(looperThreadRealm,new PostConditions(){
    @Override public void run(    Realm realm){
      assertEquals(2,looperThreadRealm.where(AllJavaTypes.class).findAll().size());
    }
  }
,child,parent);
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void notification_notSentAfterUnregisterListenerRealmResults(){
  final Realm looperThreadRealm=looperThread.getRealm();
  looperThreadRealm.beginTransaction();
  AllJavaTypes child=looperThreadRealm.createObject(AllJavaTypes.class,10);
  looperThreadRealm.commitTransaction();
  RealmChangeListener<RealmResults<AllJavaTypes>> listener=new RealmChangeListener<RealmResults<AllJavaTypes>>(){
    @Override public void onChange(    RealmResults<AllJavaTypes> object){
      fail("String_Node_Str");
    }
  }
;
  RealmResults<AllJavaTypes> objParents=child.getObjectParents();
  objParents.addChangeListener(listener);
  objParents.removeChangeListener(listener);
  looperThreadRealm.beginTransaction();
  AllJavaTypes parent=looperThreadRealm.createObject(AllJavaTypes.class,1);
  parent.setFieldObject(child);
  looperThreadRealm.commitTransaction();
  verifyPostConditions(looperThreadRealm,new PostConditions(){
    @Override public void run(    Realm realm){
      assertEquals(2,looperThreadRealm.where(AllJavaTypes.class).findAll().size());
    }
  }
,child,parent);
}
Program: 155609
Project: 155609
Buggy source:
@Test @RunTestInLooperThread public void notification_onCommitRealmResults(){
  final Realm looperThreadRealm=looperThread.realm;
  looperThreadRealm.beginTransaction();
  AllJavaTypes child=looperThreadRealm.createObject(AllJavaTypes.class,10);
  looperThreadRealm.commitTransaction();
  final AtomicInteger counter=new AtomicInteger(0);
  RealmChangeListener<RealmResults<AllJavaTypes>> listener=new RealmChangeListener<RealmResults<AllJavaTypes>>(){
    @Override public void onChange(    RealmResults<AllJavaTypes> object){
      counter.incrementAndGet();
    }
  }
;
  child.getObjectParents().addChangeListener(listener);
  looperThreadRealm.beginTransaction();
  AllJavaTypes parent=looperThreadRealm.createObject(AllJavaTypes.class,1);
  parent.setFieldObject(child);
  looperThreadRealm.commitTransaction();
  verifyPostConditions(looperThreadRealm,new PostConditions(){
    @Override public void run(    Realm realm){
      assertEquals(2,looperThreadRealm.where(AllJavaTypes.class).findAll().size());
      assertEquals(1,counter.get());
    }
  }
,child,parent);
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void notification_onCommitRealmResults(){
  final Realm looperThreadRealm=looperThread.getRealm();
  looperThreadRealm.beginTransaction();
  AllJavaTypes child=looperThreadRealm.createObject(AllJavaTypes.class,10);
  looperThreadRealm.commitTransaction();
  final AtomicInteger counter=new AtomicInteger(0);
  RealmChangeListener<RealmResults<AllJavaTypes>> listener=new RealmChangeListener<RealmResults<AllJavaTypes>>(){
    @Override public void onChange(    RealmResults<AllJavaTypes> object){
      counter.incrementAndGet();
    }
  }
;
  child.getObjectParents().addChangeListener(listener);
  looperThreadRealm.beginTransaction();
  AllJavaTypes parent=looperThreadRealm.createObject(AllJavaTypes.class,1);
  parent.setFieldObject(child);
  looperThreadRealm.commitTransaction();
  verifyPostConditions(looperThreadRealm,new PostConditions(){
    @Override public void run(    Realm realm){
      assertEquals(2,looperThreadRealm.where(AllJavaTypes.class).findAll().size());
      assertEquals(1,counter.get());
    }
  }
,child,parent);
}
Program: 155610
Project: 155610
Buggy source:
@Test @RunTestInLooperThread public void linkingObjects_IllegalStateException_ifDeleted(){
  final Realm realm=looperThread.realm;
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      final BacklinksTarget target=realm.createObject(BacklinksTarget.class);
      target.setId(1);
      final BacklinksSource source=realm.createObject(BacklinksSource.class);
      source.setChild(target);
    }
  }
);
  final BacklinksTarget target=realm.where(BacklinksTarget.class).equalTo(BacklinksTarget.FIELD_ID,1L).findFirst();
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      target.deleteFromRealm();
    }
  }
);
  assertFalse(target.isValid());
  thrown.expect(IllegalStateException.class);
  target.getParents();
  fail();
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void linkingObjects_IllegalStateException_ifDeleted(){
  final Realm realm=looperThread.getRealm();
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      final BacklinksTarget target=realm.createObject(BacklinksTarget.class);
      target.setId(1);
      final BacklinksSource source=realm.createObject(BacklinksSource.class);
      source.setChild(target);
    }
  }
);
  final BacklinksTarget target=realm.where(BacklinksTarget.class).equalTo(BacklinksTarget.FIELD_ID,1L).findFirst();
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      target.deleteFromRealm();
    }
  }
);
  assertFalse(target.isValid());
  thrown.expect(IllegalStateException.class);
  target.getParents();
  fail();
}
Program: 155611
Project: 155611
Buggy source:
@Test @RunTestInLooperThread public void notification_notSentOnUnrelatedChangeRealmResults(){
  final Realm looperThreadRealm=looperThread.realm;
  looperThreadRealm.beginTransaction();
  AllJavaTypes child=looperThreadRealm.createObject(AllJavaTypes.class,10);
  AllJavaTypes parent=looperThreadRealm.createObject(AllJavaTypes.class,1);
  looperThreadRealm.commitTransaction();
  RealmChangeListener<RealmResults<AllJavaTypes>> listener=new RealmChangeListener<RealmResults<AllJavaTypes>>(){
    @Override public void onChange(    RealmResults<AllJavaTypes> object){
      fail("String_Node_Str");
    }
  }
;
  child.getObjectParents().addChangeListener(listener);
  looperThreadRealm.beginTransaction();
  looperThreadRealm.where(AllJavaTypes.class).equalTo("String_Node_Str",1).findAll().deleteAllFromRealm();
  looperThreadRealm.commitTransaction();
  verifyPostConditions(looperThreadRealm,new PostConditions(){
    @Override public void run(    Realm realm){
      assertEquals(1,looperThreadRealm.where(AllJavaTypes.class).findAll().size());
    }
  }
,child,parent);
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void notification_notSentOnUnrelatedChangeRealmResults(){
  final Realm looperThreadRealm=looperThread.getRealm();
  looperThreadRealm.beginTransaction();
  AllJavaTypes child=looperThreadRealm.createObject(AllJavaTypes.class,10);
  AllJavaTypes parent=looperThreadRealm.createObject(AllJavaTypes.class,1);
  looperThreadRealm.commitTransaction();
  RealmChangeListener<RealmResults<AllJavaTypes>> listener=new RealmChangeListener<RealmResults<AllJavaTypes>>(){
    @Override public void onChange(    RealmResults<AllJavaTypes> object){
      fail("String_Node_Str");
    }
  }
;
  child.getObjectParents().addChangeListener(listener);
  looperThreadRealm.beginTransaction();
  looperThreadRealm.where(AllJavaTypes.class).equalTo("String_Node_Str",1).findAll().deleteAllFromRealm();
  looperThreadRealm.commitTransaction();
  verifyPostConditions(looperThreadRealm,new PostConditions(){
    @Override public void run(    Realm realm){
      assertEquals(1,looperThreadRealm.where(AllJavaTypes.class).findAll().size());
    }
  }
,child,parent);
}
Program: 155612
Project: 155612
Buggy source:
@Test @RunTestInLooperThread public void linkingObjects_IllegalStateException_ifNotYetLoaded(){
  final Realm realm=looperThread.realm;
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      final BacklinksTarget target=realm.createObject(BacklinksTarget.class);
      target.setId(1);
      final BacklinksSource source=realm.createObject(BacklinksSource.class);
      source.setChild(target);
    }
  }
);
  final BacklinksTarget targetAsync=realm.where(BacklinksTarget.class).equalTo(BacklinksTarget.FIELD_ID,1L).findFirstAsync();
  assertFalse(targetAsync.isLoaded());
  thrown.expect(IllegalStateException.class);
  targetAsync.getParents();
  fail();
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void linkingObjects_IllegalStateException_ifNotYetLoaded(){
  final Realm realm=looperThread.getRealm();
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      final BacklinksTarget target=realm.createObject(BacklinksTarget.class);
      target.setId(1);
      final BacklinksSource source=realm.createObject(BacklinksSource.class);
      source.setChild(target);
    }
  }
);
  final BacklinksTarget targetAsync=realm.where(BacklinksTarget.class).equalTo(BacklinksTarget.FIELD_ID,1L).findFirstAsync();
  assertFalse(targetAsync.isLoaded());
  thrown.expect(IllegalStateException.class);
  targetAsync.getParents();
  fail();
}
Program: 155613
Project: 155613
Buggy source:
private void verifyPostConditions(final Realm realm,final PostConditions test,final Object... refs){
  realm.beginTransaction();
  realm.commitTransaction();
  looperThread.keepStrongReference.addAll(Arrays.asList(refs));
  looperThread.postRunnable(new Runnable(){
    @Override public void run(){
      test.run(realm);
      looperThread.testComplete();
    }
  }
);
}

Fixed version (ground truth):
private void verifyPostConditions(final Realm realm,final PostConditions test,final Object... refs){
  realm.beginTransaction();
  realm.commitTransaction();
  for (  Object ref : refs) {
    looperThread.keepStrongReference(ref);
  }
  looperThread.postRunnable(new Runnable(){
    @Override public void run(){
      test.run(realm);
      looperThread.testComplete();
    }
  }
);
}
Program: 155614
Project: 155614
Buggy source:
@Test @RunTestInLooperThread public void linkingObjects_IllegalStateException_ifDeletedIndirectly(){
  final Realm realm=looperThread.realm;
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      final BacklinksTarget target1=realm.createObject(BacklinksTarget.class);
      target1.setId(1);
      final BacklinksSource source=realm.createObject(BacklinksSource.class);
      source.setChild(target1);
    }
  }
);
  final BacklinksTarget target=realm.where(BacklinksTarget.class).equalTo(BacklinksTarget.FIELD_ID,1L).findFirst();
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      realm.where(BacklinksTarget.class).findAll().deleteAllFromRealm();
    }
  }
);
  assertFalse(target.isValid());
  thrown.expect(IllegalStateException.class);
  target.getParents();
  fail();
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void linkingObjects_IllegalStateException_ifDeletedIndirectly(){
  final Realm realm=looperThread.getRealm();
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      final BacklinksTarget target1=realm.createObject(BacklinksTarget.class);
      target1.setId(1);
      final BacklinksSource source=realm.createObject(BacklinksSource.class);
      source.setChild(target1);
    }
  }
);
  final BacklinksTarget target=realm.where(BacklinksTarget.class).equalTo(BacklinksTarget.FIELD_ID,1L).findFirst();
  realm.executeTransaction(new Realm.Transaction(){
    @Override public void execute(    Realm realm){
      realm.where(BacklinksTarget.class).findAll().deleteAllFromRealm();
    }
  }
);
  assertFalse(target.isValid());
  thrown.expect(IllegalStateException.class);
  target.getParents();
  fail();
}