nus-yam/ex-repair huggingface dataset:
Program: 155531
Project: 155531
Buggy source:
public void setHoldability(int holdability) throws SQLException {
  getConnection().setHoldability(holdability);
}

Fixed version (ground truth):
public void setHoldability(int holdability) throws SQLException {
  getDelegate().setHoldability(holdability);
}
Program: 155532
Project: 155532
Buggy source:
public String getCatalog() throws SQLException {
  return getConnection().getCatalog();
}

Fixed version (ground truth):
public String getCatalog() throws SQLException {
  return getDelegate().getCatalog();
}
Program: 155533
Project: 155533
Buggy source:
public String nativeSQL(String sql) throws SQLException {
  return getConnection().nativeSQL(sql);
}

Fixed version (ground truth):
public String nativeSQL(String sql) throws SQLException {
  return getDelegate().nativeSQL(sql);
}
Program: 155534
Project: 155534
Buggy source:
public Connection getConnection(){
  return connection;
}

Fixed version (ground truth):
public Connection getConnection(){
  return delegate;
}
Program: 155535
Project: 155535
Buggy source:
public boolean isReadOnly() throws SQLException {
  return getConnection().isReadOnly();
}

Fixed version (ground truth):
public boolean isReadOnly() throws SQLException {
  return getDelegate().isReadOnly();
}
Program: 155536
Project: 155536
Buggy source:
public Savepoint setSavepoint(String name) throws SQLException {
  if (jdbcPooledConnection == null)   throw new SQLException("String_Node_Str");
  if (jdbcPooledConnection.isParticipatingInActiveGlobalTransaction())   throw new SQLException("String_Node_Str");
  return getConnection().setSavepoint(name);
}

Fixed version (ground truth):
public Savepoint setSavepoint(String name) throws SQLException {
  if (jdbcPooledConnection == null)   throw new SQLException("String_Node_Str");
  if (jdbcPooledConnection.isParticipatingInActiveGlobalTransaction())   throw new SQLException("String_Node_Str");
  return getDelegate().setSavepoint(name);
}
Program: 155537
Project: 155537
Buggy source:
public void close() throws SQLException {
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + this);
  if (jdbcPooledConnection == null)   return;
  PoolingDataSource poolingDataSource=jdbcPooledConnection.getPoolingDataSource();
  jdbcPooledConnection.release();
  jdbcPooledConnection=null;
  if (!poolingDataSource.getKeepConnectionOpenUntilAfter2Pc()) {
    connection.close();
  }
 else {
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + connection);
  }
}

Fixed version (ground truth):
public void close() throws SQLException {
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + this);
  if (jdbcPooledConnection == null)   return;
  PoolingDataSource poolingDataSource=jdbcPooledConnection.getPoolingDataSource();
  jdbcPooledConnection.release();
  jdbcPooledConnection=null;
  if (!poolingDataSource.getKeepConnectionOpenUntilAfter2Pc()) {
    delegate.close();
  }
 else {
    pretendClosed=true;
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + delegate);
  }
}
Program: 155538
Project: 155538
Buggy source:
public void rollback(Savepoint savepoint) throws SQLException {
  if (jdbcPooledConnection == null)   throw new SQLException("String_Node_Str");
  if (jdbcPooledConnection.isParticipatingInActiveGlobalTransaction())   throw new SQLException("String_Node_Str");
  getConnection().rollback(savepoint);
}

Fixed version (ground truth):
public void rollback(Savepoint savepoint) throws SQLException {
  if (jdbcPooledConnection == null)   throw new SQLException("String_Node_Str");
  if (jdbcPooledConnection.isParticipatingInActiveGlobalTransaction())   throw new SQLException("String_Node_Str");
  getDelegate().rollback(savepoint);
}
Program: 155539
Project: 155539
Buggy source:
public void setTypeMap(Map map) throws SQLException {
  getConnection().setTypeMap(map);
}

Fixed version (ground truth):
public void setTypeMap(Map map) throws SQLException {
  getDelegate().setTypeMap(map);
}
Program: 155540
Project: 155540
Buggy source:
public boolean getAutoCommit() throws SQLException {
  if (jdbcPooledConnection == null)   throw new SQLException("String_Node_Str");
  if (jdbcPooledConnection.isParticipatingInActiveGlobalTransaction())   return false;
  return getConnection().getAutoCommit();
}

Fixed version (ground truth):
public boolean getAutoCommit() throws SQLException {
  if (jdbcPooledConnection == null)   throw new SQLException("String_Node_Str");
  if (jdbcPooledConnection.isParticipatingInActiveGlobalTransaction())   return false;
  return getDelegate().getAutoCommit();
}
Program: 155541
Project: 155541
Buggy source:
public void clearWarnings() throws SQLException {
  getConnection().clearWarnings();
}

Fixed version (ground truth):
public void clearWarnings() throws SQLException {
  getDelegate().clearWarnings();
}
Program: 155542
Project: 155542
Buggy source:
public Statement createStatement(int resultSetType,int resultSetConcurrency,int resultSetHoldability) throws SQLException {
  enlistResource();
  return getConnection().createStatement(resultSetType,resultSetConcurrency,resultSetHoldability);
}

Fixed version (ground truth):
public Statement createStatement(int resultSetType,int resultSetConcurrency,int resultSetHoldability) throws SQLException {
  enlistResource();
  return getDelegate().createStatement(resultSetType,resultSetConcurrency,resultSetHoldability);
}
Program: 155543
Project: 155543
Buggy source:
public boolean isClosed() throws SQLException {
  if (jdbcPooledConnection == null)   return true;
  return getConnection().isClosed();
}

Fixed version (ground truth):
public boolean isClosed() throws SQLException {
  if (jdbcPooledConnection == null)   return true;
  return getDelegate().isClosed();
}
Program: 155544
Project: 155544
Buggy source:
public void setAutoCommit(boolean autoCommit) throws SQLException {
  if (jdbcPooledConnection == null)   throw new SQLException("String_Node_Str");
  if (!jdbcPooledConnection.isParticipatingInActiveGlobalTransaction())   getConnection().setAutoCommit(autoCommit);
 else   if (autoCommit)   throw new SQLException("String_Node_Str");
}

