Program: 155604
Project: 155604
Buggy source:
@Test @RunTestInLooperThread public void findAllSortedAsync_usingMultipleFields(){
  final DynamicRealm dynamicRealm=initializeDynamicRealm();
  dynamicRealm.setAutoRefresh(false);
  dynamicRealm.beginTransaction();
  dynamicRealm.delete(AllTypes.CLASS_NAME);
  for (int i=0; i < 5; ) {
    DynamicRealmObject allTypes=dynamicRealm.createObject(AllTypes.CLASS_NAME);
    allTypes.set(AllTypes.FIELD_LONG,i);
    allTypes.set(AllTypes.FIELD_STRING,"String_Node_Str" + i % 3);
    allTypes=dynamicRealm.createObject(AllTypes.CLASS_NAME);
    allTypes.set(AllTypes.FIELD_LONG,i);
    allTypes.set(AllTypes.FIELD_STRING,"String_Node_Str" + (++i % 3));
  }
  dynamicRealm.commitTransaction();
  dynamicRealm.setAutoRefresh(true);
  final RealmResults<DynamicRealmObject> realmResults1=dynamicRealm.where(AllTypes.CLASS_NAME).findAllSortedAsync(new String[]{AllTypes.FIELD_STRING,AllTypes.FIELD_LONG},new Sort[]{Sort.ASCENDING,Sort.DESCENDING});
  final RealmResults<DynamicRealmObject> realmResults2=dynamicRealm.where(AllTypes.CLASS_NAME).between(AllTypes.FIELD_LONG,0,5).findAllSortedAsync(new String[]{AllTypes.FIELD_STRING,AllTypes.FIELD_LONG},new Sort[]{Sort.DESCENDING,Sort.ASCENDING});
  final Runnable signalCallbackDone=new Runnable(){
    final AtomicInteger callbacksDone=new AtomicInteger(2);
    @Override public void run(){
      if (callbacksDone.decrementAndGet() == 0) {
        dynamicRealm.close();
        looperThread.testComplete();
      }
    }
  }
;
  realmResults1.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>(){
    @Override public void onChange(    RealmResults<DynamicRealmObject> object){
      assertEquals("String_Node_Str",realmResults1.get(0).get(AllTypes.FIELD_STRING));
      assertEquals(3L,realmResults1.get(0).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(1).get(AllTypes.FIELD_STRING));
      assertEquals(2L,realmResults1.get(1).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(2).get(AllTypes.FIELD_STRING));
      assertEquals(0L,realmResults1.get(2).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(3).get(AllTypes.FIELD_STRING));
      assertEquals(4L,realmResults1.get(3).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(4).get(AllTypes.FIELD_STRING));
      assertEquals(3L,realmResults1.get(4).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(5).get(AllTypes.FIELD_STRING));
      assertEquals(1L,realmResults1.get(5).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(6).get(AllTypes.FIELD_STRING));
      assertEquals(0L,realmResults1.get(6).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(7).get(AllTypes.FIELD_STRING));
      assertEquals(4L,realmResults1.get(7).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(8).get(AllTypes.FIELD_STRING));
      assertEquals(2L,realmResults1.get(8).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(9).get(AllTypes.FIELD_STRING));
      assertEquals(1L,realmResults1.get(9).get(AllTypes.FIELD_LONG));
      signalCallbackDone.run();
    }
  }
);
  realmResults2.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>(){
    @Override public void onChange(    RealmResults<DynamicRealmObject> object){
      assertEquals("String_Node_Str",realmResults2.get(0).get(AllTypes.FIELD_STRING));
      assertEquals(1L,realmResults2.get(0).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(1).get(AllTypes.FIELD_STRING));
      assertEquals(2L,realmResults2.get(1).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(2).get(AllTypes.FIELD_STRING));
      assertEquals(4L,realmResults2.get(2).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(3).get(AllTypes.FIELD_STRING));
      assertEquals(0L,realmResults2.get(3).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(4).get(AllTypes.FIELD_STRING));
      assertEquals(1L,realmResults2.get(4).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(5).get(AllTypes.FIELD_STRING));
      assertEquals(3L,realmResults2.get(5).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(6).get(AllTypes.FIELD_STRING));
      assertEquals(4L,realmResults2.get(6).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(7).get(AllTypes.FIELD_STRING));
      assertEquals(0L,realmResults2.get(7).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(8).get(AllTypes.FIELD_STRING));
      assertEquals(2L,realmResults2.get(8).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(9).get(AllTypes.FIELD_STRING));
      assertEquals(3L,realmResults2.get(9).get(AllTypes.FIELD_LONG));
      signalCallbackDone.run();
    }
  }
);
  looperThread.keepStrongReference.add(realmResults1);
  looperThread.keepStrongReference.add(realmResults2);
}

