nus-yam/ex-repair huggingface dataset:
Program: 155656
Project: 155656
Buggy source:
/** 
 * Returns   {@code false} if the results are not yet loaded, {@code true} if they are loaded.
 * @return {@code true} if the query has completed and the data is available, {@code false} if the query is stillrunning in the background.
 */
public boolean isLoaded(){
  realm.checkIfValid();
  return collection.isLoaded();
}

Fixed version (ground truth):
/** 
 * Returns   {@code false} if the results are not yet loaded, {@code true} if they are loaded.
 * @return {@code true} if the query has completed and the data is available, {@code false} if the query is stillrunning in the background.
 */
@Override public boolean isLoaded(){
  realm.checkIfValid();
  return collection.isLoaded();
}
Program: 155657
Project: 155657
Buggy source:
/** 
 * Makes an asynchronous query blocking. This will also trigger any registered   {@link RealmChangeListener} whenthe query completes.
 * @return {@code true} if it successfully completed the query, {@code false} otherwise.
 */
public boolean load(){
  realm.checkIfValid();
  collection.load();
  return true;
}

Fixed version (ground truth):
/** 
 * Makes an asynchronous query blocking. This will also trigger any registered   {@link RealmChangeListener} whenthe query completes.
 * @return {@code true} if it successfully completed the query, {@code false} otherwise.
 */
@Override public boolean load(){
  realm.checkIfValid();
  collection.load();
  return true;
}
Program: 155658
Project: 155658
Buggy source:
protected native double nativeGetDouble(long nativeRowPtr,long columnIndex);

Fixed version (ground truth):
@Override protected native double nativeGetDouble(long nativeRowPtr,long columnIndex);
Program: 155659
Project: 155659
Buggy source:
protected native int nativeGetColumnType(long nativeTablePtr,long columnIndex);

Fixed version (ground truth):
@Override protected native int nativeGetColumnType(long nativeTablePtr,long columnIndex);
Program: 155660
Project: 155660
Buggy source:
protected native long nativeGetTimestamp(long nativeRowPtr,long columnIndex);

Fixed version (ground truth):
@Override protected native long nativeGetTimestamp(long nativeRowPtr,long columnIndex);
Program: 155661
Project: 155661
Buggy source:
protected native long nativeGetLinkView(long nativePtr,long columnIndex);

Fixed version (ground truth):
@Override protected native long nativeGetLinkView(long nativePtr,long columnIndex);
Program: 155662
Project: 155662
Buggy source:
protected native void nativeSetBoolean(long nativeRowPtr,long columnIndex,boolean value);

Fixed version (ground truth):
@Override protected native void nativeSetBoolean(long nativeRowPtr,long columnIndex,boolean value);
Program: 155663
Project: 155663
Buggy source:
protected native boolean nativeGetBoolean(long nativeRowPtr,long columnIndex);

Fixed version (ground truth):
@Override protected native boolean nativeGetBoolean(long nativeRowPtr,long columnIndex);
Program: 155664
Project: 155664
Buggy source:
protected native void nativeNullifyLink(long nativeRowPtr,long columnIndex);

Fixed version (ground truth):
@Override protected native void nativeNullifyLink(long nativeRowPtr,long columnIndex);
Program: 155665
Project: 155665
Buggy source:
protected native long nativeGetColumnIndex(long nativeTablePtr,String columnName);

Fixed version (ground truth):
@Override protected native long nativeGetColumnIndex(long nativeTablePtr,String columnName);
Program: 155666
Project: 155666
Buggy source:
protected native void nativeSetByteArray(long nativePtr,long columnIndex,byte[] data);

Fixed version (ground truth):
@Override protected native void nativeSetByteArray(long nativePtr,long columnIndex,byte[] data);
Program: 155667
Project: 155667
Buggy source:
protected native void nativeSetDouble(long nativeRowPtr,long columnIndex,double value);

Fixed version (ground truth):
@Override protected native void nativeSetDouble(long nativeRowPtr,long columnIndex,double value);
Program: 155668
Project: 155668
Buggy source:
protected native long nativeGetLink(long nativeRowPtr,long columnIndex);

Fixed version (ground truth):
@Override protected native long nativeGetLink(long nativeRowPtr,long columnIndex);
Program: 155669
Project: 155669
Buggy source:
protected native void nativeSetLink(long nativeRowPtr,long columnIndex,long value);

Fixed version (ground truth):
@Override protected native void nativeSetLink(long nativeRowPtr,long columnIndex,long value);
Program: 155670
Project: 155670
Buggy source:
protected native long nativeGetLong(long nativeRowPtr,long columnIndex);

Fixed version (ground truth):
@Override protected native long nativeGetLong(long nativeRowPtr,long columnIndex);
Program: 155671
Project: 155671
Buggy source:
protected native void nativeSetLong(long nativeRowPtr,long columnIndex,long value);

Fixed version (ground truth):
@Override protected native void nativeSetLong(long nativeRowPtr,long columnIndex,long value);
Program: 155672
Project: 155672
Buggy source:
protected native long nativeGetColumnCount(long nativeTablePtr);

Fixed version (ground truth):
@Override protected native long nativeGetColumnCount(long nativeTablePtr);
Program: 155673
Project: 155673
Buggy source:
protected native String nativeGetColumnName(long nativeTablePtr,long columnIndex);

Fixed version (ground truth):
@Override protected native String nativeGetColumnName(long nativeTablePtr,long columnIndex);
Program: 155674
Project: 155674
Buggy source:
protected native boolean nativeIsNullLink(long nativeRowPtr,long columnIndex);

Fixed version (ground truth):
@Override protected native boolean nativeIsNullLink(long nativeRowPtr,long columnIndex);
Program: 155675
Project: 155675
Buggy source:
protected native byte[] nativeGetByteArray(long nativePtr,long columnIndex);

Fixed version (ground truth):
@Override protected native byte[] nativeGetByteArray(long nativePtr,long columnIndex);
Program: 155676
Project: 155676
Buggy source:
protected native void nativeSetTimestamp(long nativeRowPtr,long columnIndex,long dateTimeValue);