Fixed version (ground truth):
public void setAutoCommit(boolean autoCommit) throws SQLException {
  if (jdbcPooledConnection == null)   throw new SQLException("String_Node_Str");
  if (!jdbcPooledConnection.isParticipatingInActiveGlobalTransaction())   getDelegate().setAutoCommit(autoCommit);
 else   if (autoCommit)   throw new SQLException("String_Node_Str");
}
Program: 155545
Project: 155545
Buggy source:
public int getTransactionIsolation() throws SQLException {
  return getConnection().getTransactionIsolation();
}

Fixed version (ground truth):
public int getTransactionIsolation() throws SQLException {
  return getDelegate().getTransactionIsolation();
}
Program: 155546
Project: 155546
Buggy source:
public String toString(){
  return "String_Node_Str" + jdbcPooledConnection + "String_Node_Str"+ connection;
}

Fixed version (ground truth):
public String toString(){
  return "String_Node_Str" + jdbcPooledConnection + "String_Node_Str"+ delegate;
}
Program: 155547
Project: 155547
Buggy source:
public DatabaseMetaData getMetaData() throws SQLException {
  return getConnection().getMetaData();
}

Fixed version (ground truth):
public DatabaseMetaData getMetaData() throws SQLException {
  return getDelegate().getMetaData();
}
Program: 155548
Project: 155548
Buggy source:
public void setReadOnly(boolean readOnly) throws SQLException {
  getConnection().setReadOnly(readOnly);
}

Fixed version (ground truth):
public void setReadOnly(boolean readOnly) throws SQLException {
  getDelegate().setReadOnly(readOnly);
}
Program: 155549
Project: 155549
Buggy source:
public CallableStatement prepareCall(String sql,int resultSetType,int resultSetConcurrency,int resultSetHoldability) throws SQLException {
  enlistResource();
  return getConnection().prepareCall(sql,resultSetType,resultSetConcurrency,resultSetHoldability);
}

Fixed version (ground truth):
public CallableStatement prepareCall(String sql,int resultSetType,int resultSetConcurrency,int resultSetHoldability) throws SQLException {
  enlistResource();
  return getDelegate().prepareCall(sql,resultSetType,resultSetConcurrency,resultSetHoldability);
}
Program: 155550
Project: 155550
Buggy source:
public Map getTypeMap() throws SQLException {
  return getConnection().getTypeMap();
}

Fixed version (ground truth):
public Map getTypeMap() throws SQLException {
  return getDelegate().getTypeMap();
}
Program: 155551
Project: 155551
Buggy source:
/** 
 * Run all registered Synchronizations' beforeCompletion() method. Be aware that this method can change the transaction status to mark it as rollback only for instance.
 * @throws bitronix.tm.internal.BitronixSystemException
 */
private void fireBeforeCompletionEvent() throws BitronixSystemException {
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + synchronizations.size() + "String_Node_Str");
  for (int i=0; i < synchronizations.size(); i++) {
    Synchronization synchronization=(Synchronization)synchronizations.get(i);
    try {
      if (log.isDebugEnabled())       log.debug("String_Node_Str" + synchronization);
      synchronization.beforeCompletion();
    }
 catch (    RuntimeException ex) {
      log.warn("String_Node_Str" + synchronization + "String_Node_Str",ex);
      setStatus(Status.STATUS_MARKED_ROLLBACK);
      return;
    }
  }
  ManagementRegistrar.unregister("String_Node_Str" + resourceManager.getGtrid());
}

Fixed version (ground truth):
/** 
 * Run all registered Synchronizations' beforeCompletion() method. Be aware that this method can change the transaction status to mark it as rollback only for instance.
 * @throws bitronix.tm.internal.BitronixSystemException if status changing due to a synchronization throwing anexception fails.
 */
private void fireBeforeCompletionEvent() throws BitronixSystemException {
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + synchronizations.size() + "String_Node_Str");
  for (int i=0; i < synchronizations.size(); i++) {
    Synchronization synchronization=(Synchronization)synchronizations.get(i);
    try {
      if (log.isDebugEnabled())       log.debug("String_Node_Str" + synchronization);
      synchronization.beforeCompletion();
    }
 catch (    RuntimeException ex) {
      log.warn("String_Node_Str" + synchronization + "String_Node_Str",ex);
      setStatus(Status.STATUS_MARKED_ROLLBACK);
      return;
    }
  }
}
Program: 155552
Project: 155552
Buggy source:
private void fireAfterCompletionEvent(){
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + synchronizations.size() + "String_Node_Str");
  for (int i=0; i < synchronizations.size(); i++) {
    Synchronization synchronization=(Synchronization)synchronizations.get(i);
    try {
      if (log.isDebugEnabled())       log.debug("String_Node_Str" + synchronization + "String_Node_Str"+ Decoder.decodeStatus(status));
      synchronization.afterCompletion(status);
    }
 catch (    Exception ex) {
      log.warn("String_Node_Str" + synchronization,ex);
    }
  }
}

Fixed version (ground truth):
private void fireAfterCompletionEvent(){
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + synchronizations.size() + "String_Node_Str");
  for (int i=0; i < synchronizations.size(); i++) {
    Synchronization synchronization=(Synchronization)synchronizations.get(i);
    try {
      if (log.isDebugEnabled())       log.debug("String_Node_Str" + synchronization + "String_Node_Str"+ Decoder.decodeStatus(status));
      synchronization.afterCompletion(status);
    }
 catch (    Exception ex) {
      log.warn("String_Node_Str" + synchronization,ex);
    }
  }
  ManagementRegistrar.unregister("String_Node_Str" + resourceManager.getGtrid());
}
Program: 155553
Project: 155553
Buggy source:
private void closePendingSessions(){
  for (int i=0; i < sessions.size(); i++) {
    DualSessionWrapper dualSessionWrapper=(DualSessionWrapper)sessions.get(i);
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + dualSessionWrapper);
    try {
      dualSessionWrapper.close();
    }
 catch (    JMSException ex) {
      log.warn("String_Node_Str" + dualSessionWrapper,ex);
    }
  }
}

