Program: 12304
Project: 12304
Buggy source:
/** 
 * reorder.cpp:339
 * @param id_test
 * @param b
 * @param tc
 * @param tests_to_restore
 * @return
 */
private SavedTest restore_saved_tests_to_test(ByRef<Test> t,boolean is_id_field,int bound_vars_tc_number,SavedTest tests_to_restore){
  SavedTest prev_st=null, next_st=null;
  SavedTest st=tests_to_restore;
  while (st != null) {
    next_st=st.next;
    boolean added_it=false;
    if ((is_id_field && (st.the_test.asGoalIdTest() != null || st.the_test.asImpasseIdTest() != null)) || st.the_test.asDisjunctionTest() != null) {
      if (Tests.test_includes_equality_test_for_symbol(t.value,st.var)) {
        t.value=Tests.add_new_test_to_test_if_not_already_there(t.value,st.the_test);
        added_it=true;
      }
    }
    RelationalTest rt=st.the_test.asRelationalTest();
    if (rt != null) {
      SymbolImpl referent=rt.referent;
      if (Tests.test_includes_equality_test_for_symbol(t.value,st.var)) {
        if (symbol_is_constant_or_marked_variable(referent,bound_vars_tc_number) || (st.var == referent)) {
          t.value=Tests.add_new_test_to_test_if_not_already_there(t.value,st.the_test);
          added_it=true;
        }
      }
 else       if (Tests.test_includes_equality_test_for_symbol(t.value,referent)) {
        if (symbol_is_constant_or_marked_variable(st.var,bound_vars_tc_number) || (st.var == referent)) {
          rt.type=RelationalTest.reverse_direction_of_relational_test(rt.type);
          rt.referent=st.var;
          st.var=referent;
          t.value=Tests.add_new_test_to_test_if_not_already_there(t.value,st.the_test);
          added_it=true;
        }
      }
    }
    if (added_it) {
      if (prev_st != null) {
        prev_st.next=next_st;
      }
 else {
        tests_to_restore=next_st;
      }
    }
 else {
      prev_st=st;
    }
    st=next_st;
  }
  return tests_to_restore;
}

Fixed version (ground truth):
/** 
 * reorder.cpp:339
 * @param id_test
 * @param b
 * @param tc
 * @param tests_to_restore
 * @return
 */
private SavedTest restore_saved_tests_to_test(ByRef<Test> t,boolean is_id_field,int bound_vars_tc_number,SavedTest tests_to_restore,boolean neg){
  SavedTest prev_st=null, next_st=null;
  SavedTest st=tests_to_restore;
  while (st != null) {
    next_st=st.next;
    boolean added_it=false;
    if ((is_id_field && (st.the_test.asGoalIdTest() != null || st.the_test.asImpasseIdTest() != null)) || st.the_test.asDisjunctionTest() != null) {
      if (Tests.test_includes_equality_test_for_symbol(t.value,st.var)) {
        t.value=Tests.add_new_test_to_test_if_not_already_there(t.value,st.the_test,neg);
        added_it=true;
      }
    }
    RelationalTest rt=st.the_test.asRelationalTest();
    if (rt != null) {
      SymbolImpl referent=rt.referent;
      if (Tests.test_includes_equality_test_for_symbol(t.value,st.var)) {
        if (symbol_is_constant_or_marked_variable(referent,bound_vars_tc_number) || (st.var == referent)) {
          t.value=Tests.add_new_test_to_test_if_not_already_there(t.value,st.the_test,neg);
          added_it=true;
        }
      }
 else       if (Tests.test_includes_equality_test_for_symbol(t.value,referent)) {
        if (symbol_is_constant_or_marked_variable(st.var,bound_vars_tc_number) || (st.var == referent)) {
          rt.type=RelationalTest.reverse_direction_of_relational_test(rt.type);
          rt.referent=st.var;
          st.var=referent;
          t.value=Tests.add_new_test_to_test_if_not_already_there(t.value,st.the_test,neg);
          added_it=true;
        }
      }
    }
    if (added_it) {
      if (prev_st != null) {
        prev_st.next=next_st;
      }
 else {
        tests_to_restore=next_st;
      }
    }
 else {
      prev_st=st;
    }
    st=next_st;
  }
  return tests_to_restore;
}