Fixed version (ground truth):
@Override protected native void nativeSetTimestamp(long nativeRowPtr,long columnIndex,long dateTimeValue);
Program: 155677
Project: 155677
Buggy source:
protected native void nativeSetString(long nativeRowPtr,long columnIndex,String value);

Fixed version (ground truth):
@Override protected native void nativeSetString(long nativeRowPtr,long columnIndex,String value);
Program: 155678
Project: 155678
Buggy source:
protected native float nativeGetFloat(long nativeRowPtr,long columnIndex);

Fixed version (ground truth):
@Override protected native float nativeGetFloat(long nativeRowPtr,long columnIndex);
Program: 155679
Project: 155679
Buggy source:
protected native String nativeGetString(long nativePtr,long columnIndex);

Fixed version (ground truth):
@Override protected native String nativeGetString(long nativePtr,long columnIndex);
Program: 155680
Project: 155680
Buggy source:
protected native void nativeSetFloat(long nativeRowPtr,long columnIndex,float value);

Fixed version (ground truth):
@Override protected native void nativeSetFloat(long nativeRowPtr,long columnIndex,float value);
Program: 155681
Project: 155681
Buggy source:
/** 
 * Not supported by Realm collection iterators.
 * @throws UnsupportedOperationException
 */
@Deprecated public void remove(){
  throw new UnsupportedOperationException("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Not supported by Realm collection iterators.
 * @throws UnsupportedOperationException
 */
@Override @Deprecated public void remove(){
  throw new UnsupportedOperationException("String_Node_Str");
}
Program: 155682
Project: 155682
Buggy source:
public String toString(){
  long columnCount=getColumnCount();
  String name=getName();
  StringBuilder stringBuilder=new StringBuilder("String_Node_Str");
  if (name != null && !name.isEmpty()) {
    stringBuilder.append(getName());
    stringBuilder.append("String_Node_Str");
  }
  if (hasPrimaryKey()) {
    String pkFieldName=getColumnName(getPrimaryKey());
    stringBuilder.append("String_Node_Str").append(pkFieldName).append("String_Node_Str");
  }
  stringBuilder.append("String_Node_Str");
  stringBuilder.append(columnCount);
  stringBuilder.append("String_Node_Str");
  for (int i=0; i < columnCount; i++) {
    if (i != 0) {
      stringBuilder.append("String_Node_Str");
    }
    stringBuilder.append(getColumnName(i));
  }
  stringBuilder.append("String_Node_Str");
  stringBuilder.append("String_Node_Str");
  stringBuilder.append(size());
  stringBuilder.append("String_Node_Str");
  return stringBuilder.toString();
}

Fixed version (ground truth):
@Override public String toString(){
  long columnCount=getColumnCount();
  String name=getName();
  StringBuilder stringBuilder=new StringBuilder("String_Node_Str");
  if (name != null && !name.isEmpty()) {
    stringBuilder.append(getName());
    stringBuilder.append("String_Node_Str");
  }
  if (hasPrimaryKey()) {
    String pkFieldName=getColumnName(getPrimaryKey());
    stringBuilder.append("String_Node_Str").append(pkFieldName).append("String_Node_Str");
  }
  stringBuilder.append("String_Node_Str");
  stringBuilder.append(columnCount);
  stringBuilder.append("String_Node_Str");
  for (int i=0; i < columnCount; i++) {
    if (i != 0) {
      stringBuilder.append("String_Node_Str");
    }
    stringBuilder.append(getColumnName(i));
  }
  stringBuilder.append("String_Node_Str");
  stringBuilder.append("String_Node_Str");
  stringBuilder.append(size());
  stringBuilder.append("String_Node_Str");
  return stringBuilder.toString();
}
Program: 155683
Project: 155683
Buggy source:
/** 
 * {@inheritDoc}
 */
public void cancel(){
  pendingTask.cancel(true);
  isCancelled=true;
  service.getQueue().remove(pendingTask);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public void cancel(){
  pendingTask.cancel(true);
  isCancelled=true;
  service.getQueue().remove(pendingTask);
}
Program: 155684
Project: 155684
Buggy source:
/** 
 * {@inheritDoc}
 */
public boolean isCancelled(){
  return isCancelled;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public boolean isCancelled(){
  return isCancelled;
}
Program: 155686
Project: 155686
Buggy source:
@Test public void mutableMethodsOutsideTransactions(){
  for (  CollectionMutatorMethod method : CollectionMutatorMethod.values()) {
    Class<? extends Throwable> expected=IllegalStateException.class;
    if (collectionClass == ManagedCollection.REALMRESULTS || isSnapshot(collectionClass)) {
switch (method) {
case ADD_OBJECT:
case ADD_ALL_OBJECTS:
case CLEAR:
case REMOVE_OBJECT:
case REMOVE_ALL:
case RETAIN_ALL:
        expected=UnsupportedOperationException.class;
    }
  }
  try {
switch (method) {
case DELETE_ALL:
      collection.deleteAllFromRealm();
    break;
case ADD_OBJECT:
  collection.add(new AllJavaTypes());
case ADD_ALL_OBJECTS:
collection.addAll(Collections.singletonList(new AllJavaTypes()));
break;
case CLEAR:
collection.clear();
break;
case REMOVE_OBJECT:
collection.remove(new AllJavaTypes());
break;
case REMOVE_ALL:
collection.removeAll(Collections.singletonList(new AllJavaTypes()));
break;
case RETAIN_ALL:
collection.retainAll(Collections.singletonList(new AllJavaTypes()));
break;
}
fail("String_Node_Str" + method);
}
 catch (Throwable t) {
if (!t.getClass().equals(expected)) {
fail(method + "String_Node_Str" + t+ "String_Node_Str"+ expected);
}
}
}
}

Fixed version (ground truth):
@Test public void mutableMethodsOutsideTransactions(){
  for (  CollectionMutatorMethod method : CollectionMutatorMethod.values()) {
    Class<? extends Throwable> expected=IllegalStateException.class;
    if (collectionClass == ManagedCollection.REALMRESULTS || isSnapshot(collectionClass)) {
switch (method) {
case ADD_OBJECT:
case ADD_ALL_OBJECTS:
case CLEAR:
case REMOVE_OBJECT:
case REMOVE_ALL:
case RETAIN_ALL:
        expected=UnsupportedOperationException.class;
      break;
default :
  }
}
try {
switch (method) {
case DELETE_ALL:
    collection.deleteAllFromRealm();
  break;
case ADD_OBJECT:
collection.add(new AllJavaTypes());
break;
case ADD_ALL_OBJECTS:
collection.addAll(Collections.singletonList(new AllJavaTypes()));
break;
case CLEAR:
collection.clear();
break;
case REMOVE_OBJECT:
collection.remove(new AllJavaTypes());
break;
case REMOVE_ALL:
collection.removeAll(Collections.singletonList(new AllJavaTypes()));
break;
case RETAIN_ALL:
collection.retainAll(Collections.singletonList(new AllJavaTypes()));
break;
}
fail("String_Node_Str" + method);
}
 catch (Throwable t) {
if (!t.getClass().equals(expected)) {
fail(method + "String_Node_Str" + t+ "String_Node_Str"+ expected);
}
}
}
}
Program: 155687
Project: 155687
Buggy source:
@Override public Boolean call() throws Exception {
  Class<? extends Throwable> expected=IllegalStateException.class;
  if (collectionClass == ManagedCollection.REALMRESULTS || isSnapshot(collectionClass)) {
switch (method) {
case ADD_OBJECT:
case ADD_ALL_OBJECTS:
case CLEAR:
case REMOVE_OBJECT:
case REMOVE_ALL:
case RETAIN_ALL:
      expected=UnsupportedOperationException.class;
  }
}
try {
switch (method) {
case ADD_OBJECT:
    collection.add(new AllJavaTypes());
  break;
case ADD_ALL_OBJECTS:
collection.addAll(Collections.singletonList(new AllJavaTypes()));
break;
case CLEAR:
collection.clear();
case CONTAINS:
case CONTAINS_ALL:
collection.containsAll(Collections.singletonList(tempObject));
break;
case EQUALS:
collection.equals(createCollection(collectionClass));
break;
case HASHCODE:
collection.hashCode();
break;
case IS_EMPTY:
collection.isEmpty();
break;
case ITERATOR:
return true;
case REMOVE_OBJECT:
collection.remove(new AllJavaTypes());
break;
case REMOVE_ALL:
collection.removeAll(Collections.singletonList(new AllJavaTypes()));
break;
case RETAIN_ALL:
collection.retainAll(Collections.singletonList(new AllJavaTypes()));
break;
case SIZE:
collection.size();
break;
case TO_ARRAY:
collection.toArray();
break;
case TO_ARRAY_INPUT:
collection.toArray(new Object[collection.size()]);
break;
}
return false;
}
 catch (Throwable t) {
if (!t.getClass().equals(expected)) {
return false;
}
}
return true;
}

Fixed version (ground truth):
@Override public Boolean call() throws Exception {
  Class<? extends Throwable> expected=IllegalStateException.class;
  if (collectionClass == ManagedCollection.REALMRESULTS || isSnapshot(collectionClass)) {
switch (method) {
case ADD_OBJECT:
case ADD_ALL_OBJECTS:
case CLEAR:
case REMOVE_OBJECT:
case REMOVE_ALL:
case RETAIN_ALL:
      expected=UnsupportedOperationException.class;
    break;
default :
}
}
try {
switch (method) {
case ADD_OBJECT:
  collection.add(new AllJavaTypes());
break;
case ADD_ALL_OBJECTS:
collection.addAll(Collections.singletonList(new AllJavaTypes()));
break;
case CLEAR:
collection.clear();
break;
case CONTAINS:
collection.contains(tempObject);
break;
case CONTAINS_ALL:
collection.containsAll(Collections.singletonList(tempObject));
break;
case EQUALS:
collection.equals(createCollection(collectionClass));
break;
case HASHCODE:
collection.hashCode();
break;
case IS_EMPTY:
collection.isEmpty();
break;
case ITERATOR:
return true;
case REMOVE_OBJECT:
collection.remove(new AllJavaTypes());
break;
case REMOVE_ALL:
collection.removeAll(Collections.singletonList(new AllJavaTypes()));
break;
case RETAIN_ALL:
collection.retainAll(Collections.singletonList(new AllJavaTypes()));
break;
case SIZE:
collection.size();
break;
case TO_ARRAY:
collection.toArray();
break;
case TO_ARRAY_INPUT:
collection.toArray(new Object[collection.size()]);
break;
}
return false;
}
 catch (Throwable t) {
if (!t.getClass().equals(expected)) {
return false;
}
}
return true;
}
Program: 155688
Project: 155688
Buggy source:
@Test public void looperThreadQuitsLooperEarly() throws InterruptedException {
  final CountDownLatch backgroundLooperStartedAndStopped=new CountDownLatch(1);
  final CountDownLatch mainThreadCommitCompleted=new CountDownLatch(1);
  final CountDownLatch backgroundThreadStopped=new CountDownLatch(1);
  ExecutorService executorService=Executors.newSingleThreadExecutor();
  executorService.submit(new Runnable(){
    @Override public void run(){
      Looper.prepare();
      Realm realm=Realm.getInstance(realmConfig);
      realm.setAutoRefresh(false);
      TestHelper.quitLooperOrFail();
      backgroundLooperStartedAndStopped.countDown();
      try {
        mainThreadCommitCompleted.await();
      }
 catch (      InterruptedException e) {
        fail("String_Node_Str");
      }
      realm.close();
      backgroundThreadStopped.countDown();
    }
  }
);
  TestHelper.awaitOrFail(backgroundLooperStartedAndStopped);
  Realm realm=Realm.getInstance(realmConfig);
  RealmLogger logger=TestHelper.getFailureLogger(Log.WARN);
  RealmLog.add(logger);
  realm.beginTransaction();
  realm.commitTransaction();
  mainThreadCommitCompleted.countDown();
  TestHelper.awaitOrFail(backgroundThreadStopped);
  realm.close();
  RealmLog.remove(logger);
}

Fixed version (ground truth):
@Test public void looperThreadQuitsLooperEarly() throws InterruptedException {
  final CountDownLatch backgroundLooperStartedAndStopped=new CountDownLatch(1);
  final CountDownLatch mainThreadCommitCompleted=new CountDownLatch(1);
  final CountDownLatch backgroundThreadStopped=new CountDownLatch(1);
  ExecutorService executorService=Executors.newSingleThreadExecutor();
  final Future<?> future=executorService.submit(new Runnable(){
    @Override public void run(){
      Looper.prepare();
      Realm realm=Realm.getInstance(realmConfig);
      realm.setAutoRefresh(false);
      TestHelper.quitLooperOrFail();
      backgroundLooperStartedAndStopped.countDown();
      try {
        mainThreadCommitCompleted.await();
      }
 catch (      InterruptedException e) {
        fail("String_Node_Str");
      }
      realm.close();
      backgroundThreadStopped.countDown();
    }
  }
);
  TestHelper.awaitOrFail(backgroundLooperStartedAndStopped);
  Realm realm=Realm.getInstance(realmConfig);
  RealmLogger logger=TestHelper.getFailureLogger(Log.WARN);
  RealmLog.add(logger);
  realm.beginTransaction();
  realm.commitTransaction();
  mainThreadCommitCompleted.countDown();
  TestHelper.awaitOrFail(backgroundThreadStopped);
  realm.close();
  RealmLog.remove(logger);
}
Program: 155689
Project: 155689
Buggy source:
@Test public void listIterator_deleteManagedObjectIndirectly(){
  realm.beginTransaction();
  ListIterator<AllJavaTypes> it=collection.listIterator();
  it.next();
  it.next().deleteFromRealm();
  realm.commitTransaction();
switch (collectionClass) {
case MANAGED_REALMLIST:
case REALMRESULTS:
    assertEquals(TEST_SIZE - 1,collection.size());
  break;
case UNMANAGED_REALMLIST:
assertEquals(TEST_SIZE,collection.size());
break;
}
it.previous();
AllJavaTypes types=it.next();
assertTrue(collectionClass == CollectionClass.MANAGED_REALMLIST ? types.isValid() : !types.isValid());
}

Fixed version (ground truth):
@Test public void listIterator_deleteManagedObjectIndirectly(){
  if (skipTest(CollectionClass.REALMRESULTS_SNAPSHOT_LIST_BASE,CollectionClass.REALMRESULTS_SNAPSHOT_RESULTS_BASE)) {
    return;
  }
  realm.beginTransaction();
  ListIterator<AllJavaTypes> it=collection.listIterator();
  it.next();
  it.next().deleteFromRealm();
  realm.commitTransaction();
switch (collectionClass) {
case MANAGED_REALMLIST:
case REALMRESULTS:
    assertEquals(TEST_SIZE - 1,collection.size());
  break;
case UNMANAGED_REALMLIST:
assertEquals(TEST_SIZE,collection.size());
break;
default :
fail();
return;
}
it.previous();
AllJavaTypes types=it.next();
assertTrue(collectionClass == CollectionClass.MANAGED_REALMLIST ? types.isValid() : !types.isValid());
}
Program: 155690
Project: 155690
Buggy source:
@Test public void methods_indexOutOfBounds(){
  collection=createEmptyCollection(realm,collectionClass);
  for (  ListMethod method : ListMethod.values()) {
    realm.beginTransaction();
    try {
switch (method) {
case ADD_INDEX:
        collection.add(1,new AllJavaTypes());
      break;
case ADD_ALL_INDEX:
    collection.addAll(1,Collections.singleton(new AllJavaTypes()));
  break;
case GET_INDEX:
collection.get(1);
break;
case LIST_ITERATOR_INDEX:
collection.listIterator(1);
break;
case REMOVE_INDEX:
collection.remove(1);
case SET:
collection.set(1,new AllJavaTypes());
case SUBLIST:
collection.subList(1,2);
case FIRST:
case LAST:
case INDEX_OF:
case LAST_INDEX_OF:
case LIST_ITERATOR:
continue;
}
fail(method + "String_Node_Str");
}
 catch (IndexOutOfBoundsException ignored) {
}
catch (UnsupportedOperationException ignored) {
}
 finally {
realm.cancelTransaction();
}
}
for (OrderedRealmCollectionMethod method : OrderedRealmCollectionMethod.values()) {
realm.beginTransaction();
try {
switch (method) {
case DELETE_INDEX:
collection.deleteFromRealm(1);
break;
case DELETE_FIRST:
case DELETE_LAST:
case SORT:
case SORT_FIELD:
case SORT_2FIELDS:
case SORT_MULTI:
case CREATE_SNAPSHOT:
continue;
}
fail(method + "String_Node_Str");
}
 catch (IndexOutOfBoundsException ignored) {
}
catch (UnsupportedOperationException ignored) {
}
 finally {
realm.cancelTransaction();
}
}
}

Fixed version (ground truth):
@Test public void methods_indexOutOfBounds(){
  collection=createEmptyCollection(realm,collectionClass);
  for (  ListMethod method : ListMethod.values()) {
    realm.beginTransaction();
    try {
switch (method) {
case ADD_INDEX:
        collection.add(1,new AllJavaTypes());
      break;
case ADD_ALL_INDEX:
    collection.addAll(1,Collections.singleton(new AllJavaTypes()));
  break;
case GET_INDEX:
collection.get(1);
break;
case LIST_ITERATOR_INDEX:
collection.listIterator(1);
break;
case REMOVE_INDEX:
collection.remove(1);
break;
case SET:
collection.set(1,new AllJavaTypes());
break;
case SUBLIST:
collection.subList(1,2);
break;
case FIRST:
case LAST:
case INDEX_OF:
case LAST_INDEX_OF:
case LIST_ITERATOR:
continue;
}
fail(method + "String_Node_Str");
}
 catch (IndexOutOfBoundsException ignored) {
}
catch (UnsupportedOperationException ignored) {
}
 finally {
realm.cancelTransaction();
}
}
for (OrderedRealmCollectionMethod method : OrderedRealmCollectionMethod.values()) {
realm.beginTransaction();
try {
switch (method) {
case DELETE_INDEX:
collection.deleteFromRealm(1);
break;
case DELETE_FIRST:
case DELETE_LAST:
case SORT:
case SORT_FIELD:
case SORT_2FIELDS:
case SORT_MULTI:
case CREATE_SNAPSHOT:
continue;
}
fail(method + "String_Node_Str");
}
 catch (IndexOutOfBoundsException ignored) {
}
catch (UnsupportedOperationException ignored) {
}
 finally {
realm.cancelTransaction();
}
}
}
Program: 155691
Project: 155691
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);
  }
 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(expected.getKind(),RealmFileException.Kind.ACCESS_ERROR);
    assertTrue(Realm.deleteRealm(configA));
    realm=Realm.getInstance(configB);
    realm.close();
  }
}
Program: 155692
Project: 155692
Buggy source:
@Test public void createObjectFromJson_allSimpleObjectAllTypes() throws JSONException {
  JSONObject json=new JSONObject();
  json.put("String_Node_Str","String_Node_Str");
  json.put("String_Node_Str",1L);
  json.put("String_Node_Str",1.23F);
  json.put("String_Node_Str",1.23D);
  json.put("String_Node_Str",true);
  json.put("String_Node_Str",new String(Base64.encode(new byte[]{1,2,3},Base64.DEFAULT)));
  realm.beginTransaction();
  realm.createObjectFromJson(AllTypes.class,json);
  realm.commitTransaction();
  AllTypes obj=realm.where(AllTypes.class).findFirst();
  assertEquals("String_Node_Str",obj.getColumnString());
  assertEquals(1L,obj.getColumnLong());
  assertEquals(1.23F,obj.getColumnFloat(),0F);
  assertEquals(1.23D,obj.getColumnDouble(),0D);
  assertEquals(true,obj.isColumnBoolean());
  assertArrayEquals(new byte[]{1,2,3},obj.getColumnBinary());
}