Fixed version (ground truth):
private void closePendingSessions(){
  for (int i=0; i < sessions.size(); i++) {
    DualSessionWrapper dualSessionWrapper=(DualSessionWrapper)sessions.get(i);
    if (dualSessionWrapper.getState() != STATE_ACCESSIBLE)     continue;
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + dualSessionWrapper);
    try {
      dualSessionWrapper.close();
    }
 catch (    JMSException ex) {
      log.warn("String_Node_Str" + dualSessionWrapper,ex);
    }
  }
}
Program: 155554
Project: 155554
Buggy source:
public void stateChanged(XAStatefulHolder source,int oldState,int newState){
  if (newState == STATE_IN_POOL) {
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + poolingConnectionFactory);
  }
  if (oldState == STATE_IN_POOL && newState == STATE_ACCESSIBLE) {
    acquisitionDate=new Date();
  }
  if (newState == STATE_CLOSED) {
    sessions.remove(source);
    ManagementRegistrar.unregister(jmxName);
  }
}

Fixed version (ground truth):
public void stateChanged(XAStatefulHolder source,int oldState,int newState){
  if (newState == STATE_IN_POOL) {
    if (log.isDebugEnabled())     log.debug("String_Node_Str" + poolingConnectionFactory);
    sessions.clear();
  }
  if (oldState == STATE_IN_POOL && newState == STATE_ACCESSIBLE) {
    acquisitionDate=new Date();
  }
  if (newState == STATE_CLOSED) {
    ManagementRegistrar.unregister(jmxName);
  }
}
Program: 155556
Project: 155556
Buggy source:
@Override public void run(){
  try {
    object.getDynamicRealm();
    fail();
  }
 catch (  Throwable t) {
    throwable.set(t);
  }
 finally {
    threadFinished.countDown();
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    object.getDynamicRealm();
    fail();
  }
 catch (  IllegalStateException e) {
    assertEquals(BaseRealm.INCORRECT_THREAD_MESSAGE,e.getMessage());
  }
 finally {
    threadFinished.countDown();
  }
}
Program: 155557
Project: 155557
Buggy source:
@Test public void getRealm_illegalThreadThrows() throws Throwable {
  realm.beginTransaction();
  realm.createObject(AllTypes.class);
  realm.commitTransaction();
  dynamicRealm.refresh();
  final DynamicRealmObject object=dynamicRealm.where(AllTypes.CLASS_NAME).findFirst();
  final CountDownLatch threadFinished=new CountDownLatch(1);
  final AtomicReference<Throwable> throwable=new AtomicReference<>();
  final Thread thread=new Thread(new Runnable(){
    @Override public void run(){
      try {
        object.getDynamicRealm();
        fail();
      }
 catch (      Throwable t) {
        throwable.set(t);
      }
 finally {
        threadFinished.countDown();
      }
    }
  }
);
  thread.start();
  TestHelper.awaitOrFail(threadFinished);
  final Throwable thrownInTheThread=throwable.get();
  if (!(thrownInTheThread instanceof IllegalStateException)) {
    throw thrownInTheThread;
  }
  assertEquals(BaseRealm.INCORRECT_THREAD_MESSAGE,thrownInTheThread.getMessage());
}

Fixed version (ground truth):
@Test public void getRealm_illegalThreadThrows() throws Throwable {
  realm.beginTransaction();
  realm.createObject(AllTypes.class);
  realm.commitTransaction();
  dynamicRealm.refresh();
  final DynamicRealmObject object=dynamicRealm.where(AllTypes.CLASS_NAME).findFirst();
  final CountDownLatch threadFinished=new CountDownLatch(1);
  final Thread thread=new Thread(new Runnable(){
    @Override public void run(){
      try {
        object.getDynamicRealm();
        fail();
      }
 catch (      IllegalStateException e) {
        assertEquals(BaseRealm.INCORRECT_THREAD_MESSAGE,e.getMessage());
      }
 finally {
        threadFinished.countDown();
      }
    }
  }
);
  thread.start();
  TestHelper.awaitOrFail(threadFinished);
}
Program: 155558
Project: 155558
Buggy source:
@Test public void mutableMethodsOutsideTransactions(){
  for (  OrderedCollectionMutatorMethod method : OrderedCollectionMutatorMethod.values()) {
    Class<? extends Throwable> expected=IllegalStateException.class;
    if (collectionClass == ManagedCollection.REALMRESULTS || isSnapshot(collectionClass)) {
switch (method) {
case ADD_INDEX:
case ADD_ALL_INDEX:
case SET:
case REMOVE_INDEX:
        expected=UnsupportedOperationException.class;
      break;
default :
  }
}
try {
switch (method) {
case DELETE_INDEX:
    collection.deleteFromRealm(0);
  break;
case DELETE_FIRST:
collection.deleteFirstFromRealm();
break;
case DELETE_LAST:
collection.deleteLastFromRealm();
break;
case ADD_INDEX:
collection.add(0,new AllJavaTypes());
break;
case ADD_ALL_INDEX:
collection.addAll(0,Collections.singletonList(new AllJavaTypes()));
break;
case SET:
collection.set(0,new AllJavaTypes());
break;
case REMOVE_INDEX:
collection.remove(0);
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 (  OrderedCollectionMutatorMethod method : OrderedCollectionMutatorMethod.values()) {
    Class<? extends Throwable> expected=IllegalStateException.class;
    if (collectionClass == ManagedCollection.REALMRESULTS || isSnapshot(collectionClass)) {
switch (method) {
case ADD_INDEX:
case ADD_ALL_INDEX:
case SET:
case REMOVE_INDEX:
        expected=UnsupportedOperationException.class;
      break;
default :
  }
}
try {
switch (method) {
case DELETE_INDEX:
    collection.deleteFromRealm(0);
  break;
case DELETE_FIRST:
collection.deleteFirstFromRealm();
break;
case DELETE_LAST:
collection.deleteLastFromRealm();
break;
case ADD_INDEX:
collection.add(0,new AllJavaTypes());
break;
case ADD_ALL_INDEX:
collection.addAll(0,Collections.singletonList(new AllJavaTypes()));
break;
case SET:
collection.set(0,new AllJavaTypes());
break;
case REMOVE_INDEX:
collection.remove(0);
break;
}
fail("String_Node_Str" + method);
}
 catch (IllegalStateException e) {
assertEquals(expected,e.getClass());
}
catch (UnsupportedOperationException e) {
assertEquals(expected,e.getClass());
}
}
}
Program: 155559
Project: 155559
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;
      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);
}
}
}
}

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 (IllegalStateException e) {
assertEquals(expected,e.getClass());
}
catch (UnsupportedOperationException e) {
assertEquals(expected,e.getClass());
}
}
}
Program: 155560
Project: 155560
Buggy source:
public void listIterator_add(){
  if (skipTest(CollectionClass.REALMRESULTS)) {
    return;
  }
  realm.beginTransaction();
  ListIterator<AllJavaTypes> it=collection.listIterator();
  try {
    it.add(new AllJavaTypes());
    fail();
  }
 catch (  IllegalStateException ignored) {
  }
  AllJavaTypes obj=it.next();
  assertEquals(0,obj.getFieldLong());
  it.add(new AllJavaTypes(42));
  obj=it.previous();
  assertEquals(42,obj.getFieldLong());
}