Fixed version (ground truth):
@Test @RunTestInLooperThread public void findAllSortedAsync_usingMultipleFields(){
  final DynamicRealm dynamicRealm=initializeDynamicRealm();
  dynamicRealm.setAutoRefresh(false);
  dynamicRealm.beginTransaction();
  dynamicRealm.delete(AllTypes.CLASS_NAME);
  for (int i=0; i < 5; ) {
    DynamicRealmObject allTypes=dynamicRealm.createObject(AllTypes.CLASS_NAME);
    allTypes.set(AllTypes.FIELD_LONG,i);
    allTypes.set(AllTypes.FIELD_STRING,"String_Node_Str" + i % 3);
    allTypes=dynamicRealm.createObject(AllTypes.CLASS_NAME);
    allTypes.set(AllTypes.FIELD_LONG,i);
    allTypes.set(AllTypes.FIELD_STRING,"String_Node_Str" + (++i % 3));
  }
  dynamicRealm.commitTransaction();
  dynamicRealm.setAutoRefresh(true);
  final RealmResults<DynamicRealmObject> realmResults1=dynamicRealm.where(AllTypes.CLASS_NAME).findAllSortedAsync(new String[]{AllTypes.FIELD_STRING,AllTypes.FIELD_LONG},new Sort[]{Sort.ASCENDING,Sort.DESCENDING});
  final RealmResults<DynamicRealmObject> realmResults2=dynamicRealm.where(AllTypes.CLASS_NAME).between(AllTypes.FIELD_LONG,0,5).findAllSortedAsync(new String[]{AllTypes.FIELD_STRING,AllTypes.FIELD_LONG},new Sort[]{Sort.DESCENDING,Sort.ASCENDING});
  final Runnable signalCallbackDone=new Runnable(){
    final AtomicInteger callbacksDone=new AtomicInteger(2);
    @Override public void run(){
      if (callbacksDone.decrementAndGet() == 0) {
        dynamicRealm.close();
        looperThread.testComplete();
      }
    }
  }
;
  realmResults1.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>(){
    @Override public void onChange(    RealmResults<DynamicRealmObject> object){
      assertEquals("String_Node_Str",realmResults1.get(0).get(AllTypes.FIELD_STRING));
      assertEquals(3L,realmResults1.get(0).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(1).get(AllTypes.FIELD_STRING));
      assertEquals(2L,realmResults1.get(1).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(2).get(AllTypes.FIELD_STRING));
      assertEquals(0L,realmResults1.get(2).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(3).get(AllTypes.FIELD_STRING));
      assertEquals(4L,realmResults1.get(3).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(4).get(AllTypes.FIELD_STRING));
      assertEquals(3L,realmResults1.get(4).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(5).get(AllTypes.FIELD_STRING));
      assertEquals(1L,realmResults1.get(5).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(6).get(AllTypes.FIELD_STRING));
      assertEquals(0L,realmResults1.get(6).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(7).get(AllTypes.FIELD_STRING));
      assertEquals(4L,realmResults1.get(7).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(8).get(AllTypes.FIELD_STRING));
      assertEquals(2L,realmResults1.get(8).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults1.get(9).get(AllTypes.FIELD_STRING));
      assertEquals(1L,realmResults1.get(9).get(AllTypes.FIELD_LONG));
      signalCallbackDone.run();
    }
  }
);
  realmResults2.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>(){
    @Override public void onChange(    RealmResults<DynamicRealmObject> object){
      assertEquals("String_Node_Str",realmResults2.get(0).get(AllTypes.FIELD_STRING));
      assertEquals(1L,realmResults2.get(0).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(1).get(AllTypes.FIELD_STRING));
      assertEquals(2L,realmResults2.get(1).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(2).get(AllTypes.FIELD_STRING));
      assertEquals(4L,realmResults2.get(2).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(3).get(AllTypes.FIELD_STRING));
      assertEquals(0L,realmResults2.get(3).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(4).get(AllTypes.FIELD_STRING));
      assertEquals(1L,realmResults2.get(4).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(5).get(AllTypes.FIELD_STRING));
      assertEquals(3L,realmResults2.get(5).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(6).get(AllTypes.FIELD_STRING));
      assertEquals(4L,realmResults2.get(6).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(7).get(AllTypes.FIELD_STRING));
      assertEquals(0L,realmResults2.get(7).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(8).get(AllTypes.FIELD_STRING));
      assertEquals(2L,realmResults2.get(8).get(AllTypes.FIELD_LONG));
      assertEquals("String_Node_Str",realmResults2.get(9).get(AllTypes.FIELD_STRING));
      assertEquals(3L,realmResults2.get(9).get(AllTypes.FIELD_LONG));
      signalCallbackDone.run();
    }
  }
);
  looperThread.keepStrongReference(realmResults1);
  looperThread.keepStrongReference(realmResults2);
}