Fixed version (ground truth):
@Test public void createObjectFromJson_allSimpleObjectAllTypes() throws JSONException {
  JSONObject json=new JSONObject();
  json.put("String_Node_Str","String_Node_Str");
  json.put("String_Node_Str",1L);
  json.put("String_Node_Str",1.23F);
  json.put("String_Node_Str",1.23D);
  json.put("String_Node_Str",true);
  json.put("String_Node_Str",new String(Base64.encode(new byte[]{1,2,3},Base64.DEFAULT),UTF_8));
  realm.beginTransaction();
  realm.createObjectFromJson(AllTypes.class,json);
  realm.commitTransaction();
  AllTypes obj=realm.where(AllTypes.class).findFirst();
  assertEquals("String_Node_Str",obj.getColumnString());
  assertEquals(1L,obj.getColumnLong());
  assertEquals(1.23F,obj.getColumnFloat(),0F);
  assertEquals(1.23D,obj.getColumnDouble(),0D);
  assertEquals(true,obj.isColumnBoolean());
  assertArrayEquals(new byte[]{1,2,3},obj.getColumnBinary());
}
Program: 155693
Project: 155693
Buggy source:
private InputStream convertJsonObjectToStream(JSONObject obj){
  return new ByteArrayInputStream(obj.toString().getBytes());
}