Fixed version (ground truth):
@Test public void listIterator_add(){
  if (skipTest(CollectionClass.REALMRESULTS)) {
    return;
  }
  realm.beginTransaction();
  ListIterator<AllJavaTypes> it=collection.listIterator();
  try {
    it.add(new AllJavaTypes());
    fail();
  }
 catch (  IllegalStateException ignored) {
  }
  AllJavaTypes obj=it.next();
  assertEquals(0,obj.getFieldLong());
  it.add(new AllJavaTypes(42));
  obj=it.previous();
  assertEquals(42,obj.getFieldLong());
}
Program: 155561
Project: 155561
Buggy source:
@Test public void listIterator_remove_beforeNext(){
  Iterator<AllJavaTypes> it=collection.listIterator();
  realm.beginTransaction();
  try {
    it.remove();
  }
 catch (  IllegalStateException e) {
    assertRealmList();
  }
catch (  UnsupportedOperationException e) {
    assertResultsOrSnapshot();
  }
}

Fixed version (ground truth):
@Test public void listIterator_remove_beforeNext(){
  Iterator<AllJavaTypes> it=collection.listIterator();
  realm.beginTransaction();
  try {
    it.remove();
    fail();
  }
 catch (  IllegalStateException e) {
    assertRealmList();
  }
catch (  UnsupportedOperationException e) {
    assertResultsOrSnapshot();
  }
}
Program: 155562
Project: 155562
Buggy source:
@Override public void run(){
  try {
    object.getRealm();
    fail();
  }
 catch (  Throwable t) {
    throwable.set(t);
    threadFinished.countDown();
    return;
  }
  try {
    RealmObject.getRealm(object);
    fail();
  }
 catch (  Throwable t) {
    throwable.set(t);
  }
 finally {
    threadFinished.countDown();
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    object.getRealm();
    fail();
  }
 catch (  IllegalStateException e) {
    assertEquals(BaseRealm.INCORRECT_THREAD_MESSAGE,e.getMessage());
  }
  try {
    RealmObject.getRealm(object);
    fail();
  }
 catch (  IllegalStateException e) {
    assertEquals(BaseRealm.INCORRECT_THREAD_MESSAGE,e.getMessage());
  }
 finally {
    threadFinished.countDown();
  }
}
Program: 155563
Project: 155563
Buggy source:
@Test public void getRealm_illegalThreadThrows() throws Throwable {
  realm.beginTransaction();
  final AllTypes object=realm.createObject(AllTypes.class);
  realm.commitTransaction();
  final CountDownLatch threadFinished=new CountDownLatch(1);
  final AtomicReference<Throwable> throwable=new AtomicReference<>();
  final Thread thread=new Thread(new Runnable(){
    @Override public void run(){
      try {
        object.getRealm();
        fail();
      }
 catch (      Throwable t) {
        throwable.set(t);
        threadFinished.countDown();
        return;
      }
      try {
        RealmObject.getRealm(object);
        fail();
      }
 catch (      Throwable t) {
        throwable.set(t);
      }
 finally {
        threadFinished.countDown();
      }
    }
  }
);
  thread.start();
  TestHelper.awaitOrFail(threadFinished);
  final Throwable thrownInTheThread=throwable.get();
  if (!(thrownInTheThread instanceof IllegalStateException)) {
    throw thrownInTheThread;
  }
  assertEquals(BaseRealm.INCORRECT_THREAD_MESSAGE,thrownInTheThread.getMessage());
}

