Program: 155740
Project: 155740
Buggy source:
/** 
 * Similar to   {@link #executeTransaction(Transaction)} but runs asynchronously from a worker thread.
 * @param transaction {@link io.realm.Realm.Transaction} to execute.
 * @param callback optional, to receive the result of this query.
 * @return a {@link RealmAsyncTask} representing a cancellable task.
 * @throws IllegalArgumentException if the {@code transaction} is {@code null}, or if the realm is opened from another thread.
 */
public RealmAsyncTask executeTransaction(final Transaction transaction,final Transaction.Callback callback){
  if (transaction == null)   throw new IllegalArgumentException("String_Node_Str");
  if (callback != null && handler == null) {
    throw new IllegalStateException("String_Node_Str" + "String_Node_Str");
  }
  final RealmConfiguration realmConfiguration=getConfiguration();
  final Future<?> pendingQuery=asyncQueryExecutor.submit(new Runnable(){
    @Override public void run(){
      if (!Thread.currentThread().isInterrupted()) {
        Realm bgRealm=Realm.getInstance(realmConfiguration);
        bgRealm.beginTransaction();
        try {
          transaction.execute(bgRealm);
          if (!Thread.currentThread().isInterrupted()) {
            bgRealm.commitTransaction();
            if (callback != null && handler != null && !Thread.currentThread().isInterrupted() && handler.getLooper().getThread().isAlive()) {
              bgRealm.close();
              handler.post(new Runnable(){
                @Override public void run(){
                  callback.onSuccess();
                }
              }
);
            }
          }
 else {
            if (bgRealm.isInTransaction()) {
              bgRealm.cancelTransaction();
            }
 else {
              RealmLog.w("String_Node_Str");
            }
          }
        }
 catch (        final Exception e) {
          if (bgRealm.isInTransaction()) {
            bgRealm.cancelTransaction();
          }
 else {
            RealmLog.w("String_Node_Str");
          }
          if (callback != null && handler != null && !Thread.currentThread().isInterrupted() && handler.getLooper().getThread().isAlive()) {
            bgRealm.close();
            handler.post(new Runnable(){
              @Override public void run(){
                callback.onError(e);
              }
            }
);
          }
        }
 finally {
          if (!bgRealm.isClosed()) {
            bgRealm.close();
          }
        }
      }
    }
  }
);
  return new RealmAsyncTask(pendingQuery);
}

Fixed version (ground truth):
/** 
 * Similar to   {@link #executeTransaction(Transaction)} but runs asynchronously from a worker thread.
 * @param transaction {@link io.realm.Realm.Transaction} to execute.
 * @param callback optional, to receive the result of this query.
 * @return a {@link RealmAsyncTask} representing a cancellable task.
 * @throws IllegalArgumentException if the {@code transaction} is {@code null}, or if the realm is opened from another thread.
 */
public RealmAsyncTask executeTransaction(final Transaction transaction,final Transaction.Callback callback){
  if (transaction == null)   throw new IllegalArgumentException("String_Node_Str");
  if (callback != null && handler == null) {
    throw new IllegalStateException("String_Node_Str" + "String_Node_Str");
  }
  final RealmConfiguration realmConfiguration=getConfiguration();
  final Future<?> pendingQuery=asyncQueryExecutor.submit(new Runnable(){
    @Override public void run(){
      if (Thread.currentThread().isInterrupted()) {
        return;
      }
      boolean transactionCommitted=false;
      final Exception[] exception=new Exception[1];
      final Realm bgRealm=Realm.getInstance(realmConfiguration);
      bgRealm.beginTransaction();
      try {
        transaction.execute(bgRealm);
        if (!Thread.currentThread().isInterrupted()) {
          bgRealm.commitTransaction(new Runnable(){
            @Override public void run(){
              bgRealm.close();
            }
          }
);
          transactionCommitted=true;
        }
      }
 catch (      final Exception e) {
        exception[0]=e;
      }
 finally {
        if (!bgRealm.isClosed()) {
          if (bgRealm.isInTransaction()) {
            bgRealm.cancelTransaction();
          }
 else           if (exception[0] != null) {
            RealmLog.w("String_Node_Str");
          }
          bgRealm.close();
        }
        if (callback != null && handler != null && !Thread.currentThread().isInterrupted() && handler.getLooper().getThread().isAlive()) {
          if (transactionCommitted) {
            handler.post(new Runnable(){
              @Override public void run(){
                callback.onSuccess();
              }
            }
);
          }
 else           if (exception[0] != null) {
            handler.post(new Runnable(){
              @Override public void run(){
                callback.onError(exception[0]);
              }
            }
);
          }
        }
      }
    }
  }
);
  return new RealmAsyncTask(pendingQuery);
}