Fixed version (ground truth):
private InputStream convertJsonObjectToStream(JSONObject obj){
  return new ByteArrayInputStream(obj.toString().getBytes(UTF_8));
}
Program: 155695
Project: 155695
Buggy source:
@Test public void and_implicit(){
  populateTestRealm(realm,200);
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).equalTo(AllTypes.FIELD_FLOAT,31.234567f);
  RealmResults<AllTypes> resultList=query.between(AllTypes.FIELD_LONG,1,10).findAll();
  assertEquals(0,resultList.size());
  query=realm.where(AllTypes.class).equalTo(AllTypes.FIELD_FLOAT,81.234567f);
  resultList=query.between(AllTypes.FIELD_LONG,1,100).findAll();
  assertEquals(1,resultList.size());
}

Fixed version (ground truth):
@Test public void and_implicit(){
  populateTestRealm(realm,200);
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).equalTo(AllTypes.FIELD_FLOAT,31.2345f);
  RealmResults<AllTypes> resultList=query.between(AllTypes.FIELD_LONG,1,10).findAll();
  assertEquals(0,resultList.size());
  query=realm.where(AllTypes.class).equalTo(AllTypes.FIELD_FLOAT,81.2345f);
  resultList=query.between(AllTypes.FIELD_LONG,1,100).findAll();
  assertEquals(1,resultList.size());
}
Program: 155696
Project: 155696
Buggy source:
@Test public void lessThanOrEqualTo(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_FLOAT,31.234567f).findAll();
  assertEquals(31,resultList.size());
  resultList=realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_FLOAT,31.234567f).between(AllTypes.FIELD_LONG,11,20).findAll();
  assertEquals(10,resultList.size());
}