Fixed version (ground truth):
@Test public void getRealm_illegalThreadThrows() throws Throwable {
  realm.beginTransaction();
  final AllTypes object=realm.createObject(AllTypes.class);
  realm.commitTransaction();
  final CountDownLatch threadFinished=new CountDownLatch(1);
  final Thread thread=new Thread(new Runnable(){
    @Override public void run(){
      try {
        object.getRealm();
        fail();
      }
 catch (      IllegalStateException e) {
        assertEquals(BaseRealm.INCORRECT_THREAD_MESSAGE,e.getMessage());
      }
      try {
        RealmObject.getRealm(object);
        fail();
      }
 catch (      IllegalStateException e) {
        assertEquals(BaseRealm.INCORRECT_THREAD_MESSAGE,e.getMessage());
      }
 finally {
        threadFinished.countDown();
      }
    }
  }
);
  thread.start();
  TestHelper.awaitOrFail(threadFinished);
}
Program: 155564
Project: 155564
Buggy source:
@Test public void callThreadConfinedMethodsFromWrongThread() throws Throwable {
  final RealmQuery<AllJavaTypes> query=realm.where(AllJavaTypes.class);
  final AtomicReference<Throwable> throwableFromThread=new AtomicReference<Throwable>();
  final CountDownLatch testFinished=new CountDownLatch(1);
  final String expectedMessage;
  try {
    final Field expectedMessageField=BaseRealm.class.getDeclaredField("String_Node_Str");
    expectedMessageField.setAccessible(true);
    expectedMessage=(String)expectedMessageField.get(null);
  }
 catch (  NoSuchFieldException e) {
    throw new AssertionError(e);
  }
catch (  IllegalAccessException e) {
    throw new AssertionError(e);
  }
  final Thread thread=new Thread("String_Node_Str"){
    @Override public void run(){
      try {
        for (        ThreadConfinedMethods method : ThreadConfinedMethods.values()) {
          try {
            callThreadConfinedMethod(query,method);
            fail("String_Node_Str");
          }
 catch (          Throwable e) {
            if (e instanceof IllegalStateException && expectedMessage.equals(e.getMessage())) {
              continue;
            }
            throwableFromThread.set(e);
            return;
          }
        }
      }
  finally {
        testFinished.countDown();
      }
    }
  }
;
  thread.start();
  TestHelper.awaitOrFail(testFinished);
  final Throwable throwable=throwableFromThread.get();
  if (throwable != null) {
    throw throwable;
  }
}

Fixed version (ground truth):
@Test public void callThreadConfinedMethodsFromWrongThread() throws Throwable {
  final RealmQuery<AllJavaTypes> query=realm.where(AllJavaTypes.class);
  final CountDownLatch testFinished=new CountDownLatch(1);
  final String expectedMessage;
  try {
    final Field expectedMessageField=BaseRealm.class.getDeclaredField("String_Node_Str");
    expectedMessageField.setAccessible(true);
    expectedMessage=(String)expectedMessageField.get(null);
  }
 catch (  NoSuchFieldException e) {
    throw new AssertionError(e);
  }
catch (  IllegalAccessException e) {
    throw new AssertionError(e);
  }
  final Thread thread=new Thread("String_Node_Str"){
    @Override public void run(){
      try {
        for (        ThreadConfinedMethods method : ThreadConfinedMethods.values()) {
          try {
            callThreadConfinedMethod(query,method);
            fail("String_Node_Str");
          }
 catch (          IllegalStateException e) {
            assertEquals(expectedMessage,e.getMessage());
          }
        }
      }
  finally {
        testFinished.countDown();
      }
    }
  }
;
  thread.start();
  TestHelper.awaitOrFail(testFinished);
}
Program: 155565
Project: 155565
Buggy source:
@Test public void mutableMethodsCalled_notInTransaction(){
  if (type == SchemaType.IMMUTABLE) {
    return;
  }
  realm.cancelTransaction();
  try {
    realmSchema.create("String_Node_Str");
  }
 catch (  IllegalStateException expected) {
    assertThat(expected.getMessage(),CoreMatchers.containsString("String_Node_Str"));
  }
  try {
    realmSchema.createWithPrimaryKeyField("String_Node_Str","String_Node_Str",String.class);
  }
 catch (  IllegalStateException expected) {
    assertThat(expected.getMessage(),CoreMatchers.containsString("String_Node_Str"));
  }
  try {
    realmSchema.remove("String_Node_Str");
  }
 catch (  IllegalStateException expected) {
    assertThat(expected.getMessage(),CoreMatchers.containsString("String_Node_Str"));
  }
  try {
    realmSchema.rename("String_Node_Str","String_Node_Str");
  }
 catch (  IllegalStateException expected) {
    assertThat(expected.getMessage(),CoreMatchers.containsString("String_Node_Str"));
  }
}

Fixed version (ground truth):
@Test public void mutableMethodsCalled_notInTransaction(){
  if (type == SchemaType.IMMUTABLE) {
    return;
  }
  realm.cancelTransaction();
  try {
    realmSchema.create("String_Node_Str");
    fail();
  }
 catch (  IllegalStateException expected) {
    assertThat(expected.getMessage(),CoreMatchers.containsString("String_Node_Str"));
  }
  try {
    realmSchema.createWithPrimaryKeyField("String_Node_Str","String_Node_Str",String.class);
    fail();
  }
 catch (  IllegalStateException expected) {
    assertThat(expected.getMessage(),CoreMatchers.containsString("String_Node_Str"));
  }
  try {
    realmSchema.remove("String_Node_Str");
    fail();
  }
 catch (  IllegalStateException expected) {
    assertThat(expected.getMessage(),CoreMatchers.containsString("String_Node_Str"));
  }
  try {
    realmSchema.rename("String_Node_Str","String_Node_Str");
    fail();
  }
 catch (  IllegalStateException expected) {
    assertThat(expected.getMessage(),CoreMatchers.containsString("String_Node_Str"));
  }
}
Program: 155566
Project: 155566
Buggy source:
@Test public void waitForChange_onLooperThread() throws Throwable {
  final CountDownLatch bgRealmClosed=new CountDownLatch(1);
  final ExceptionHolder bgError=new ExceptionHolder();
  Thread thread=new Thread(new Runnable(){
    @Override public void run(){
      Looper.prepare();
      Realm realm=Realm.getInstance(realmConfig);
      try {
        realm.waitForChange();
        fail();
      }
 catch (      Throwable expected) {
        bgError.setException(expected);
      }
 finally {
        realm.close();
        bgRealmClosed.countDown();
      }
    }
  }
);
  thread.start();
  TestHelper.awaitOrFail(bgRealmClosed);
  if (bgError.getException() instanceof AssertionError) {
    throw bgError.getException();
  }
  assertEquals(IllegalStateException.class,bgError.getException().getClass());
}