Fixed version (ground truth):
@Test public void lessThanOrEqualTo(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_FLOAT,31.2345f).findAll();
  assertEquals(31,resultList.size());
  resultList=realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_FLOAT,31.2345f).between(AllTypes.FIELD_LONG,11,20).findAll();
  assertEquals(10,resultList.size());
}
Program: 155697
Project: 155697
Buggy source:
@Test(expected=UnsupportedOperationException.class) public void or_missingFilterAfter(){
  realm.where(AllTypes.class).or().equalTo(AllTypes.FIELD_FLOAT,31.234567f).findAll();
}

Fixed version (ground truth):
@Test(expected=UnsupportedOperationException.class) public void or_missingFilterAfter(){
  realm.where(AllTypes.class).or().equalTo(AllTypes.FIELD_FLOAT,31.2345f).findAll();
}
Program: 155698
Project: 155698
Buggy source:
@Test(expected=UnsupportedOperationException.class) public void or_missingFilterBefore(){
  realm.where(AllTypes.class).or().equalTo(AllTypes.FIELD_FLOAT,31.234567f).findAll();
}

Fixed version (ground truth):
@Test(expected=UnsupportedOperationException.class) public void or_missingFilterBefore(){
  realm.where(AllTypes.class).or().equalTo(AllTypes.FIELD_FLOAT,31.2345f).findAll();
}
Program: 155699
Project: 155699
Buggy source:
@Test public void lessThan(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).lessThan(AllTypes.FIELD_FLOAT,31.234567f).findAll();
  assertEquals(30,resultList.size());
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).lessThan(AllTypes.FIELD_FLOAT,31.234567f);
  resultList=query.between(AllTypes.FIELD_LONG,1,10).findAll();
  assertEquals(10,resultList.size());
}