Fixed version (ground truth):
@Test public void waitForChange_onLooperThread() throws Throwable {
  final CountDownLatch bgRealmClosed=new CountDownLatch(1);
  Thread thread=new Thread(new Runnable(){
    @Override public void run(){
      Looper.prepare();
      Realm realm=Realm.getInstance(realmConfig);
      try {
        realm.waitForChange();
        fail();
      }
 catch (      IllegalStateException ignored) {
      }
 finally {
        realm.close();
        bgRealmClosed.countDown();
      }
    }
  }
);
  thread.start();
  TestHelper.awaitOrFail(bgRealmClosed);
}
Program: 155567
Project: 155567
Buggy source:
@Test public void sortCaseSensitive(){
  chars="String_Node_Str";
  createAndTest(new StringBuffer(chars).reverse().toString());
  chars="String_Node_Str";
  numberOfPermutations=0;
  permute(chars,0,chars.length() - 1);
  assertEquals(numberOfPermutations,factorial(chars.length()));
}

Fixed version (ground truth):
@Test public void sortCaseSensitive(){
  chars="String_Node_Str";
  createAndTest(new StringBuilder(chars).reverse().toString());
  chars="String_Node_Str";
  numberOfPermutations=0;
  permute(chars,0,chars.length() - 1);
  assertEquals(numberOfPermutations,factorial(chars.length()));
}
Program: 155568
Project: 155568
Buggy source:
@Override protected void before() throws Throwable {
  super.before();
  RealmConfiguration config=createConfiguration(UUID.randomUUID().toString());
  LinkedList<Object> refs=new LinkedList<>();
  List<Realm> realms=new LinkedList<>();
  LinkedList<Closeable> closeables=new LinkedList<>();
synchronized (lock) {
    realmConfiguration=config;
    realm=null;
    backgroundHandler=null;
    keepStrongReference=refs;
    testRealms=realms;
    closableResources=closeables;
  }
}

Fixed version (ground truth):
@Override protected void before() throws Throwable {
  super.before();
  RealmConfiguration config=createConfiguration(UUID.randomUUID().toString());
  List<Object> refs=new ArrayList<>();
  List<Realm> realms=new ArrayList<>();
  List<Closeable> closeables=new ArrayList<>();
synchronized (lock) {
    realmConfiguration=config;
    realm=null;
    backgroundHandler=null;
    keepStrongReference=refs;
    testRealms=realms;
    closableResources=closeables;
  }
}
Program: 155569
Project: 155569
Buggy source:
/** 
 * Stops the ROS instance used for the test.
 */
protected static void stopSyncServer(){
  try {
    HttpUtils.stopSyncServer();
  }
 catch (  Exception e) {
    Log.e(HttpUtils.TAG,"String_Node_Str" + Util.getStackTrace(e));
  }
}

Fixed version (ground truth):
/** 
 * Stops the ROS instance used for the test. The   {@link #startSyncServer()} will stop the sync server if needed, sonormally there is no need to call this.
 */
protected static void stopSyncServer(){
  try {
    HttpUtils.stopSyncServer();
  }
 catch (  Exception e) {
    Log.e(HttpUtils.TAG,"String_Node_Str" + Util.getStackTrace(e));
  }
}
Program: 155570
Project: 155570
Buggy source:
@After public void teardownTest(){
  if (!looperThread.isRuleUsed() || looperThread.isTestComplete()) {
    restoreEnvironmentAfterTest();
    stopSyncServer();
  }
 else {
    looperThread.runAfterTest(new Runnable(){
      @Override public void run(){
        restoreEnvironmentAfterTest();
        stopSyncServer();
      }
    }
);
  }
}

Fixed version (ground truth):
@After public void teardownTest(){
  if (!looperThread.isRuleUsed() || looperThread.isTestComplete()) {
    restoreEnvironmentAfterTest();
  }
 else {
    looperThread.runAfterTest(new Runnable(){
      @Override public void run(){
        restoreEnvironmentAfterTest();
      }
    }
);
  }
}
Program: 155571
Project: 155571
Buggy source:
@Override public void run(){
  restoreEnvironmentAfterTest();
  stopSyncServer();
}

Fixed version (ground truth):
@Override public void run(){
  restoreEnvironmentAfterTest();
}
Program: 155572
Project: 155572
Buggy source:
public static void startSyncServer() throws Exception {
  Request request=new Request.Builder().url(START_SERVER).build();
  Response response=client.newCall(request).execute();
  if (!response.isSuccessful())   throw new IOException("String_Node_Str" + response);
  SystemClock.sleep(2000);
}

Fixed version (ground truth):
/** 
 * Start the sync server. If the server has been started before, stop it first.
 */
public static void startSyncServer() throws Exception {
  Request request=new Request.Builder().url(START_SERVER).build();
  Response response=client.newCall(request).execute();
  if (!response.isSuccessful())   throw new IOException("String_Node_Str" + response);
  SystemClock.sleep(2000);
}
Program: 155573
Project: 155573
Buggy source:
public static void stopSyncServer() throws Exception {
  Request request=new Request.Builder().url(STOP_SERVER).build();
  Response response=client.newCall(request).execute();
  if (!response.isSuccessful())   throw new IOException("String_Node_Str" + response);
}

Fixed version (ground truth):
/** 
 * Stop the sync server if it is alive.   {@link #startSyncServer()} will implicitly stop the server if needed, sonormally there is no need to call this.
 */
public static void stopSyncServer() throws Exception {
  Request request=new Request.Builder().url(STOP_SERVER).build();
  Response response=client.newCall(request).execute();
  if (!response.isSuccessful())   throw new IOException("String_Node_Str" + response);
}
Program: 155574
Project: 155574
Buggy source:
@Override public RealmObjectSchema rename(String oldClassName,String newClassName){
  realm.checkNotInSync();
  checkNotEmpty(oldClassName,"String_Node_Str");
  checkNotEmpty(newClassName,"String_Node_Str");
  String oldInternalName=Table.getTableNameForClass(oldClassName);
  String newInternalName=Table.getTableNameForClass(newClassName);
  checkHasTable(oldClassName,"String_Node_Str" + oldClassName);
  if (realm.getSharedRealm().hasTable(newInternalName)) {
    throw new IllegalArgumentException(oldClassName + "String_Node_Str" + newClassName);
  }
  Table oldTable=getTable(oldClassName);
  String pkField=null;
  if (oldTable.hasPrimaryKey()) {
    pkField=oldTable.getColumnName(oldTable.getPrimaryKey());
    oldTable.setPrimaryKey(null);
  }
  realm.getSharedRealm().renameTable(oldInternalName,newInternalName);
  Table table=realm.getSharedRealm().getTable(newInternalName);
  if (pkField != null) {
    table.setPrimaryKey(pkField);
  }
  return new MutableRealmObjectSchema(realm,this,table);
}

Fixed version (ground truth):
@Override public RealmObjectSchema rename(String oldClassName,String newClassName){
  realm.checkNotInSync();
  checkNotEmpty(oldClassName,"String_Node_Str");
  checkNotEmpty(newClassName,"String_Node_Str");
  String oldInternalName=Table.getTableNameForClass(oldClassName);
  String newInternalName=Table.getTableNameForClass(newClassName);
  checkHasTable(oldClassName,"String_Node_Str" + oldClassName);
  if (realm.getSharedRealm().hasTable(newInternalName)) {
    throw new IllegalArgumentException(oldClassName + "String_Node_Str" + newClassName);
  }
  Table oldTable=getTable(oldClassName);
  String pkField=null;
  if (oldTable.hasPrimaryKey()) {
    pkField=oldTable.getColumnName(oldTable.getPrimaryKey());
    oldTable.setPrimaryKey(null);
  }
  realm.getSharedRealm().renameTable(oldInternalName,newInternalName);
  Table table=realm.getSharedRealm().getTable(newInternalName);
  if (pkField != null) {
    table.setPrimaryKey(pkField);
  }
  RealmObjectSchema objectSchema=removeFromClassNameToSchemaMap(oldInternalName);
  if (objectSchema == null || !objectSchema.getTable().isValid() || !objectSchema.getClassName().equals(newClassName)) {
    objectSchema=new MutableRealmObjectSchema(realm,this,table);
  }
  putToClassNameToSchemaMap(newInternalName,objectSchema);
  return objectSchema;
}
Program: 155575
Project: 155575
Buggy source:
@Override public void remove(String className){
  realm.checkNotInSync();
  checkNotEmpty(className,EMPTY_STRING_MSG);
  String internalTableName=Table.getTableNameForClass(className);
  checkHasTable(className,"String_Node_Str" + className);
  Table table=getTable(className);
  if (table.hasPrimaryKey()) {
    table.setPrimaryKey(null);
  }
  realm.getSharedRealm().removeTable(internalTableName);
}

Fixed version (ground truth):
@Override public void remove(String className){
  realm.checkNotInSync();
  checkNotEmpty(className,EMPTY_STRING_MSG);
  String internalTableName=Table.getTableNameForClass(className);
  checkHasTable(className,"String_Node_Str" + className);
  Table table=getTable(className);
  if (table.hasPrimaryKey()) {
    table.setPrimaryKey(null);
  }
  realm.getSharedRealm().removeTable(internalTableName);
  removeFromClassNameToSchemaMap(internalTableName);
}
Program: 155577
Project: 155577
Buggy source:
RealmObjectSchema getSchemaForClass(String className){
  String tableName=Table.getTableNameForClass(className);
  RealmObjectSchema dynamicSchema=dynamicClassToSchema.get(tableName);
  if (dynamicSchema == null) {
    if (!realm.getSharedRealm().hasTable(tableName)) {
      throw new IllegalArgumentException("String_Node_Str" + className + "String_Node_Str");
    }
    dynamicSchema=new ImmutableRealmObjectSchema(realm,this,realm.getSharedRealm().getTable(tableName));
    dynamicClassToSchema.put(tableName,dynamicSchema);
  }
  return dynamicSchema;
}

Fixed version (ground truth):
RealmObjectSchema getSchemaForClass(String className){
  String tableName=Table.getTableNameForClass(className);
  RealmObjectSchema dynamicSchema=dynamicClassToSchema.get(tableName);
  if (dynamicSchema == null || !dynamicSchema.getTable().isValid() || !dynamicSchema.getClassName().equals(className)) {
    if (!realm.getSharedRealm().hasTable(tableName)) {
      throw new IllegalArgumentException("String_Node_Str" + className + "String_Node_Str");
    }
    dynamicSchema=new ImmutableRealmObjectSchema(realm,this,realm.getSharedRealm().getTable(tableName));
    dynamicClassToSchema.put(tableName,dynamicSchema);
  }
  return dynamicSchema;
}
Program: 155578
Project: 155578
Buggy source:
@Override public RealmObjectSchema createWithPrimaryKeyField(String className,String primaryKeyFieldName,Class<?> fieldType,FieldAttribute... attributes){
  checkEmpty(className,EMPTY_STRING_MSG);
  RealmObjectSchema.checkLegalName(primaryKeyFieldName);
  String internalTableName=checkAndGetTableNameFromClassName(className);
  RealmObjectSchema.FieldMetaData metadata=RealmObjectSchema.getSupportedSimpleFields().get(fieldType);
  if (metadata == null || (metadata.realmType != RealmFieldType.STRING && metadata.realmType != RealmFieldType.INTEGER)) {
    throw new IllegalArgumentException(String.format("String_Node_Str",fieldType));
  }
  boolean isStringField=(metadata.realmType == RealmFieldType.STRING);
  boolean nullable=metadata.defaultNullable;
  if (MutableRealmObjectSchema.containsAttribute(attributes,FieldAttribute.REQUIRED)) {
    nullable=false;
  }
  return new MutableRealmObjectSchema(realm,this,realm.getSharedRealm().createTableWithPrimaryKey(internalTableName,primaryKeyFieldName,isStringField,nullable));
}