Fixed version (ground truth):
@Test public void lessThan(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).lessThan(AllTypes.FIELD_FLOAT,31.2345f).findAll();
  assertEquals(30,resultList.size());
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).lessThan(AllTypes.FIELD_FLOAT,31.2345f);
  resultList=query.between(AllTypes.FIELD_LONG,1,10).findAll();
  assertEquals(10,resultList.size());
}
Program: 155700
Project: 155700
Buggy source:
@Test public void greaterThanOrEqualTo(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_FLOAT,10.234567f).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 9,resultList.size());
  resultList=realm.where(AllTypes.class).beginsWith(AllTypes.FIELD_STRING,"String_Node_Str").greaterThanOrEqualTo(AllTypes.FIELD_FLOAT,50.234567f).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 100,resultList.size());
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_FLOAT,11.234567f);
  query=query.between(AllTypes.FIELD_LONG,1,20);
  resultList=query.beginsWith(AllTypes.FIELD_STRING,"String_Node_Str").findAll();
  assertEquals(1,resultList.size());
}

Fixed version (ground truth):
@Test public void greaterThanOrEqualTo(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_FLOAT,10.2345f).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 9,resultList.size());
  resultList=realm.where(AllTypes.class).beginsWith(AllTypes.FIELD_STRING,"String_Node_Str").greaterThanOrEqualTo(AllTypes.FIELD_FLOAT,50.2345f).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 100,resultList.size());
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).greaterThanOrEqualTo(AllTypes.FIELD_FLOAT,11.2345f);
  query=query.between(AllTypes.FIELD_LONG,1,20);
  resultList=query.beginsWith(AllTypes.FIELD_STRING,"String_Node_Str").findAll();
  assertEquals(1,resultList.size());
}
Program: 155701
Project: 155701
Buggy source:
@Test public void equalTo(){
  populateTestRealm(realm,200);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).equalTo(AllTypes.FIELD_FLOAT,31.234567f).findAll();
  assertEquals(1,resultList.size());
  resultList=realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_FLOAT,11.0f).equalTo(AllTypes.FIELD_LONG,10).findAll();
  assertEquals(1,resultList.size());
  resultList=realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_FLOAT,11.0f).equalTo(AllTypes.FIELD_LONG,1).findAll();
  assertEquals(0,resultList.size());
}

Fixed version (ground truth):
@Test public void equalTo(){
  populateTestRealm(realm,200);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).equalTo(AllTypes.FIELD_FLOAT,31.2345f).findAll();
  assertEquals(1,resultList.size());
  resultList=realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_FLOAT,11.0f).equalTo(AllTypes.FIELD_LONG,10).findAll();
  assertEquals(1,resultList.size());
  resultList=realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_FLOAT,11.0f).equalTo(AllTypes.FIELD_LONG,1).findAll();
  assertEquals(0,resultList.size());
}
Program: 155702
Project: 155702
Buggy source:
@Test public void greaterThan(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_FLOAT,10.234567f).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 10,resultList.size());
  resultList=realm.where(AllTypes.class).beginsWith(AllTypes.FIELD_STRING,"String_Node_Str").greaterThan(AllTypes.FIELD_FLOAT,50.234567f).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 100,resultList.size());
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_FLOAT,11.234567f);
  resultList=query.between(AllTypes.FIELD_LONG,1,20).findAll();
  assertEquals(10,resultList.size());
}

Fixed version (ground truth):
@Test public void greaterThan(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_FLOAT,10.2345f).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 10,resultList.size());
  resultList=realm.where(AllTypes.class).beginsWith(AllTypes.FIELD_STRING,"String_Node_Str").greaterThan(AllTypes.FIELD_FLOAT,150.2345f).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 150,resultList.size());
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).greaterThan(AllTypes.FIELD_FLOAT,11.2345f);
  resultList=query.between(AllTypes.FIELD_LONG,1,20).findAll();
  assertEquals(10,resultList.size());
}
Program: 155703
Project: 155703
Buggy source:
private void doTestForInFloat(String targetField){
  populateNoPrimaryKeyNullTypesRows();
  try {
    realm.where(NoPrimaryKeyNullTypes.class).in(targetField,(Float[])null).findAll();
    fail();
  }
 catch (  IllegalArgumentException ignored) {
  }
  try {
    realm.where(NoPrimaryKeyNullTypes.class).in(targetField,new Float[]{}).findAll();
    fail();
  }
 catch (  IllegalArgumentException ignored) {
  }
  RealmResults<NoPrimaryKeyNullTypes> resultList=realm.where(NoPrimaryKeyNullTypes.class).in(targetField,new Float[]{1.234567f + 1}).findAll();
  assertEquals(1,resultList.size());
  resultList=realm.where(NoPrimaryKeyNullTypes.class).in(targetField,new Float[]{1.234567f + 2}).findAll();
  assertEquals(1,resultList.size());
  resultList=realm.where(NoPrimaryKeyNullTypes.class).in(targetField,new Float[]{1.234567f + 1,1.234567f + 2}).findAll();
  assertEquals(2,resultList.size());
  resultList=realm.where(NoPrimaryKeyNullTypes.class).not().in(targetField,new Float[]{1.234567f + 1,1.234567f + 2}).findAll();
  assertEquals(198,resultList.size());
}

Fixed version (ground truth):
private void doTestForInFloat(String targetField){
  populateNoPrimaryKeyNullTypesRows();
  try {
    realm.where(NoPrimaryKeyNullTypes.class).in(targetField,(Float[])null).findAll();
    fail();
  }
 catch (  IllegalArgumentException ignored) {
  }
  try {
    realm.where(NoPrimaryKeyNullTypes.class).in(targetField,new Float[]{}).findAll();
    fail();
  }
 catch (  IllegalArgumentException ignored) {
  }
  RealmResults<NoPrimaryKeyNullTypes> resultList=realm.where(NoPrimaryKeyNullTypes.class).in(targetField,new Float[]{1.2345f + 1}).findAll();
  assertEquals(1,resultList.size());
  resultList=realm.where(NoPrimaryKeyNullTypes.class).in(targetField,new Float[]{1.2345f + 2}).findAll();
  assertEquals(1,resultList.size());
  resultList=realm.where(NoPrimaryKeyNullTypes.class).in(targetField,new Float[]{1.2345f + 1,1.2345f + 2}).findAll();
  assertEquals(2,resultList.size());
  resultList=realm.where(NoPrimaryKeyNullTypes.class).not().in(targetField,new Float[]{1.2345f + 1,1.2345f + 2}).findAll();
  assertEquals(198,resultList.size());
}
Program: 155704
Project: 155704
Buggy source:
@Test public void notEqualTo(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).notEqualTo(AllTypes.FIELD_LONG,31).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 1,resultList.size());
  resultList=realm.where(AllTypes.class).notEqualTo(AllTypes.FIELD_FLOAT,11.234567f).equalTo(AllTypes.FIELD_LONG,10).findAll();
  assertEquals(0,resultList.size());
  resultList=realm.where(AllTypes.class).notEqualTo(AllTypes.FIELD_FLOAT,11.234567f).equalTo(AllTypes.FIELD_LONG,1).findAll();
  assertEquals(1,resultList.size());
}

Fixed version (ground truth):
@Test public void notEqualTo(){
  final int TEST_OBJECTS_COUNT=200;
  populateTestRealm(realm,TEST_OBJECTS_COUNT);
  RealmResults<AllTypes> resultList=realm.where(AllTypes.class).notEqualTo(AllTypes.FIELD_LONG,31).findAll();
  assertEquals(TEST_OBJECTS_COUNT - 1,resultList.size());
  resultList=realm.where(AllTypes.class).notEqualTo(AllTypes.FIELD_FLOAT,11.2345f).equalTo(AllTypes.FIELD_LONG,10).findAll();
  assertEquals(0,resultList.size());
  resultList=realm.where(AllTypes.class).notEqualTo(AllTypes.FIELD_FLOAT,11.2345f).equalTo(AllTypes.FIELD_LONG,1).findAll();
  assertEquals(1,resultList.size());
}
Program: 155705
Project: 155705
Buggy source:
@Test public void in_floatNotNull(){
  doTestForInFloat(NoPrimaryKeyNullTypes.FIELD_FLOAT_NOT_NULL);
  try {
    realm.where(NoPrimaryKeyNullTypes.class).not().in(NoPrimaryKeyNullTypes.FIELD_FLOAT_NOT_NULL,new Float[]{1.234567f + 1,null,1.234567f + 2}).findAll();
    fail();
  }
 catch (  IllegalArgumentException ignored) {
  }
}

Fixed version (ground truth):
@Test public void in_floatNotNull(){
  doTestForInFloat(NoPrimaryKeyNullTypes.FIELD_FLOAT_NOT_NULL);
  try {
    realm.where(NoPrimaryKeyNullTypes.class).not().in(NoPrimaryKeyNullTypes.FIELD_FLOAT_NOT_NULL,new Float[]{1.2345f + 1,null,1.2345f + 2}).findAll();
    fail();
  }
 catch (  IllegalArgumentException ignored) {
  }
}
Program: 155706
Project: 155706
Buggy source:
@Test public void or(){
  populateTestRealm(realm,200);
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).equalTo(AllTypes.FIELD_FLOAT,31.234567f);
  RealmResults<AllTypes> resultList=query.or().between(AllTypes.FIELD_LONG,1,20).findAll();
  assertEquals(21,resultList.size());
  resultList=query.or().equalTo(AllTypes.FIELD_STRING,"String_Node_Str").findAll();
  assertEquals(21,resultList.size());
  resultList=query.or().equalTo(AllTypes.FIELD_STRING,"String_Node_Str").findAll();
  assertEquals(22,resultList.size());
}

Fixed version (ground truth):
@Test public void or(){
  populateTestRealm(realm,200);
  RealmQuery<AllTypes> query=realm.where(AllTypes.class).equalTo(AllTypes.FIELD_FLOAT,31.2345f);
  RealmResults<AllTypes> resultList=query.or().between(AllTypes.FIELD_LONG,1,20).findAll();
  assertEquals(21,resultList.size());
  resultList=query.or().equalTo(AllTypes.FIELD_STRING,"String_Node_Str").findAll();
  assertEquals(21,resultList.size());
  resultList=query.or().equalTo(AllTypes.FIELD_STRING,"String_Node_Str").findAll();
  assertEquals(22,resultList.size());
}
Program: 155707
Project: 155707
Buggy source:
@Test public void in_floatNull(){
  doTestForInFloat(NoPrimaryKeyNullTypes.FIELD_FLOAT_NULL);
  RealmResults<NoPrimaryKeyNullTypes> resultList=realm.where(NoPrimaryKeyNullTypes.class).not().in(NoPrimaryKeyNullTypes.FIELD_FLOAT_NULL,new Float[]{1.234567f + 1,null,1.234567f + 2}).findAll();
  assertEquals(131,resultList.size());
}

Fixed version (ground truth):
@Test public void in_floatNull(){
  doTestForInFloat(NoPrimaryKeyNullTypes.FIELD_FLOAT_NULL);
  RealmResults<NoPrimaryKeyNullTypes> resultList=realm.where(NoPrimaryKeyNullTypes.class).not().in(NoPrimaryKeyNullTypes.FIELD_FLOAT_NULL,new Float[]{1.2345f + 1,null,1.2345f + 2}).findAll();
  assertEquals(131,resultList.size());
}
Program: 155708
Project: 155708
Buggy source:
public UncheckedRow lastUncheckedRow(){
  return table.getUncheckedRowByPointer(nativeLastRow(nativePtr));
}

Fixed version (ground truth):
public UncheckedRow lastUncheckedRow(){
  long rowPtr=nativeLastRow(nativePtr);
  if (rowPtr != 0) {
    return table.getUncheckedRowByPointer(rowPtr);
  }
  return null;
}
Program: 155709
Project: 155709
Buggy source:
public UncheckedRow firstUncheckedRow(){
  return table.getUncheckedRowByPointer(nativeFirstRow(nativePtr));
}