Fixed version (ground truth):
@Override public RealmObjectSchema createWithPrimaryKeyField(String className,String primaryKeyFieldName,Class<?> fieldType,FieldAttribute... attributes){
  checkNotEmpty(className,EMPTY_STRING_MSG);
  RealmObjectSchema.checkLegalName(primaryKeyFieldName);
  String internalTableName=checkAndGetTableNameFromClassName(className);
  RealmObjectSchema.FieldMetaData metadata=RealmObjectSchema.getSupportedSimpleFields().get(fieldType);
  if (metadata == null || (metadata.realmType != RealmFieldType.STRING && metadata.realmType != RealmFieldType.INTEGER)) {
    throw new IllegalArgumentException(String.format("String_Node_Str",fieldType));
  }
  boolean isStringField=(metadata.realmType == RealmFieldType.STRING);
  boolean nullable=metadata.defaultNullable;
  if (MutableRealmObjectSchema.containsAttribute(attributes,FieldAttribute.REQUIRED)) {
    nullable=false;
  }
  return new MutableRealmObjectSchema(realm,this,realm.getSharedRealm().createTableWithPrimaryKey(internalTableName,primaryKeyFieldName,isStringField,nullable));
}
Program: 155579
Project: 155579
Buggy source:
@Override public void run(){
  DynamicRealm dynamicRealm=DynamicRealm.getInstance(realm.getConfiguration());
  RealmList<DynamicRealmObject> list=new RealmList<DynamicRealmObject>();
  list.add(dObjDynamic);
  dynamicRealm.beginTransaction();
  try {
    dynamicRealm.where(AllJavaTypes.CLASS_NAME).findFirst().setList(AllJavaTypes.FIELD_LIST,list);
    fail();
  }
 catch (  IllegalArgumentException expected) {
    assertEquals(expected.getMessage(),"String_Node_Str");
  }
  dynamicRealm.cancelTransaction();
  dynamicRealm.close();
  finishedLatch.countDown();
}

Fixed version (ground truth):
@Override public void run(){
  DynamicRealm dynamicRealm=DynamicRealm.getInstance(realm.getConfiguration());
  RealmList<DynamicRealmObject> list=new RealmList<DynamicRealmObject>();
  list.add(dObjDynamic);
  dynamicRealm.beginTransaction();
  try {
    dynamicRealm.where(AllJavaTypes.CLASS_NAME).findFirst().setList(AllJavaTypes.FIELD_LIST,list);
    fail();
  }
 catch (  IllegalArgumentException expected) {
    assertEquals("String_Node_Str",expected.getMessage());
  }
  dynamicRealm.cancelTransaction();
  dynamicRealm.close();
  finishedLatch.countDown();
}
Program: 155580
Project: 155580
Buggy source:
@Test public void setList_elementBelongToDiffThreadRealmThrows(){
  final CountDownLatch finishedLatch=new CountDownLatch(1);
  new Thread(new Runnable(){
    @Override public void run(){
      DynamicRealm dynamicRealm=DynamicRealm.getInstance(realm.getConfiguration());
      RealmList<DynamicRealmObject> list=new RealmList<DynamicRealmObject>();
      list.add(dObjDynamic);
      dynamicRealm.beginTransaction();
      try {
        dynamicRealm.where(AllJavaTypes.CLASS_NAME).findFirst().setList(AllJavaTypes.FIELD_LIST,list);
        fail();
      }
 catch (      IllegalArgumentException expected) {
        assertEquals(expected.getMessage(),"String_Node_Str");
      }
      dynamicRealm.cancelTransaction();
      dynamicRealm.close();
      finishedLatch.countDown();
    }
  }
).start();
  TestHelper.awaitOrFail(finishedLatch);
}

Fixed version (ground truth):
@Test public void setList_elementBelongToDiffThreadRealmThrows(){
  final CountDownLatch finishedLatch=new CountDownLatch(1);
  new Thread(new Runnable(){
    @Override public void run(){
      DynamicRealm dynamicRealm=DynamicRealm.getInstance(realm.getConfiguration());
      RealmList<DynamicRealmObject> list=new RealmList<DynamicRealmObject>();
      list.add(dObjDynamic);
      dynamicRealm.beginTransaction();
      try {
        dynamicRealm.where(AllJavaTypes.CLASS_NAME).findFirst().setList(AllJavaTypes.FIELD_LIST,list);
        fail();
      }
 catch (      IllegalArgumentException expected) {
        assertEquals("String_Node_Str",expected.getMessage());
      }
      dynamicRealm.cancelTransaction();
      dynamicRealm.close();
      finishedLatch.countDown();
    }
  }
).start();
  TestHelper.awaitOrFail(finishedLatch);
}
Program: 155581
Project: 155581
Buggy source:
@Test public void setObject_objectBelongToDiffThreadRealmThrows(){
  final CountDownLatch finishedLatch=new CountDownLatch(1);
  new Thread(new Runnable(){
    @Override public void run(){
      DynamicRealm dynamicRealm=DynamicRealm.getInstance(realm.getConfiguration());
      dynamicRealm.beginTransaction();
      try {
        dynamicRealm.where(AllJavaTypes.CLASS_NAME).findFirst().setObject(AllJavaTypes.FIELD_OBJECT,dObjDynamic);
        fail();
      }
 catch (      IllegalArgumentException expected) {
        assertEquals(expected.getMessage(),"String_Node_Str");
      }
      dynamicRealm.cancelTransaction();
      dynamicRealm.close();
      finishedLatch.countDown();
    }
  }
).start();
  TestHelper.awaitOrFail(finishedLatch);
}

Fixed version (ground truth):
@Test public void setObject_objectBelongToDiffThreadRealmThrows(){
  final CountDownLatch finishedLatch=new CountDownLatch(1);
  new Thread(new Runnable(){
    @Override public void run(){
      DynamicRealm dynamicRealm=DynamicRealm.getInstance(realm.getConfiguration());
      dynamicRealm.beginTransaction();
      try {
        dynamicRealm.where(AllJavaTypes.CLASS_NAME).findFirst().setObject(AllJavaTypes.FIELD_OBJECT,dObjDynamic);
        fail();
      }
 catch (      IllegalArgumentException expected) {
        assertEquals("String_Node_Str",expected.getMessage());
      }
      dynamicRealm.cancelTransaction();
      dynamicRealm.close();
      finishedLatch.countDown();
    }
  }
).start();
  TestHelper.awaitOrFail(finishedLatch);
}