Fixed version (ground truth):
public UncheckedRow firstUncheckedRow(){
  long rowPtr=nativeFirstRow(nativePtr);
  if (rowPtr != 0) {
    return table.getUncheckedRowByPointer(rowPtr);
  }
  return null;
}
Program: 155711
Project: 155711
Buggy source:
@Override public void onChange(PendingRow pendingRow){
  if (frontEnd == null) {
    throw new IllegalStateException(PROXY_NOT_SET_MESSAGE);
  }
  if (frontEnd.get() == null) {
    clearPendingCollection();
    return;
  }
  if (pendingCollection.isValid()) {
    UncheckedRow uncheckedRow=pendingCollection.firstUncheckedRow();
    if (uncheckedRow != null) {
      Row row=returnCheckedRow ? CheckedRow.getFromRow(uncheckedRow) : uncheckedRow;
      frontEnd.get().onQueryFinished(row);
      clearPendingCollection();
    }
  }
 else {
    clearPendingCollection();
  }
}

Fixed version (ground truth):
@Override public void onChange(PendingRow pendingRow){
  if (frontEnd == null) {
    throw new IllegalStateException(PROXY_NOT_SET_MESSAGE);
  }
  if (frontEnd.get() == null) {
    clearPendingCollection();
    return;
  }
  if (pendingCollection == null) {
    return;
  }
  if (pendingCollection.isValid()) {
    UncheckedRow uncheckedRow=pendingCollection.firstUncheckedRow();
    if (uncheckedRow != null) {
      Row row=returnCheckedRow ? CheckedRow.getFromRow(uncheckedRow) : uncheckedRow;
      frontEnd.get().onQueryFinished(row);
      clearPendingCollection();
    }
  }
 else {
    clearPendingCollection();
  }
}
Program: 155712
Project: 155712
Buggy source:
public PendingRow(SharedRealm sharedRealm,TableQuery query,SortDescriptor sortDescriptor,final boolean returnCheckedRow){
  pendingCollection=new Collection(sharedRealm,query,sortDescriptor);
  listener=new RealmChangeListener<PendingRow>(){
    @Override public void onChange(    PendingRow pendingRow){
      if (frontEnd == null) {
        throw new IllegalStateException(PROXY_NOT_SET_MESSAGE);
      }
      if (frontEnd.get() == null) {
        clearPendingCollection();
        return;
      }
      if (pendingCollection.isValid()) {
        UncheckedRow uncheckedRow=pendingCollection.firstUncheckedRow();
        if (uncheckedRow != null) {
          Row row=returnCheckedRow ? CheckedRow.getFromRow(uncheckedRow) : uncheckedRow;
          frontEnd.get().onQueryFinished(row);
          clearPendingCollection();
        }
      }
 else {
        clearPendingCollection();
      }
    }
  }
;
  pendingCollection.addListener(this,listener);
  this.returnCheckedRow=returnCheckedRow;
}

Fixed version (ground truth):
public PendingRow(SharedRealm sharedRealm,TableQuery query,SortDescriptor sortDescriptor,final boolean returnCheckedRow){
  pendingCollection=new Collection(sharedRealm,query,sortDescriptor);
  listener=new RealmChangeListener<PendingRow>(){
    @Override public void onChange(    PendingRow pendingRow){
      if (frontEnd == null) {
        throw new IllegalStateException(PROXY_NOT_SET_MESSAGE);
      }
      if (frontEnd.get() == null) {
        clearPendingCollection();
        return;
      }
      if (pendingCollection == null) {
        return;
      }
      if (pendingCollection.isValid()) {
        UncheckedRow uncheckedRow=pendingCollection.firstUncheckedRow();
        if (uncheckedRow != null) {
          Row row=returnCheckedRow ? CheckedRow.getFromRow(uncheckedRow) : uncheckedRow;
          frontEnd.get().onQueryFinished(row);
          clearPendingCollection();
        }
      }
 else {
        clearPendingCollection();
      }
    }
  }
;
  pendingCollection.addListener(this,listener);
  this.returnCheckedRow=returnCheckedRow;
}
Program: 155713
Project: 155713
Buggy source:
@Override protected void onStart(){
  super.onStart();
  user=User.currentUser();
  if (user != null) {
    SyncConfiguration config=new SyncConfiguration.Builder(user,REALM_URL).initialData(new Realm.Transaction(){
      @Override public void execute(      Realm realm){
        realm.createObject(CRDTCounter.class,1);
      }
    }
).build();
    realm=Realm.getInstance(config);
    counter=realm.where(CounterOperation.class).findAllAsync();
    counter.addChangeListener(new RealmChangeListener<RealmResults<CounterOperation>>(){
      @Override public void onChange(      RealmResults<CounterOperation> result){
        Number sum=result.sum("String_Node_Str");
        if (sum != null) {
          counterView.setText(Long.toString(sum.longValue()));
        }
 else {
          counterView.setText("String_Node_Str");
        }
      }
    }
);
    counterView.setText("String_Node_Str");
  }
}

Fixed version (ground truth):
@Override protected void onStart(){
  super.onStart();
  user=User.currentUser();
  if (user != null) {
    SyncConfiguration config=new SyncConfiguration.Builder(user,REALM_URL).initialData(new Realm.Transaction(){
      @Override public void execute(      Realm realm){
        if (realm.isEmpty()) {
          realm.createObject(CRDTCounter.class,1);
        }
      }
    }
).build();
    realm=Realm.getInstance(config);
    counter=realm.where(CounterOperation.class).findAllAsync();
    counter.addChangeListener(new RealmChangeListener<RealmResults<CounterOperation>>(){
      @Override public void onChange(      RealmResults<CounterOperation> result){
        Number sum=result.sum("String_Node_Str");
        if (sum != null) {
          counterView.setText(Long.toString(sum.longValue()));
        }
 else {
          counterView.setText("String_Node_Str");
        }
      }
    }
);
    counterView.setText("String_Node_Str");
  }
}